Submission #27309

# Submission time Handle Problem Language Result Execution time Memory
27309 2017-07-12T07:55:11 Z 서규호(#1142) Ruka (COI15_ruka) C++14
0 / 100
0 ms 14520 KB
#include <bits/stdc++.h>

#define lld long long
#define pii pair<int,int>
#define pll pair<lld,lld>
#define pb push_back
#define next nextt
#define Inf 1000000000
#define Linf 1000000000000000000LL
#define Mod 1000000007

using namespace std;

int N,M,where,sqrtn,ans,bsize;
int nx[100002],ny[100002];
int sx[100002],ex[100002],sy[100002],ey[100002];
struct data{
	int x,y;
}a[100002];
pii memox[100002],memoy[100002];
struct SEG{
	int tmp[1000000];
	void update(int s,int e,int add){
		for(int i=s+500000; i<=e+500000; i++) tmp[i]+= add;
	}
	int get(int it){
		return tmp[it+500000];
	}
}seg1,seg2;

void f(int num){
	if(a[num].x > 0){
		sx[num] = -a[num].x-nx[num];
		ex[num] = -nx[num];
	}else if(a[num].x < 0){
		sx[num] = -nx[num];
		ex[num] = -a[num].x-nx[num];
	}else{
		sx[num] = 1; ex[num] = 0;
	}
	if(a[num].y > 0){
		sy[num] = -a[num].y-ny[num];
		ey[num] = -ny[num];
	}else if(a[num].y < 0){
		sy[num] = -ny[num];
		ey[num] = -a[num].y-ny[num];
	}else{
		sy[num] = 1; ey[num] = 0;
	}
}

int main(){
	scanf("%d",&N);
	for(int i=1; i<=N; i++) scanf("%d %d",&a[i].x,&a[i].y);
	scanf("%d",&M);
	nx[1] = ny[1] = 1;
	for(int i=1; i<=N; i++){
		nx[i+1] = nx[i]+a[i].x;
		ny[i+1] = ny[i]+a[i].y;
		f(i);
		if(sx[i] <= 0 && 0 <= ex[i]) ans++;
		if(sy[i] <= 0 && 0 <= ey[i]) ans++;
	}
	for(int i=N; i>=2; i--){
		memox[i] = {sx[i],ex[i]};
		if(sx[i] <= ex[i]) seg1.update(sx[i],ex[i],1);
		memoy[i] = {sy[i],ey[i]};
		if(sy[i] <= ey[i]) seg2.update(sy[i],ey[i],1);
	}

	int addx = 0,addy = 0;
	where = 1;
	for(int i=1; i<=M; i++){
		int x,y;
		char s[3];
		scanf("%s",s);
		if(s[0] == 'B'){
			if(where != 1){
				memox[where] = {sx[where]+addx,ex[where]+addx};
				memoy[where] = {sy[where]+addy,ey[where]+addy};
				seg1.update(memox[where].first,memox[where].second,1);
				seg2.update(memoy[where].first,memoy[where].second,1);
				where--;
			}
		}else if(s[0] == 'F'){
			if(where != N){
				where++;
				seg1.update(memox[where].first,memox[where].second,-1);
				seg2.update(memoy[where].first,memoy[where].second,-1);
				nx[where] += addx;
				ny[where] += addy;
				f(where);
			}
			if(where == N){
				addx = addy = 0;
			}
		}
		else if(s[0] == 'Q'){
			printf("%d\n",ans);
		}else{
			scanf("%d %d",&x,&y);
			if(sx[where] <= 0 && 0 <= ex[where]) ans--;
			if(sy[where] <= 0 && 0 <= ey[where]) ans--;
			ans -= seg1.get(addx); ans -= seg2.get(addy);
			addx += (x-a[where].x); addy += (y-a[where].y);
			ans += seg1.get(addx); ans += seg2.get(addy);
			a[where].x = x; a[where].y = y;
			f(where);
			if(sx[where] <= 0 && 0 <= ex[where]) ans++;
			if(sy[where] <= 0 && 0 <= ey[where]) ans++;
		}
	}

	return 0;
}

Compilation message

ruka.cpp: In function 'int main()':
ruka.cpp:53:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&N);
                ^
ruka.cpp:54:56: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1; i<=N; i++) scanf("%d %d",&a[i].x,&a[i].y);
                                                        ^
ruka.cpp:55:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&M);
                ^
ruka.cpp:76:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%s",s);
                ^
ruka.cpp:101:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d",&x,&y);
                        ^
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 14520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 14520 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 14520 KB Output isn't correct
2 Halted 0 ms 0 KB -