-
Notifications
You must be signed in to change notification settings - Fork 0
/
1973C.cpp
54 lines (46 loc) · 802 Bytes
/
1973C.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
int t;
cin >> t;
for (int tn = 0; tn < t; tn++)
{
int n;
cin >> n;
vector<int> p(n);
for (int i = 0; i < n; i++)
cin >> p[i];
int x = 0;
for (int i = 0; i < n; i++)
{
p[i]--;
if (p[i] == 0)
x = i % 2;
}
vector<int> z(n);
for (int k = 0; k < 2; k++)
{
vector<int> v;
for (int i = k; i < n; i += 2)
v.push_back(p[i]);
sort(v.begin(), v.end());
for (int i = 0; i < v.size(); i++)
z[v[i]] = (k == x ? n / 2 : n) - i - 1;
}
vector<int> q(n);
for (int i = 0; i < n; i++)
q[i] = z[p[i]];
for (int i = 0; i < n; i++)
{
if (i > 0)
cout << " ";
cout << q[i] + 1;
}
cout << endl;
}
return 0;
}