Submission #27370

# Submission time Handle Problem Language Result Execution time Memory
27370 2017-07-12T10:48:34 Z kdh9949 Ruka (COI15_ruka) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

int n, q, l, tx[2], dx[100010][2], off;

const int B = 50000010;
struct BIT{
	map<int, int> dat;
	void upd(int x, int v){ for(x += B; x <= 2 * B; x += x & -x) dat[x] += v; }
	int get(int x){ int ret = 0; for(x += B; x; x -= x & -x) ret += dat[x]; return ret; }
} U[2], D[2];

void ap(int t){
	int nx = t[x] + dx[l][t];
	int s = min(t[x], nx), e = max(t[x], nx);
	D[t].upd(s + off, -1); D[t].upd(e + off, 1);
	U[t].upd(s, 1); U[t].upd(e, -1);
	t[x] += dx[l++][t];
}

void dui(int t){
	t[x] -= dx[--l][t];
	int nx = t[x] + dx[l][t];
	int s = min(t[x], nx), e = max(t[x], nx);
	U[t].upd(s, -1); U[t].upd(e, 1);
	D[t].upd(s + off, 1); D[t].upd(e + off, -1);
}

void upd(int t, int v){
	dx[t][l] += v;
	off -= v;
}

int get(int t){
	return U[t].get(0) + D[t].get(off);
}

int main(){
	scanf("%d", &n);
	tx[0] = tx[1] = 1;
	for(int i = 1; i <= n; i++){
		scanf("%d%d", dx[i], dx[i] + 1);
		for(int t = 0; t < 2; t++){
			int nx = tx[t] + dx[t][i];
			D[t].upd(min(tx[t], nx), 1);
			D[t].upd(max(tx[t], nx), -1);
			tx[t] = nx;
		}
	}
	l = 1;
	tx[0] = tx[1] = 1;
	scanf("%d", &q);
	for(char t; q--; ){
		scanf(" %c", &t);
		if(t == 'F' && l < n){ ap(0); ap(1); }
		else if(t == 'B' && l > 1){ dui(0); dui(1); }
		else if(t == 'C'){
			int x[2]; scanf("%d%d", x, x + 1);
			upd(0, x[0]); upd(1, x[1]);
		}
		else{
			printf("%d\n", get(0) + get(1));
		}
	}
}

Compilation message

ruka.cpp: In function 'void ap(int)':
ruka.cpp:14:13: error: 'x' was not declared in this scope
  int nx = t[x] + dx[l][t];
             ^
ruka.cpp:16:34: error: 'e' was not declared in this scope
  D[t].upd(s + off, -1); D[t].upd(e + off, 1);
                                  ^
ruka.cpp: In function 'void dui(int)':
ruka.cpp:22:4: error: 'x' was not declared in this scope
  t[x] -= dx[--l][t];
    ^
ruka.cpp:25:28: error: 'e' was not declared in this scope
  U[t].upd(s, -1); U[t].upd(e, 1);
                            ^
ruka.cpp: In function 'int main()':
ruka.cpp:39:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
ruka.cpp:42:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", dx[i], dx[i] + 1);
                                  ^
ruka.cpp:52:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &q);
                 ^
ruka.cpp:54:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf(" %c", &t);
                   ^
ruka.cpp:58:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int x[2]; scanf("%d%d", x, x + 1);
                                     ^