Submission #104914

# Submission time Handle Problem Language Result Execution time Memory
104914 2019-04-09T16:00:43 Z eriksuenderhauf Game (IOI13_game) C++11
100 / 100
5848 ms 77956 KB
#include <bits/stdc++.h>
#include "game.h"
//#include "grader.h"
#define pii pair<int, int>
#define pll pair<long long, long long>
#define vii vector<pii>
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long int ll;
int R, C;

ll gcd(ll x, ll y) {
	if (x == 0 || y == 0) return max(x, y);
	return __gcd(x, y);
}

struct nodeY
{
	int lo, hi;
	nodeY *l=0, *r=0;
	ll val = 0;
};

struct nodeX {
	nodeX *l=0, *r=0;
	nodeY *root=0;
	nodeX() {
		l = 0, r = 0;
		root = new nodeY();
		root->lo = 0, root->hi = C - 1;
	}
};
nodeX *root=0;

ll qry2(nodeY *cur, int yL, int yH) {
	if (!cur) return 0;
	if (yH < cur->lo || cur->hi < yL) return 0;
	if (yL <= cur->lo && cur->hi <= yH) return cur->val;
	return gcd(qry2(cur->l, yL, yH), qry2(cur->r, yL, yH));
}

ll qry1(nodeX *cur, int l, int r, int xL, int xH, int yL, int yH) {
	if (!cur) return 0;
	if (r < xL || xH < l) return 0;
	if (xL <= l && r <= xH) return qry2(cur->root, yL, yH);
	int m = (l + r) / 2;
	return gcd(qry1(cur->l, l, m, xL, xH, yL, yH), qry1(cur->r, m+1, r, xL, xH, yL, yH));
}

void upd2(nodeY *cur, int y, ll val) {
	if (cur->lo == cur->hi) {
		cur->val = val;
		return;
	}
	int m = (cur->lo + cur->hi) / 2;
	nodeY *&nxt = (y <= m) ? cur->l : cur->r;
	if (!nxt) {
		nxt = new nodeY();
		nxt->lo = y, nxt->hi = y;
		nxt->val = val;
	} else if (nxt->lo <= y && y <= nxt->hi)
		upd2(nxt, y, val);
	else {
		nodeY *nx = new nodeY();
		nx->lo = cur->lo, nx->hi = cur->hi;
		do {
			if (y <= m)
				nx->hi = m;
			else
				nx->lo = m + 1;
			m = (nx->lo + nx->hi) / 2;
		} while ((y <= m) == (nxt->lo <= m));
		if (y <= m)
			nx->r = nxt;
		else
			nx->l = nxt;
		nxt = nx;
		upd2(nx, y, val);
	}
	ll a = 0, b = 0;
	if (cur->l) a = cur->l->val;
	if (cur->r) b = cur->r->val;
	cur->val = gcd(a, b);
}

void upd1(int l, int r, nodeX *cur, int x, int y, ll val) {
	if (l == r) {
		upd2(cur->root, y, val);
		return;
	}
	int m = (l + r) / 2;
	ll a = 0, b = 0;
	if (x <= m) {
		if (!cur->l) cur->l = new nodeX();
		upd1(l, m, cur->l, x, y, val);
	} else {
		if (!cur->r) cur->r = new nodeX();
		upd1(m+1, r, cur->r, x, y, val);
	}
	if (cur->l) a = qry2(cur->l->root, y, y);
	if (cur->r) b = qry2(cur->r->root, y, y);
	upd2(cur->root, y, gcd(a, b));
}

void init(int R1, int C1) {
	R = R1, C = C1;
	root = new nodeX();
}

void update(int p, int q, ll k) {
	upd1(0, R-1, root, p, q, k);
}

ll calculate(int p, int q, int u, int v) {
	return qry1(root, 0, R-1, p, u, q, v);	
}

Compilation message

grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
  int res;
      ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 3 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 3 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 304 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 855 ms 8672 KB Output is correct
