#include<bits/stdc++.h>
#define NN 100100
using namespace std;
int h[NN], n;
map<int, set<int>> adj[NN];
int upd[2*NN][2];
void init(int N, int D, int H[]) {
n = N;
for(int i = 0; i < N; i++)
h[i] = H[i];
}
void curseChanges(int U, int A[], int B[]) {
for(int i = 0; i < n; i++) adj[i][0];
for(int i = 1; i <= U; i++) {
upd[i][0] = A[i-1], upd[i][1] = B[i-1];
}
for(int i = 1; i <= U/5*5; i++) {
int a= upd[i][0], b = upd[i][1];
set<int> x = (--adj[a].end())->second, y = (--adj[b].end())->second;
if(x.count(b)) x.erase(b), y.erase(a);
else x.insert(b), y.insert(a);
adj[a][(i/5+1)*5] = x, adj[b][(i/5+1)*5] = y;
}
}
int calc(vector<int> a, vector<int> b){
int ans = 1e9;
for(int i = 0, j = 0; i < (int)a.size()&&j < (int)b.size();i++) {
if(a[i]>b[j]) swap(a, b), swap(i, j);
if(j) ans=min(ans,(int)abs(a[i]-b[j-1]));
ans = min(ans, abs(a[i] - b[j]));
}
return ans;
}
int question(int x, int y, int v) {
set<int> a = (--adj[x].upper_bound(v))->second, b = (--adj[y].upper_bound(v))->second;
int t = v/5*5;
while(t <= v) {
int c = upd[t][0], d = upd[t][1];
if(d==x) swap(c, d);
if(c==x) {
if(a.count(d)) a.erase(d);
else a.insert(d);
}
if(d==y) swap(c, d);
if(c==y) {
if(b.count(d)) b.erase(d);
else b.insert(d);
}
t++;
}
vector<int> c, d;
for(auto i: a) c.push_back(h[i]);
for(auto i: b) d.push_back(h[i]);
sort(c.begin(), c.end());
sort(d.begin(), d.end());
return calc(c,d);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
5456 KB |
Output is correct |
2 |
Correct |
4 ms |
5456 KB |
Output is correct |
3 |
Correct |
4 ms |
5416 KB |
Output is correct |
4 |
Correct |
24 ms |
15460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
491 ms |
112200 KB |
Output is correct |
2 |
Correct |
465 ms |
112160 KB |
Output is correct |
3 |
Correct |
703 ms |
225788 KB |
Output is correct |
4 |
Runtime error |
448 ms |
262144 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
477 ms |
112252 KB |
Output is correct |
2 |
Runtime error |
479 ms |
262144 KB |
Execution killed with signal 9 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
9936 KB |
Output is correct |
2 |
Correct |
125 ms |
15744 KB |
Output is correct |
3 |
Correct |
188 ms |
12080 KB |
Output is correct |
4 |
Correct |
1207 ms |
65608 KB |
Output is correct |
5 |
Correct |
1187 ms |
50864 KB |
Output is correct |
6 |
Correct |
159 ms |
17184 KB |
Output is correct |
7 |
Correct |
921 ms |
41444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4944 KB |
Output is correct |
2 |
Correct |
4 ms |
5456 KB |
Output is correct |
3 |
Correct |
4 ms |
5456 KB |
Output is correct |
4 |
Correct |
4 ms |
5416 KB |
Output is correct |
5 |
Correct |
24 ms |
15460 KB |
Output is correct |
6 |
Correct |
491 ms |
112200 KB |
Output is correct |
7 |
Correct |
465 ms |
112160 KB |
Output is correct |
8 |
Correct |
703 ms |
225788 KB |
Output is correct |
9 |
Runtime error |
448 ms |
262144 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |