generated from projeto-de-algoritmos-2024/RepositorioTemplate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq1.cpp
44 lines (29 loc) · 822 Bytes
/
q1.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
// 1490 - D. Permutation Transformation
#include <bits/stdc++.h>
using namespace std;
unordered_map<int,int> unmap;
void getRootSubArray(int l, int r, vector<int> vals, int depth) {
if(l > r) return;
int maxVal = l;
for(int i = l; i <= r; ++i)
if(vals[i] > vals[maxVal]) maxVal = i;
unmap[vals[maxVal]] = depth;
getRootSubArray(l, maxVal - 1, vals, depth+1);
getRootSubArray(maxVal + 1, r, vals, depth+1);
}
int main(){
int t, n;
cin >> t;
while(t--) {
cin >> n;
vector<int> vals(n);
for(int i = 0; i < n; ++i)
cin >> vals[i];
getRootSubArray(0, n - 1, vals, 0);
for(int i = 0; i < n; ++i)
cout << unmap[vals[i]] << " ";
cout << endl;
unmap.clear();
}
return EXIT_SUCCESS;
}