This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define lld long long
#define pp pair<int,int>
#define pb push_back
#define MOD 10007
#define left lleft
#define right rright
#define INF 2000000000
#define Linf 1000000000000000000LL
#define next nnext
#define minus mminus
using namespace std;
int N,M,Q,nn;
int ans[100002];
int query[200002],server[100002];
bool check[100002];
struct data{
int x,y;
}a[100002];
vector<int> edge[100002];
struct SEG{
int op;
int seg[400000];
void update(int node,int l,int r,int s,int e,int value){
if(r < s || e < l) return;
if(op == 0) seg[node] = 0;
if(s <= l && r <= e){
if(op == 1) seg[node] = min(seg[node],value);
else if(op == 2) seg[node] = max(seg[node],value);
else seg[node] = value;
return;
}
int mid = (l+r)/2;
update(node*2,l,mid,s,e,value);
update(node*2+1,mid+1,r,s,e,value);
}
int get(int x){
int t;
if(op == 1) t = INF;
else if(op == 2) t = 0;
x += (nn-1);
while(x){
if(op == 1) t = min(t,seg[x]);
else if(op == 2) t = max(t,seg[x]);
x /= 2;
}
return t;
}
int get2(int node,int l,int r,int x){
if(r < x || x < l) return 0;
if(seg[node] != 0) return seg[node];
int mid = (l+r)/2;
return max(get2(node*2,l,mid,x),get2(node*2+1,mid+1,r,x));
}
}minseg,maxseg,rsseg,reseg;
bool pflag2 = true;
void process2(){
minseg.op = 1; maxseg.op = 2;
for(int i=1; i<nn*2; i++){
minseg.seg[i] = INF;
}
for(int i=1; i<=N; i++){
minseg.update(1,1,nn,i,i,i);
maxseg.update(1,1,nn,i,i,i);
rsseg.update(1,1,nn,i,i,i);
reseg.update(1,1,nn,i,i,i);
}
for(int i=1; i<=M; i++){
int x,y;
x = a[query[i]].x; y = a[query[i]].y;
check[query[i]] = !check[query[i]];
if(check[query[i]]){
int s1,e1,s2,e2;
s1 = rsseg.get2(1,1,nn,x); e1 = x;
s2 = y; e2 = reseg.get2(1,1,nn,y);
maxseg.update(1,1,nn,s1,e1,maxseg.get(y));
minseg.update(1,1,nn,s2,e2,minseg.get(x));
reseg.update(1,1,nn,s1,e1,e2);
rsseg.update(1,1,nn,s2,e2,s1);
}else{
int s,e;
s = rsseg.get2(1,1,nn,x);
e = reseg.get2(1,1,nn,y);
reseg.update(1,1,nn,s,x,x);
rsseg.update(1,1,nn,y,e,y);
}
}
for(int i=1; i<=N; i++){
ans[i] = maxseg.get(i)-minseg.get(i)+1;
}
for(int i=1; i<=Q; i++){
printf("%d\n",ans[server[i]]);
}
exit(0);
}
int main(){
scanf("%d %d %d",&N,&M,&Q);
for(nn=1; nn<N; nn*=2);
for(int i=1; i<N; i++){
scanf("%d %d",&a[i].x,&a[i].y);
if(!(a[i].x == i && a[i].y == i+1)) pflag2 = false;
}
for(int i=1; i<=M; i++){
scanf("%d",&query[i]);
}
for(int i=1; i<=Q; i++){
scanf("%d",&server[i]);
}
if(pflag2) process2();
while(true);
return 0;
}
Compilation message (stderr)
synchronization.cpp: In function 'int main()':
synchronization.cpp:102:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&N,&M,&Q);
^
synchronization.cpp:105:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&a[i].x,&a[i].y);
^
synchronization.cpp:109:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&query[i]);
^
synchronization.cpp:112:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&server[i]);
^
synchronization.cpp: In function 'void process2()':
synchronization.cpp:41:7: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
int t;
^
synchronization.cpp:41:7: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
synchronization.cpp:41:7: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |