Submission #614196

# Submission time Handle Problem Language Result Execution time Memory
614196 2022-07-30T21:40:43 Z GusterGoose27 Ruka (COI15_ruka) C++11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair<ll, ll> pii;

const ll MAXN = 1e5;
ll n, q;
const ll BSIZE = 301;
const ll MAXBLOCKS = 333;
ll num_blocks;
ll numsx[MAXN];
ll numsy[MAXN];
pii vecs[MAXN];

ll sign(ll v) {
	if (v == 0) return 0;
	if (v < 0) return -1;
	return 1;
}

class Block {
public:
	vector<ll> xstart;
	vector<ll> xend;
	vector<ll> ystart;
	vector<ll> yend;
	ll shiftx = 0;
	ll shifty = 0;
	ll lp, rp;
	Block() {}
	Block(ll lv, ll rv) {
		lp = lv;
		rp = rv;
		make();
	}
	void make() {
		xstart.clear();
		xend.clear();
		ystart.clear();
		yend.clear();
		for (ll i = lp; i <= rp; i++) {
			if (i > lp) {
				ll x1 = numsx[i];
				ll x2 = numsx[i-1];
				ll y1 = numsy[i];
				ll y2 = numsy[i-1];
				ll mnx = min(x1, x2);
				ll mxx = max(x1, x2);
				ll mny = min(y1, y2);
				ll mxy = max(y1, y2);
				xstart.push_back(-mxx);
				xend.push_back(-mnx);
				ystart.push_back(-mxy);
				yend.push_back(-mny);
			}
		}
		sort(xstart.begin(), xstart.end());
		sort(ystart.begin(), ystart.end());
		sort(xend.begin(), xend.end());
		sort(yend.begin(), yend.end());
	}
	ll bs(vector<ll> &v, ll pos) {
		ll mn = -1;
		ll mx = v.size();
		while (mx > mn+1) {
			ll cur = (mn+mx)/2;
			if (v[cur] < pos) mn = cur;
			else mx = cur;
			assert(v[cur] != pos);
		}
		return mn+1;
	}
	ll get() {
		return bs(xstart, shiftx)+bs(ystart, shifty)-bs(xend, shiftx)-bs(yend, shifty);
	}
	void upd(ll l, ll r, ll vx, ll vy) {
		for (ll i = lp; i <= rp; i++) {
			numsx[i] += shiftx;
			numsy[i] += shifty;
			if (l <= i && i <= r) {
				numsx[i] += vx;
				numsy[i] += vy;
			}
		}
		shiftx = 0;
		shifty = 0;
		make();
	}
};

Block blocks[MAXBLOCKS];

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> n;
	num_blocks = ceil((1.0*(n+1))/BSIZE);
	ll curx = 1;
	ll cury = 1;
	for (ll i = 0; i < n; i++) {
		numsx[i] = curx;
		numsy[i] = cury;
		ll x, y; cin >> x >> y;
		curx += x;
		cury += y;
		vecs[i] = pii(x, y);
	}
	numsx[n] = curx;
	numsy[n] = cury;
	for (ll i = 0; i < num_blocks; i++) {
		blocks[i] = Block(BSIZE*i, min(BSIZE*(i+1), n));
	}
	ll pos = 0;
	cin >> q;
	for (ll i = 0; i < q; i++) {
		char c; cin >> c;
		if (c == 'Q') {
			ll ans = 0;
			for (ll j = 0; j < num_blocks; j++) {
				ans += blocks[j].get();
				if (j < num_blocks-1) {
					ll x1 = numsx[blocks[j].rp]+blocks[j].shiftx;
					ll y1 = numsy[blocks[j].rp]+blocks[j].shifty;
					ll x2 = numsx[blocks[j+1].lp]+blocks[j+1].shiftx;
					ll y2 = numsy[blocks[j+1].lp]+blocks[j+1].shifty;
					ans += (sign(x1) != sign(x2)) + (sign(y1) != sign(y2));
				}
			}
			cout << ans << "\n";
		}
		if (c == 'B') {
			pos = max(pos-1, 0);
		}
		if (c == 'F') {
			pos = min(n-1, pos+1);
		}
		if (c == 'C') {
			ll x, y; cin >> x >> y;
			ll xsh = x-vecs[pos].first;
			ll ysh = y-vecs[pos].second;
			vecs[pos] = pii(x, y);
			for (ll j = 0; j < num_blocks; j++) {
				if (blocks[j].rp <= pos) continue;
				if (blocks[j].lp <= pos) {
					blocks[j].upd(pos+1, blocks[j].rp, xsh, ysh);
				}
				else {
					blocks[j].shiftx += xsh;
					blocks[j].shifty += ysh;
				}
			}
		}
	}
}

