#include <bits/stdc++.h>
using namespace std;
#define fi first
#define all(v) v.begin(), v.end()
const int NMAX = 1e5 + 5;
const int sqt = 30;
int n, d, u, q, h[NMAX], a, b, A[2 * NMAX], B[2 * NMAX];
vector<int> ix[NMAX];
vector<vector<pair<int, int>>> v[NMAX];
set<pair<int, int>> l, r;
void init(int N, int D, int H[]){
n = N; d = D;
for(int i = 0; i < n; i++) h[i] = H[i];
return;
}
void curseChanges(int U, int A_[], int B_[]){
u = U;
for(int i = 0; i < u; i++) A[i] = A_[i], B[i] = B_[i];
for(int i = 0; i < u; i++){
a = A[i]; b = B[i];
ix[a].emplace_back(i);
ix[b].emplace_back(i);
}
for(int i = 0; i < n; i++){
set<pair<int, int>> s;
for(int j = 0; j < ix[i].size(); j++){
int t = A[ix[i][j]] == i ? B[ix[i][j]] : A[ix[i][j]];
if(s.find({h[t], t}) == s.end()) s.insert({h[t], t});
else s.erase({h[t], t});
if(j % sqt == sqt - 1){
vector<pair<int, int>> tmp;
for(auto t : s) tmp.emplace_back(t);
v[i].emplace_back(tmp);
}
}
}
return;
}
int question(int x, int y, int V){
int ans = 1e9, xb, yb, lsz, rsz;
int xsz = lower_bound(all(ix[x]), V) - ix[x].begin();
int ysz = lower_bound(all(ix[y]), V) - ix[y].begin();
xb = (xsz - 1) / sqt; yb = (ysz - 1) / sqt;
if(xb >= 1) for(auto& t : v[x][xb - 1]) l.emplace(t);
if(yb >= 1) for(auto& t : v[y][yb - 1]) r.emplace(t);
for(int i = xb * sqt; i < xsz; i++) {
int t = (A[ix[x][i]] == x) ? B[ix[x][i]] : A[ix[x][i]];
if(l.find({h[t], t}) == l.end()) l.insert({h[t], t});
else l.erase({h[t], t});
}
for(int i = yb * sqt; i < ysz; i++) {
int t = (A[ix[y][i]] == y) ? B[ix[y][i]] : A[ix[y][i]];
if(r.find({h[t], t}) == r.end()) r.insert({h[t], t});
else r.erase({h[t], t});
}
auto xi = l.begin();
auto yi = r.begin();
lsz = l.size(); rsz = r.size();
while(xi != l.end() && yi != r.end()){
ans = min(ans, abs(xi->fi - yi->fi));
xi->fi < yi->fi ? xi++ : yi++;
}
l.clear(); r.clear();
return ans;
}
Compilation message
potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:30:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for(int j = 0; j < ix[i].size(); j++){
| ~~^~~~~~~~~~~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:47:28: warning: variable 'lsz' set but not used [-Wunused-but-set-variable]
47 | int ans = 1e9, xb, yb, lsz, rsz;
| ^~~
potion.cpp:47:33: warning: variable 'rsz' set but not used [-Wunused-but-set-variable]
47 | int ans = 1e9, xb, yb, lsz, rsz;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4944 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
5072 KB |
Output is correct |
2 |
Correct |
6 ms |
5072 KB |
Output is correct |
3 |
Correct |
5 ms |
5072 KB |
Output is correct |
4 |
Correct |
23 ms |
5868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
301 ms |
13208 KB |
Output is correct |
2 |
Correct |
299 ms |
13040 KB |
Output is correct |
3 |
Correct |
433 ms |
12332 KB |
Output is correct |
4 |
Correct |
2898 ms |
23856 KB |
Output is correct |
5 |
Correct |
700 ms |
13408 KB |
Output is correct |
6 |
Execution timed out |
3017 ms |
31504 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
238 ms |
13128 KB |
Output is correct |
2 |
Execution timed out |
3087 ms |
32712 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
64 ms |
5456 KB |
Output is correct |
2 |
Correct |
241 ms |
5460 KB |
Output is correct |
3 |
Correct |
405 ms |
5440 KB |
Output is correct |
4 |
Correct |
1430 ms |
5968 KB |
Output is correct |
5 |
Correct |
1475 ms |
5852 KB |
Output is correct |
6 |
Correct |
264 ms |
5316 KB |
Output is correct |
7 |
Correct |
1382 ms |
5676 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
4944 KB |
Output is correct |
2 |
Correct |
5 ms |
5072 KB |
Output is correct |
3 |
Correct |
6 ms |
5072 KB |
Output is correct |
4 |
Correct |
5 ms |
5072 KB |
Output is correct |
5 |
Correct |
23 ms |
5868 KB |
Output is correct |
6 |
Correct |
301 ms |
13208 KB |
Output is correct |
7 |
Correct |
299 ms |
13040 KB |
Output is correct |
8 |
Correct |
433 ms |
12332 KB |
Output is correct |
9 |
Correct |
2898 ms |
23856 KB |
Output is correct |
10 |
Correct |
700 ms |
13408 KB |
Output is correct |
11 |
Execution timed out |
3017 ms |
31504 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |