# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
466640 | 2021-08-19T20:33:06 Z | ivan_tudor | The Potion of Great Power (CEOI20_potion) | C++14 | 2495 ms | 19184 KB |
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int BUCKET_SIZE[N]; int h[N]; int n, d; int lg2[2*N]; void init(int N, int D, int H[]) { d = D; n = N; for(int i = 0; i < N; i++){ h[i] = H[i]; } } struct otherhelper{ int x; int time; }; vector <otherhelper> changes[N]; vector<vector<int>> precalc[N]; set<int> act; void curseChanges(int U, int A[], int B[]) { lg2[1] = 0; for(int i = 2; i < N; i++) lg2[i] = 1 + lg2[i/2]; for(int i = 0; i < U; i++){ changes[A[i]].push_back({B[i], i}); changes[B[i]].push_back({A[i], i}); } for(int i = 0; i < n; i++){ int cnt = 0; BUCKET_SIZE[i] = 50; if(BUCKET_SIZE[i] == 0) BUCKET_SIZE[i] = 1; for(int j = 0; j < changes[i].size(); j++){ int val = changes[i][j].x; if(act.count(val) == true) act.erase(val); else act.insert(val); cnt++; if(cnt == BUCKET_SIZE[i]){ precalc[i].push_back(vector<int>(act.size())); int nr = 0; for(auto x: act) precalc[i].back()[nr++] = (x); cnt = 0; } } act.clear(); } } bitset<100005> mark; void get_list(int x, int v, vector<int> &ans){ int pas = 0; for(int p2 = 1<<(lg2[changes[x].size()] + 1); p2 > 0; p2/=2){ if(pas + p2 < changes[x].size() && changes[x][pas + p2].time < v) pas += p2; } if(!(pas < changes[x].size() && changes[x][pas].time < v)){ return; } mark.reset(); int lastcheck = pas / BUCKET_SIZE[x] - 1; if(lastcheck >= 0){ for(auto a: precalc[x][lastcheck]){ mark[a] = true; } } for(int i = (lastcheck + 1) * BUCKET_SIZE[x]; i <= pas; i++){ int val = changes[x][i].x; mark[val] = mark[val] ^ 1; } if(lastcheck >= 0){ for(auto a: precalc[x][lastcheck]){ if(mark[a] == true){ ans.push_back(h[a]); mark[a] = false; } } } for(int i = (lastcheck + 1) * BUCKET_SIZE[x]; i <= pas; i++){ int val = changes[x][i].x; if(mark[val] == true){ ans.push_back(h[val]); mark[val] = false; } } for(auto x:act){ ans.push_back(h[x]); mark[x] = false; } act.clear(); sort(ans.begin(), ans.end()); } vector<int> a, b; int question(int x, int y, int v) { a.clear(); get_list(x, v, a); b.clear(); get_list(y, v, b); int ans = 1e9; for(int i = 0, j = 0; i < a.size() && j < b.size();){ if(a[i] < b[j]){ ans = min(ans, b[j] - a[i]); i++; } else{ ans = min(ans, a[i] - b[j]); j++; } } return ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5320 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 5448 KB | Output is correct |
2 | Correct | 5 ms | 5448 KB | Output is correct |
3 | Correct | 5 ms | 5460 KB | Output is correct |
4 | Correct | 19 ms | 6596 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 259 ms | 14404 KB | Output is correct |
2 | Correct | 249 ms | 14336 KB | Output is correct |
3 | Correct | 233 ms | 12120 KB | Output is correct |
4 | Correct | 1308 ms | 15220 KB | Output is correct |
5 | Correct | 379 ms | 12612 KB | Output is correct |
6 | Correct | 2495 ms | 19184 KB | Output is correct |
7 | Correct | 496 ms | 14396 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 213 ms | 14296 KB | Output is correct |
2 | Correct | 996 ms | 18828 KB | Output is correct |
3 | Correct | 656 ms | 16408 KB | Output is correct |
4 | Correct | 1053 ms | 19036 KB | Output is correct |
5 | Correct | 275 ms | 14560 KB | Output is correct |
6 | Correct | 1155 ms | 19136 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 76 ms | 5940 KB | Output is correct |
2 | Correct | 131 ms | 5816 KB | Output is correct |
3 | Correct | 166 ms | 5832 KB | Output is correct |
4 | Correct | 742 ms | 5944 KB | Output is correct |
5 | Correct | 738 ms | 5960 KB | Output is correct |
6 | Correct | 126 ms | 5704 KB | Output is correct |
7 | Correct | 617 ms | 5960 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 5320 KB | Output is correct |
2 | Correct | 5 ms | 5448 KB | Output is correct |
3 | Correct | 5 ms | 5448 KB | Output is correct |
4 | Correct | 5 ms | 5460 KB | Output is correct |
5 | Correct | 19 ms | 6596 KB | Output is correct |
6 | Correct | 259 ms | 14404 KB | Output is correct |
7 | Correct | 249 ms | 14336 KB | Output is correct |
8 | Correct | 233 ms | 12120 KB | Output is correct |
9 | Correct | 1308 ms | 15220 KB | Output is correct |
10 | Correct | 379 ms | 12612 KB | Output is correct |
11 | Correct | 2495 ms | 19184 KB | Output is correct |
12 | Correct | 496 ms | 14396 KB | Output is correct |
13 | Correct | 213 ms | 14296 KB | Output is correct |
14 | Correct | 996 ms | 18828 KB | Output is correct |
15 | Correct | 656 ms | 16408 KB | Output is correct |
16 | Correct | 1053 ms | 19036 KB | Output is correct |
17 | Correct | 275 ms | 14560 KB | Output is correct |
18 | Correct | 1155 ms | 19136 KB | Output is correct |
19 | Correct | 76 ms | 5940 KB | Output is correct |
20 | Correct | 131 ms | 5816 KB | Output is correct |
21 | Correct | 166 ms | 5832 KB | Output is correct |
22 | Correct | 742 ms | 5944 KB | Output is correct |
23 | Correct | 738 ms | 5960 KB | Output is correct |
24 | Correct | 126 ms | 5704 KB | Output is correct |
25 | Correct | 617 ms | 5960 KB | Output is correct |
26 | Correct | 689 ms | 14868 KB | Output is correct |
27 | Correct | 1110 ms | 16320 KB | Output is correct |
28 | Correct | 1219 ms | 16628 KB | Output is correct |
29 | Correct | 1098 ms | 15240 KB | Output is correct |
30 | Correct | 2352 ms | 19136 KB | Output is correct |
31 | Correct | 2154 ms | 19116 KB | Output is correct |
32 | Correct | 2075 ms | 19068 KB | Output is correct |