# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
612967 |
2022-07-30T02:38:02 Z |
1bin |
Tree Rotations (POI11_rot) |
C++14 |
|
1000 ms |
26064 KB |
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 2e5 + 5;
int n, t, a[NMAX], lc[NMAX], rc[NMAX];
int rt[NMAX], l[NMAX * 20], r[NMAX * 20], s[NMAX * 20], cnt;
ll ans, r1, r2;
void dfs(int x){
cin >> a[x];
if(!a[x]){
lc[x] = ++t; dfs(lc[x]);
rc[x] = ++t; dfs(rc[x]);
}
return;
}
int upd(int le, int ri, int k){
int ix = ++cnt;
s[ix] = 1;
if(le == ri) return ix;
int m = (le + ri) / 2;
if(k <= m) l[ix] = upd(le, m, k);
else r[ix] = upd(m + 1, ri, k);
return ix;
}
int merge(int x, int y){
if(!x) return y;
if(!y) return x;
r1 += s[l[x]] * s[r[y]];
r2 += s[l[y]] * s[r[x]];
l[x] = merge(l[x], l[y]);
r[x] = merge(r[x], r[y]);
s[x] = s[l[x]] + s[r[x]];
return x;
}
ll dfs2(int x){
if(a[x]) return 0;
ll ret = dfs2(lc[x]) + dfs2(rc[x]);
r1 = r2 = 0;
rt[x] = merge(rt[lc[x]], rt[rc[x]]);
ret += min(r1, r2);
return ret;
}
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
dfs(++t);
for(int i = 1; i <= t; i++)
if(a[i]) rt[i] = upd(1, n, a[i]);
cout << dfs2(1);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
1108 KB |
Output is correct |
2 |
Correct |
4 ms |
1108 KB |
Output is correct |
3 |
Correct |
4 ms |
1236 KB |
Output is correct |
4 |
Correct |
4 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
3064 KB |
Output is correct |
2 |
Correct |
12 ms |
2912 KB |
Output is correct |
3 |
Correct |
22 ms |
6936 KB |
Output is correct |
4 |
Correct |
9 ms |
3360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
42 ms |
11896 KB |
Output is correct |
2 |
Correct |
29 ms |
12020 KB |
Output is correct |
3 |
Correct |
56 ms |
13776 KB |
Output is correct |
4 |
Correct |
46 ms |
14840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
22816 KB |
Output is correct |
2 |
Correct |
83 ms |
22044 KB |
Output is correct |
3 |
Correct |
98 ms |
20764 KB |
Output is correct |
4 |
Correct |
73 ms |
21220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1036 ms |
8128 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
96 ms |
20760 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
78 ms |
23672 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
84 ms |
26064 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |