Submission #25455

# Submission time Handle Problem Language Result Execution time Memory
25455 2017-06-22T07:59:27 Z 서규호(#1066) Synchronization (JOI13_synchronization) C++14
0 / 100
416 ms 13076 KB
#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;
		}
		int mid = (l+r)/2;
		update(node*2,l,mid,s,e,value);
		update(node*2+1,mid+1,r,s,e,value);
		if(op == 0) seg[node] = 0;
	}
	int get(int x){
		int t;
		if(op == 1) t = INF;
		else 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;

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]]);	
	}
}

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);
	}
	for(int i=1; i<=M; i++){
		scanf("%d",&query[i]);
	}
	for(int i=1; i<=Q; i++){
		scanf("%d",&server[i]);
	}
	process2();

	return 0;
}

Compilation message

synchronization.cpp: In function 'int main()':
synchronization.cpp:101: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:104: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:107:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&query[i]);
                        ^
synchronization.cpp:110:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&server[i]);
                         ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13076 KB Output is correct
2 Incorrect 0 ms 13076 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 273 ms 13076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13076 KB Output is correct
2 Incorrect 0 ms 13076 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 416 ms 13076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 13076 KB Output isn't correct
2 Halted 0 ms 0 KB -