#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(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;
}
if(op == 0){
if(seg[node] != 0) seg[node*2] = seg[node*2+1] = seg[node];
seg[node] = 0;
}
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
synchronization.cpp: In function 'int main()':
synchronization.cpp:105: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:108: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:112:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&query[i]);
^
synchronization.cpp:115: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:44:7: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
int t;
^
synchronization.cpp:44:7: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
synchronization.cpp:44:7: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
13076 KB |
Output is correct |
2 |
Execution timed out |
8000 ms |
13076 KB |
Execution timed out |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8000 ms |
13076 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
13076 KB |
Output is correct |
2 |
Correct |
0 ms |
13076 KB |
Output is correct |
3 |
Correct |
0 ms |
13076 KB |
Output is correct |
4 |
Correct |
0 ms |
13076 KB |
Output is correct |
5 |
Correct |
0 ms |
13076 KB |
Output is correct |
6 |
Correct |
3 ms |
13076 KB |
Output is correct |
7 |
Correct |
46 ms |
13076 KB |
Output is correct |
8 |
Correct |
496 ms |
13076 KB |
Output is correct |
9 |
Correct |
489 ms |
13076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
476 ms |
13076 KB |
Output is correct |
2 |
Correct |
259 ms |
13076 KB |
Output is correct |
3 |
Correct |
266 ms |
13076 KB |
Output is correct |
4 |
Correct |
243 ms |
13076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
8000 ms |
13076 KB |
Execution timed out |
2 |
Halted |
0 ms |
0 KB |
- |