#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+30;
vector<bitset<500>> sts[N];
vector<array<int, 2>> adj[N];
vector<int> h, st[N];
map<array<int, 2>, int> mp;
bitset<500> s;
void init(int n, int d, int H[]){
for(int i=0; i<n; i++){
sts[i].push_back(s);
st[i].push_back(-1);
}
for(int i=0; i<n; i++){
h.push_back(H[i]);
}
}
void curseChanges(int u, int a[], int b[]){
for(int i=0; i<u; i++){
adj[a[i]].push_back({h[b[i]], b[i]});
adj[b[i]].push_back({h[a[i]], a[i]});
}
for(int i=0; i<N; i++){
sort(adj[i].begin(), adj[i].end());
}
for(int i=0; i<N; i++){
for(int l=0; l<adj[i].size(); l++){
mp[{i, adj[i][l][1]}]=l;
}
}
for(int i=0; i<u; i++){
int x=a[i], y=b[i];
bitset ss=sts[x].back();
int pos=mp[{x, y}];
if(ss[pos]==1) ss[pos]=0;
else ss[pos]=1;
sts[x].push_back(ss);
st[x].push_back(i);
ss=sts[y].back();
pos=mp[{y, x}];
if(ss[pos]==1) ss[pos]=0;
else ss[pos]=1;
sts[y].push_back(ss);
st[y].push_back(i);
}
}
int question(int x, int y, int v){
int posx = lower_bound(st[x].begin(), st[x].end(), v)-st[x].begin()-1;
int posy = lower_bound(st[y].begin(), st[y].end(), v)-st[y].begin()-1;
if(posx >= st[x].size() || posy <= 0 || st[x][posx] > v) return 1e9;
if(posy >= st[y].size() || posy <= 0 || st[y][posy] > v) return 1e9;
bitset sx = sts[x][posx], sy=sts[y][posy];
int lx=0, ly=0;
while(lx<sx.size() && sx[lx]==0) lx++;
while(ly<sy.size() && sy[ly]==0) ly++;
int ans=1e9;
while(lx<sx.size() && ly < 500){
int vx=adj[x][lx][0];
int vy=adj[y][ly][0];
ans=min(ans, abs(vx-vy));
if(vx < vy){
lx ++;
while(lx<sx.size() && sx[lx]==0) lx++;
}
else if(vx > vy){
ly ++;
while(ly<sy.size() && sy[ly]==0) ly++;
}
else{
break;
}
}
return ans;
}
Compilation message
potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:38:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 2> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for(int l=0; l<adj[i].size(); l++){
| ~^~~~~~~~~~~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:76:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | if(posx >= st[x].size() || posy <= 0 || st[x][posx] > v) return 1e9;
| ~~~~~^~~~~~~~~~~~~~~
potion.cpp:77:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
77 | if(posy >= st[y].size() || posy <= 0 || st[y][posy] > v) return 1e9;
| ~~~~~^~~~~~~~~~~~~~~
potion.cpp:82:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
82 | while(lx<sx.size() && sx[lx]==0) lx++;
| ~~^~~~~~~~~~
potion.cpp:83:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
83 | while(ly<sy.size() && sy[ly]==0) ly++;
| ~~^~~~~~~~~~
potion.cpp:87:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
87 | while(lx<sx.size() && ly < 500){
| ~~^~~~~~~~~~
potion.cpp:95:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
95 | while(lx<sx.size() && sx[lx]==0) lx++;
| ~~^~~~~~~~~~
potion.cpp:99:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::size_t' {aka 'long unsigned int'} [-Wsign-compare]
99 | while(ly<sy.size() && sy[ly]==0) ly++;
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
7888 KB |
Output is correct |
2 |
Correct |
7 ms |
7888 KB |
Output is correct |
3 |
Correct |
7 ms |
7888 KB |
Output is correct |
4 |
Correct |
35 ms |
19528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
693 ms |
96792 KB |
Output is correct |
2 |
Correct |
684 ms |
96824 KB |
Output is correct |
3 |
Runtime error |
189 ms |
112744 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
669 ms |
96804 KB |
Output is correct |
2 |
Runtime error |
337 ms |
138684 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
12572 KB |
Output is correct |
2 |
Correct |
70 ms |
11520 KB |
Output is correct |
3 |
Incorrect |
16 ms |
10712 KB |
Incorrect |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7376 KB |
Output is correct |
2 |
Correct |
6 ms |
7888 KB |
Output is correct |
3 |
Correct |
7 ms |
7888 KB |
Output is correct |
4 |
Correct |
7 ms |
7888 KB |
Output is correct |
5 |
Correct |
35 ms |
19528 KB |
Output is correct |
6 |
Correct |
693 ms |
96792 KB |
Output is correct |
7 |
Correct |
684 ms |
96824 KB |
Output is correct |
8 |
Runtime error |
189 ms |
112744 KB |
Execution killed with signal 6 |
9 |
Halted |
0 ms |
0 KB |
- |