#include <bits/stdc++.h>
using namespace std;
const int N = 1e5+30;
vector<string> sts[N];
vector<array<int, 2>> adj[N];
vector<int> h, st[N];
map<array<int, 2>, int> mp;
string s;
void init(int n, int d, int H[]){
for(int i=0; i<d; i++){
s+='0';
}
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];
string 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);
swap(x, y);
ss=sts[x].back();
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);
swap(x, y);
}
}
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;
string sx = sts[x][posx], sy=sts[y][posy];
int lx=0, ly=0;
while(sx[lx]=='0') lx++;
while(sy[ly]=='0') ly++;
int ans=1e9;
while(lx<sx.size() && ly < sy.size()){
int vx=h[adj[x][lx][1]];
int vy=h[adj[y][ly][1]];
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:42: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]
42 | for(int l=0; l<adj[i].size(); l++){
| ~^~~~~~~~~~~~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:80:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
80 | if(posx >= st[x].size() || posy <=0|| st[x][posx] >= v) return 1e9;
| ~~~~~^~~~~~~~~~~~~~~
potion.cpp:81:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | if(posy >= st[y].size() || posy <=0 || st[y][posy] >= v) return 1e9;
| ~~~~~^~~~~~~~~~~~~~~
potion.cpp:90:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | while(lx<sx.size() && ly < sy.size()){
| ~~^~~~~~~~~~
potion.cpp:90:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | while(lx<sx.size() && ly < sy.size()){
| ~~~^~~~~~~~~~~
potion.cpp:98:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | while(lx<sx.size() && sx[lx]=='0') lx++;
| ~~^~~~~~~~~~
potion.cpp:102:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
102 | while(ly<sy.size() && sy[ly]=='0') ly++;
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
7692 KB |
Incorrect |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
746 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
724 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
107 ms |
26184 KB |
Output is correct |
2 |
Correct |
118 ms |
25192 KB |
Output is correct |
3 |
Runtime error |
50 ms |
49852 KB |
Execution killed with signal 6 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
7248 KB |
Output is correct |
2 |
Incorrect |
6 ms |
7692 KB |
Incorrect |
3 |
Halted |
0 ms |
0 KB |
- |