# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
30108 | 2017-07-22T06:29:11 Z | 서규호(#1248) | Tree Rotations (POI11_rot) | C++14 | 0 ms | 1848 KB |
#include <bits/stdc++.h> #include <unistd.h> #define pii pair<int,int> #define pll pair<lld,lld> #define pb push_back #define next nextt #define left leftt #define right rightt #define lld long long #define Inf 1000000000 #define mod 1000000007 #define Linf 1000000000000000000LL #define get gett using namespace std; int N,rear; lld ans; int left[2000002],right[200002]; set<int> S[2000002]; void dfs(int x){ int in; scanf("%d",&in); if(in == 0){ rear++; left[x] = rear; dfs(rear); }else{ left[x] = in; } scanf("%d",&in); if(in == 0){ rear++; right[x] = rear; dfs(rear); }else{ right[x] = in; } } void calc(int x){ if(1 <= x && x <= N){ S[x].insert(x); return; } calc(left[x]); calc(right[x]); set<int> tmp; swap(S[x],S[left[x]]); swap(tmp,S[right[x]]); if(S[x].size() < tmp.size()) swap(S[x],tmp); int cnt = 0; lld sum = 0; auto it = S[x].begin(); for(auto &i : tmp){ while(1){ if(it != S[x].end() && (*it) < i){ cnt++; it++; }else break; } sum += cnt; } lld calctmp = (lld)S[x].size()*(lld)tmp.size(); ans += min(sum,calctmp-sum); for(auto &i : tmp) S[x].insert(i); } int main(){ //freopen("input.txt","r",stdin); int in; scanf("%d",&N); scanf("%d",&in); if(N == 1){ puts("0"); return 0; } rear = N; dfs(0); calc(0); printf("%lld\n",ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 0 ms | 1848 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 0 ms | 1848 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 0 ms | 1848 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 0 ms | 1848 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 0 ms | 1848 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 0 ms | 1848 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 0 ms | 1848 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 0 ms | 1848 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 0 ms | 1848 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 0 ms | 1848 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Runtime error | 0 ms | 1848 KB | Execution killed with signal 11 (could be triggered by violating memory limits) |
2 | Halted | 0 ms | 0 KB | - |