5 Correct 566 ms 9020 KB Output is correct
6 Correct 707 ms 5816 KB Output is correct
7 Correct 933 ms 5564 KB Output is correct
8 Correct 442 ms 4264 KB Output is correct
9 Correct 835 ms 5780 KB Output is correct
10 Correct 796 ms 5460 KB Output is correct
11 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 1430 ms 12112 KB Output is correct
13 Correct 2796 ms 5468 KB Output is correct
14 Correct 346 ms 1260 KB Output is correct
15 Correct 3085 ms 6680 KB Output is correct
16 Correct 348 ms 10360 KB Output is correct
17 Correct 1424 ms 6596 KB Output is correct
18 Correct 2966 ms 10872 KB Output is correct
19 Correct 2148 ms 10800 KB Output is correct
20 Correct 2332 ms 10384 KB Output is correct
21 Correct 3 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 428 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 3 ms 512 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 880 ms 8696 KB Output is correct
13 Correct 575 ms 8952 KB Output is correct
14 Correct 754 ms 5752 KB Output is correct
15 Correct 962 ms 5592 KB Output is correct
16 Correct 459 ms 4256 KB Output is correct
17 Correct 809 ms 5684 KB Output is correct
18 Correct 858 ms 5348 KB Output is correct
19 Correct 1402 ms 11816 KB Output is correct
20 Correct 2783 ms 5428 KB Output is correct
21 Correct 313 ms 1448 KB Output is correct
22 Correct 3104 ms 6608 KB Output is correct
23 Correct 262 ms 10332 KB Output is correct
24 Correct 1303 ms 6740 KB Output is correct
25 Correct 2840 ms 10896 KB Output is correct
26 Correct 2291 ms 11088 KB Output is correct
27 Correct 2003 ms 10360 KB Output is correct
28 Correct 709 ms 36856 KB Output is correct
29 Correct 2220 ms 39428 KB Output is correct
30 Correct 4464 ms 31132 KB Output is correct
31 Correct 3810 ms 24180 KB Output is correct
32 Correct 506 ms 2396 KB Output is correct
33 Correct 706 ms 2860 KB Output is correct
34 Correct 463 ms 36444 KB Output is correct
35 Correct 1988 ms 20168 KB Output is correct
36 Correct 3995 ms 36720 KB Output is correct
37 Correct 3060 ms 36912 KB Output is correct
38 Correct 3031 ms 36240 KB Output is correct
39 Correct 2566 ms 28780 KB Output is correct
40 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 4 ms 432 KB Output is correct
4 Correct 2 ms 300 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 352 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 3 ms 384 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 2 ms 384 KB Output is correct
12 Correct 704 ms 8332 KB Output is correct
13 Correct 622 ms 8624 KB Output is correct
14 Correct 721 ms 5496 KB Output is correct
15 Correct 941 ms 5336 KB Output is correct
16 Correct 468 ms 3936 KB Output is correct
17 Correct 876 ms 5412 KB Output is correct
18 Correct 807 ms 4944 KB Output is correct
19 Correct 1313 ms 11768 KB Output is correct
20 Correct 2892 ms 5172 KB Output is correct
21 Correct 342 ms 1088 KB Output is correct
22 Correct 3129 ms 6276 KB Output is correct
23 Correct 313 ms 10160 KB Output is correct
24 Correct 1277 ms 6388 KB Output is correct
25 Correct 2907 ms 10476 KB Output is correct
26 Correct 2111 ms 10572 KB Output is correct
27 Correct 2017 ms 9824 KB Output is correct
28 Correct 808 ms 36376 KB Output is correct
29 Correct 2307 ms 39064 KB Output is correct
30 Correct 4048 ms 30788 KB Output is correct
31 Correct 3597 ms 23524 KB Output is correct
32 Correct 443 ms 1700 KB Output is correct
33 Correct 652 ms 2468 KB Output is correct
34 Correct 437 ms 35836 KB Output is correct
35 Correct 1805 ms 19380 KB Output is correct
36 Correct 3893 ms 36256 KB Output is correct
37 Correct 3005 ms 36420 KB Output is correct
38 Correct 2972 ms 35796 KB Output is correct
39 Correct 1057 ms 76940 KB Output is correct
40 Correct 4171 ms 77956 KB Output is correct
41 Correct 5848 ms 63776 KB Output is correct
42 Correct 5512 ms 48260 KB Output is correct
43 Correct 918 ms 76100 KB Output is correct
44 Correct 656 ms 1844 KB Output is correct
45 Correct 2322 ms 28332 KB Output is correct
46 Correct 4839 ms 76256 KB Output is correct
47 Correct 5097 ms 76384 KB Output is correct
48 Correct 4877 ms 75904 KB Output is correct
49 Correct 2 ms 256 KB Output is correct