Compilation message

ruka.cpp:5:14: error: 'll' was not declared in this scope
    5 | typedef pair<ll, ll> pii;
      |              ^~
ruka.cpp:5:18: error: 'll' was not declared in this scope
    5 | typedef pair<ll, ll> pii;
      |                  ^~
ruka.cpp:5:20: error: template argument 1 is invalid
    5 | typedef pair<ll, ll> pii;
      |                    ^
ruka.cpp:5:20: error: template argument 2 is invalid
ruka.cpp:7:7: error: 'll' does not name a type
    7 | const ll MAXN = 1e5;
      |       ^~
ruka.cpp:8:1: error: 'll' does not name a type
    8 | ll n, q;
      | ^~
ruka.cpp:9:7: error: 'll' does not name a type
    9 | const ll BSIZE = 301;
      |       ^~
ruka.cpp:10:7: error: 'll' does not name a type
   10 | const ll MAXBLOCKS = 333;
      |       ^~
ruka.cpp:11:1: error: 'll' does not name a type
   11 | ll num_blocks;
      | ^~
ruka.cpp:12:1: error: 'll' does not name a type
   12 | ll numsx[MAXN];
      | ^~
ruka.cpp:13:1: error: 'll' does not name a type
   13 | ll numsy[MAXN];
      | ^~
ruka.cpp:14:10: error: 'MAXN' was not declared in this scope
   14 | pii vecs[MAXN];
      |          ^~~~
ruka.cpp:16:1: error: 'll' does not name a type
   16 | ll sign(ll v) {
      | ^~
ruka.cpp:24:9: error: 'll' was not declared in this scope
   24 |  vector<ll> xstart;
      |         ^~
ruka.cpp:24:11: error: template argument 1 is invalid
   24 |  vector<ll> xstart;
      |           ^
ruka.cpp:24:11: error: template argument 2 is invalid
ruka.cpp:25:9: error: 'll' was not declared in this scope
   25 |  vector<ll> xend;
      |         ^~
ruka.cpp:25:11: error: template argument 1 is invalid
   25 |  vector<ll> xend;
      |           ^
ruka.cpp:25:11: error: template argument 2 is invalid
ruka.cpp:26:9: error: 'll' was not declared in this scope
   26 |  vector<ll> ystart;
      |         ^~
ruka.cpp:26:11: error: template argument 1 is invalid
   26 |  vector<ll> ystart;
      |           ^
ruka.cpp:26:11: error: template argument 2 is invalid
ruka.cpp:27:9: error: 'll' was not declared in this scope
   27 |  vector<ll> yend;
      |         ^~
ruka.cpp:27:11: error: template argument 1 is invalid
   27 |  vector<ll> yend;
      |           ^
ruka.cpp:27:11: error: template argument 2 is invalid
ruka.cpp:28:2: error: 'll' does not name a type
   28 |  ll shiftx = 0;
      |  ^~
ruka.cpp:29:2: error: 'll' does not name a type
   29 |  ll shifty = 0;
      |  ^~
ruka.cpp:30:2: error: 'll' does not name a type
   30 |  ll lp, rp;
      |  ^~
ruka.cpp:32:10: error: expected ')' before 'lv'
   32 |  Block(ll lv, ll rv) {
      |       ~  ^~~
      |          )
ruka.cpp:63:2: error: 'll' does not name a type
   63 |  ll bs(vector<ll> &v, ll pos) {
      |  ^~
ruka.cpp:74:2: error: 'll' does not name a type
   74 |  ll get() {
      |  ^~
ruka.cpp:77:11: error: 'll' has not been declared
   77 |  void upd(ll l, ll r, ll vx, ll vy) {
      |           ^~
ruka.cpp:77:17: error: 'll' has not been declared
   77 |  void upd(ll l, ll r, ll vx, ll vy) {
      |                 ^~
ruka.cpp:77:23: error: 'll' has not been declared
   77 |  void upd(ll l, ll r, ll vx, ll vy) {
      |                       ^~
ruka.cpp:77:30: error: 'll' has not been declared
   77 |  void upd(ll l, ll r, ll vx, ll vy) {
      |                              ^~
ruka.cpp: In member function 'void Block::make()':
ruka.cpp:38:10: error: request for member 'clear' in '((Block*)this)->Block::xstart', which is of non-class type 'int'
   38 |   xstart.clear();
      |          ^~~~~
ruka.cpp:39:8: error: request for member 'clear' in '((Block*)this)->Block::xend', which is of non-class type 'int'
   39 |   xend.clear();
      |        ^~~~~
ruka.cpp:40:10: error: request for member 'clear' in '((Block*)this)->Block::ystart', which is of non-class type 'int'
   40 |   ystart.clear();
      |          ^~~~~
ruka.cpp:41:8: error: request for member 'clear' in '((Block*)this)->Block::yend', which is of non-class type 'int'
   41 |   yend.clear();
      |        ^~~~~
ruka.cpp:42:8: error: 'll' was not declared in this scope
   42 |   for (ll i = lp; i <= rp; i++) {
      |        ^~
ruka.cpp:42:19: error: 'i' was not declared in this scope
   42 |   for (ll i = lp; i <= rp; i++) {
      |                   ^
ruka.cpp:42:24: error: 'rp' was not declared in this scope
   42 |   for (ll i = lp; i <= rp; i++) {
      |                        ^~
ruka.cpp:43:12: error: 'lp' was not declared in this scope
   43 |    if (i > lp) {
      |            ^~
ruka.cpp:44:7: error: expected ';' before 'x1'
   44 |     ll x1 = numsx[i];
      |       ^~~
      |       ;
ruka.cpp:45:7: error: expected ';' before 'x2'
   45 |     ll x2 = numsx[i-1];
      |       ^~~
      |       ;
ruka.cpp:46:7: error: expected ';' before 'y1'
   46 |     ll y1 = numsy[i];
      |       ^~~
      |       ;
ruka.cpp:47:7: error: expected ';' before 'y2'
   47 |     ll y2 = numsy[i-1];
      |       ^~~
      |       ;
ruka.cpp:48:7: error: expected ';' before 'mnx'
   48 |     ll mnx = min(x1, x2);
      |       ^~~~
      |       ;
ruka.cpp:49:7: error: expected ';' before 'mxx'
   49 |     ll mxx = max(x1, x2);
      |       ^~~~
      |       ;
ruka.cpp:50:7: error: expected ';' before 'mny'
   50 |     ll mny = min(y1, y2);
      |       ^~~~
      |       ;
ruka.cpp:51:7: error: expected ';' before 'mxy'
   51 |     ll mxy = max(y1, y2);
      |       ^~~~
      |       ;
ruka.cpp:52:12: error: request for member 'push_back' in '((Block*)this)->Block::xstart', which is of non-class type 'int'
   52 |     xstart.push_back(-mxx);
      |            ^~~~~~~~~
ruka.cpp:52:23: error: 'mxx' was not declared in this scope
   52 |     xstart.push_back(-mxx);
      |                       ^~~
ruka.cpp:53:10: error: request for member 'push_back' in '((Block*)this)->Block::xend', which is of non-class type 'int'
   53 |     xend.push_back(-mnx);
      |          ^~~~~~~~~
ruka.cpp:53:21: error: 'mnx' was not declared in this scope
   53 |     xend.push_back(-mnx);
      |                     ^~~
ruka.cpp:54:12: error: request for member 'push_back' in '((Block*)this)->Block::ystart', which is of non-class type 'int'
   54 |     ystart.push_back(-mxy);
      |            ^~~~~~~~~
ruka.cpp:54:23: error: 'mxy' was not declared in this scope
   54 |     ystart.push_back(-mxy);
      |                       ^~~
ruka.cpp:55:10: error: request for member 'push_back' in '((Block*)this)->Block::yend', which is of non-class type 'int'
   55 |     yend.push_back(-mny);
      |          ^~~~~~~~~
ruka.cpp:55:21: error: 'mny' was not declared in this scope
   55 |     yend.push_back(-mny);
      |                     ^~~
ruka.cpp:58:15: error: request for member 'begin' in '((Block*)this)->Block::xstart', which is of non-class type 'int'
   58 |   sort(xstart.begin(), xstart.end());
      |               ^~~~~
ruka.cpp:58:31: error: request for member 'end' in '((Block*)this)->Block::xstart', which is of non-class type 'int'
   58 |   sort(xstart.begin(), xstart.end());
      |                               ^~~
ruka.cpp:59:15: error: request for member 'begin' in '((Block*)this)->Block::ystart', which is of non-class type 'int'
   59 |   sort(ystart.begin(), ystart.end());
      |               ^~~~~
ruka.cpp:59:31: error: request for member 'end' in '((Block*)this)->Block::ystart', which is of non-class type 'int'
   59 |   sort(ystart.begin(), ystart.end());
      |                               ^~~
ruka.cpp:60:13: error: request for member 'begin' in '((Block*)this)->Block::xend', which is of non-class type 'int'
   60 |   sort(xend.begin(), xend.end());
      |             ^~~~~
ruka.cpp:60:27: error: request for member 'end' in '((Block*)this)->Block::xend', which is of non-class type 'int'
   60 |   sort(xend.begin(), xend.end());
      |                           ^~~
ruka.cpp:61:13: error: request for member 'begin' in '((Block*)this)->Block::yend', which is of non-class type 'int'
   61 |   sort(yend.begin(), yend.end());
      |             ^~~~~
ruka.cpp:61:27: error: request for member 'end' in '((Block*)this)->Block::yend', which is of non-class type 'int'
   61 |   sort(yend.begin(), yend.end());
      |                           ^~~
ruka.cpp: In member function 'void Block::upd(int, int, int, int)':
ruka.cpp:78:8: error: 'll' was not declared in this scope; did you mean 'l'?
   78 |   for (ll i = lp; i <= rp; i++) {
      |        ^~
      |        l
ruka.cpp:78:19: error: 'i' was not declared in this scope
   78 |   for (ll i = lp; i <= rp; i++) {
      |                   ^
ruka.cpp:78:24: error: 'rp' was not declared in this scope; did you mean 'r'?
   78 |   for (ll i = lp; i <= rp; i++) {
      |                        ^~
      |                        r
ruka.cpp:79:4: error: 'numsx' was not declared in this scope
   79 |    numsx[i] += shiftx;
      |    ^~~~~
ruka.cpp:79:16: error: 'shiftx' was not declared in this scope
   79 |    numsx[i] += shiftx;
      |                ^~~~~~
ruka.cpp:80:4: error: 'numsy' was not declared in this scope
   80 |    numsy[i] += shifty;
      |    ^~~~~
ruka.cpp:80:16: error: 'shifty' was not declared in this scope
   80 |    numsy[i] += shifty;
      |                ^~~~~~
ruka.cpp:86:3: error: 'shiftx' was not declared in this scope
   86 |   shiftx = 0;
      |   ^~~~~~
ruka.cpp:87:3: error: 'shifty' was not declared in this scope
   87 |   shifty = 0;
      |   ^~~~~~
ruka.cpp: At global scope:
ruka.cpp:92:14: error: 'MAXBLOCKS' was not declared in this scope
   92 | Block blocks[MAXBLOCKS];
      |              ^~~~~~~~~
ruka.cpp: In function 'int main()':
ruka.cpp:96:9: error: 'n' was not declared in this scope; did you mean 'yn'?
   96 |  cin >> n;
      |         ^
      |         yn
ruka.cpp:97:2: error: 'num_blocks' was not declared in this scope
   97 |  num_blocks = ceil((1.0*(n+1))/BSIZE);
      |  ^~~~~~~~~~
ruka.cpp:97:32: error: 'BSIZE' was not declared in this scope
   97 |  num_blocks = ceil((1.0*(n+1))/BSIZE);
      |                                ^~~~~
ruka.cpp:98:2: error: 'll' was not declared in this scope
   98 |  ll curx = 1;
      |  ^~
ruka.cpp:99:4: error: expected ';' before 'cury'
   99 |  ll cury = 1;
      |    ^~~~~
      |    ;
ruka.cpp:100:9: error: expected ';' before 'i'
  100 |  for (ll i = 0; i < n; i++) {
      |         ^~
      |         ;
ruka.cpp:100:17: error: 'i' was not declared in this scope
  100 |  for (ll i = 0; i < n; i++) {
      |                 ^
ruka.cpp:101:3: error: 'numsx' was not declared in this scope
  101 |   numsx[i] = curx;
      |   ^~~~~
ruka.cpp:101:14: error: 'curx' was not declared in this scope
  101 |   numsx[i] = curx;
      |              ^~~~
ruka.cpp:102:3: error: 'numsy' was not declared in this scope
  102 |   numsy[i] = cury;
      |   ^~~~~
ruka.cpp:102:14: error: 'cury' was not declared in this scope
  102 |   numsy[i] = cury;
      |              ^~~~
ruka.cpp:103:5: error: expected ';' before 'x'
  103 |   ll x, y; cin >> x >> y;
      |     ^~
      |     ;
ruka.cpp:103:19: error: 'x' was not declared in this scope
  103 |   ll x, y; cin >> x >> y;
      |                   ^
ruka.cpp:103:24: error: 'y' was not declared in this scope; did you mean 'yn'?
  103 |   ll x, y; cin >> x >> y;
      |                        ^
      |                        yn
ruka.cpp:106:3: error: 'vecs' was not declared in this scope
  106 |   vecs[i] = pii(x, y);
      |   ^~~~
ruka.cpp:106:21: error: expression list treated as compound expression in functional cast [-fpermissive]
  106 |   vecs[i] = pii(x, y);
      |                     ^
ruka.cpp:108:2: error: 'numsx' was not declared in this scope
  108 |  numsx[n] = curx;
      |  ^~~~~
ruka.cpp:108:13: error: 'curx' was not declared in this scope
  108 |  numsx[n] = curx;
      |             ^~~~
ruka.cpp:109:2: error: 'numsy' was not declared in this scope
  109 |  numsy[n] = cury;
      |  ^~~~~
ruka.cpp:109:13: error: 'cury' was not declared in this scope
  109 |  numsy[n] = cury;
      |             ^~~~
ruka.cpp:110:9: error: expected ';' before 'i'
  110 |  for (ll i = 0; i < num_blocks; i++) {
      |         ^~
      |         ;
ruka.cpp:110:17: error: 'i' was not declared in this scope
  110 |  for (ll i = 0; i < num_blocks; i++) {
      |                 ^
ruka.cpp:111:3: error: 'blocks' was not declared in this scope; did you mean 'Block'?
  111 |   blocks[i] = Block(BSIZE*i, min(BSIZE*(i+1), n));
      |   ^~~~~~
      |   Block
ruka.cpp:113:4: error: expected ';' before 'pos'
  113 |  ll pos = 0;
      |    ^~~~
      |    ;
ruka.cpp:114:9: error: 'q' was not declared in this scope
  114 |  cin >> q;
      |         ^
ruka.cpp:115:9: error: expected ';' before 'i'
  115 |  for (ll i = 0; i < q; i++) {
      |         ^~
      |         ;
ruka.cpp:115:17: error: 'i' was not declared in this scope
  115 |  for (ll i = 0; i < q; i++) {
      |                 ^
ruka.cpp:118:6: error: expected ';' before 'ans'
  118 |    ll ans = 0;
      |      ^~~~
      |      ;
ruka.cpp:119:11: error: expected ';' before 'j'
  119 |    for (ll j = 0; j < num_blocks; j++) {
      |           ^~
      |           ;
ruka.cpp:119:19: error: 'j' was not declared in this scope
  119 |    for (ll j = 0; j < num_blocks; j++) {
      |                   ^
ruka.cpp:120:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
  120 |     ans += blocks[j].get();
      |     ^~~
      |     abs
ruka.cpp:120:12: error: 'blocks' was not declared in this scope; did you mean 'Block'?
  120 |     ans += blocks[j].get();
      |            ^~~~~~
      |            Block
ruka.cpp:122:8: error: expected ';' before 'x1'
  122 |      ll x1 = numsx[blocks[j].rp]+blocks[j].shiftx;
      |        ^~~
      |        ;
ruka.cpp:123:8: error: expected ';' before 'y1'
  123 |      ll y1 = numsy[blocks[j].rp]+blocks[j].shifty;
      |        ^~~
      |        ;
ruka.cpp:124:8: error: expected ';' before 'x2'
  124 |      ll x2 = numsx[blocks[j+1].lp]+blocks[j+1].shiftx;
      |        ^~~
      |        ;
ruka.cpp:125:8: error: expected ';' before 'y2'
  125 |      ll y2 = numsy[blocks[j+1].lp]+blocks[j+1].shifty;
      |        ^~~
      |        ;
ruka.cpp:126:19: error: 'x1' was not declared in this scope; did you mean 'y1'?
  126 |      ans += (sign(x1) != sign(x2)) + (sign(y1) != sign(y2));
      |                   ^~
      |                   y1
ruka.cpp:126:14: error: 'sign' was not declared in this scope; did you mean 'sin'?
  126 |      ans += (sign(x1) != sign(x2)) + (sign(y1) != sign(y2));
      |              ^~~~
      |              sin
ruka.cpp:126:31: error: 'x2' was not declared in this scope
  126 |      ans += (sign(x1) != sign(x2)) + (sign(y1) != sign(y2));
      |                               ^~
ruka.cpp:126:56: error: 'y2' was not declared in this scope; did you mean 'yn'?
  126 |      ans += (sign(x1) != sign(x2)) + (sign(y1) != sign(y2));
      |                                                        ^~
      |                                                        yn
ruka.cpp:129:12: error: 'ans' was not declared in this scope; did you mean 'abs'?
  129 |    cout << ans << "\n";
      |            ^~~
      |            abs
ruka.cpp:132:4: error: 'pos' was not declared in this scope; did you mean 'pow'?
  132 |    pos = max(pos-1, 0);
      |    ^~~
      |    pow
ruka.cpp:135:4: error: 'pos' was not declared in this scope; did you mean 'pow'?
  135 |    pos = min(n-1, pos+1);
      |    ^~~
      |    pow
ruka.cpp:138:6: error: expected ';' before 'x'
  138 |    ll x, y; cin >> x >> y;
      |      ^~
      |      ;
ruka.cpp:138:20: error: 'x' was not declared in this scope
  138 |    ll x, y; cin >> x >> y;
      |                    ^
ruka.cpp:138:25: error: 'y' was not declared in this scope
  138 |    ll x, y; cin >> x >> y;
      |                         ^
ruka.cpp:139:6: error: expected ';' before 'xsh'
  139 |    ll xsh = x-vecs[pos].first;
      |      ^~~~
      |      ;
ruka.cpp:140:6: error