답안 #954613

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
954613 2024-03-28T08:25:28 Z islingr 게임 (IOI13_game) C++17
100 / 100
7242 ms 211916 KB
#include "bits/stdc++.h"
#include "game.h"
using namespace std;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
using ll = long long;
using K = array<int, 2>;
 
struct Node {
	Node *l = 0, *r = 0;
 
	ll  v, g;
	K key;
	int y;
	Node(ll val, K key) : v(val), g(val), key(key), y(rng()) {}
	void pull();
};
ll val(Node* n) { return n ? n->g : 0; }
void Node::pull() { g = gcd(val(l), gcd(v, val(r))); }
 
pair<Node*, Node*> split(Node* n, K k) {
	if (!n) return {};
	if (n->key >= k) {
		auto pa = split(n->l, k);
		n->l = pa.second;
		n->pull();
		return {pa.first, n};
	} else {
		auto pa = split(n->r, k);
		n->r = pa.first;
		n->pull();
		return {n, pa.second};
	}
}
 
Node* merge(Node* l, Node* r) {
	if (!l) return r;
	if (!r) return l;
	if (l->y > r->y) {
		l->r = merge(l->r, r);
		l->pull();
		return l;
	} else {
		r->l = merge(l, r->l);
		r->pull();
		return r;
	}
}
 
struct gcd_treap {
	Node* root;
 
	gcd_treap() : root{nullptr} {}
	void set(K k, ll val) {
		Node *L, *X, *R;
		tie(L, X) = split(root, k);
		++k[1];
		tie(X, R) = split(X, k);
		--k[1];
		delete X;
		auto new_node = new Node(val, k);
		root = merge(L, merge(new_node, R));
	}
 
	ll query(int l, int r) {
		const K kl = {l, -1}, kr = {r, -1};
		Node *L, *X, *R;
		tie(L, X) = split(root, kl);
		tie(X, R) = split(X, kr);
		const auto g = val(X);
		root = merge(L, merge(X, R));
		return g;
	}
};
 
struct segtree {
	int sz;
	unordered_map<int, gcd_treap> t;
 
	segtree() {}
	segtree(int n) : sz{1} {
		while (sz < n) sz *= 2;
	}
 
	ll query(int l, int r, int u, int d) {
		ll g = 0;
		for (l += sz, r += sz; l < r; l /= 2, r /= 2) {
			if (l & 1) g = gcd(g, t[l++].query(u, d));
			if (r & 1) g = gcd(g, t[--r].query(u, d));
		}
		return g;
	}
 
	void set(int x, int y, ll val) {
		for (int p = x + sz; p > 0; p /= 2)
			t[p].set({y, x}, val);
	}
};
segtree t;
 
void init(int n, int m) { t = segtree(n); }
 
void update(int i, int j, ll val) {
	t.set(i, j, val);
}
 
ll calculate(int l, int u, int r, int d) {
	++r, ++d;
	return t.query(l, r, u, d);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 597 ms 7400 KB Output is correct
5 Correct 299 ms 7764 KB Output is correct
6 Correct 976 ms 4484 KB Output is correct
7 Correct 1095 ms 4436 KB Output is correct
8 Correct 748 ms 3476 KB Output is correct
9 Correct 1079 ms 4524 KB Output is correct
10 Correct 982 ms 4520 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1109 ms 11480 KB Output is correct
13 Correct 2804 ms 6308 KB Output is correct
14 Correct 522 ms 1368 KB Output is correct
15 Correct 2918 ms 7072 KB Output is correct
16 Correct 911 ms 8828 KB Output is correct
17 Correct 1581 ms 5448 KB Output is correct
18 Correct 2646 ms 9000 KB Output is correct
19 Correct 2329 ms 9252 KB Output is correct
20 Correct 2389 ms 8696 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 622 ms 7388 KB Output is correct
13 Correct 291 ms 7744 KB Output is correct
14 Correct 975 ms 4644 KB Output is correct
15 Correct 1070 ms 4380 KB Output is correct
16 Correct 742 ms 3368 KB Output is correct
17 Correct 1075 ms 4440 KB Output is correct
18 Correct 975 ms 4260 KB Output is correct
19 Correct 1106 ms 11352 KB Output is correct
20 Correct 2789 ms 6208 KB Output is correct
21 Correct 520 ms 1216 KB Output is correct
22 Correct 2948 ms 7004 KB Output is correct
23 Correct 934 ms 8728 KB Output is correct
24 Correct 1587 ms 5376 KB Output is correct
25 Correct 2774 ms 9124 KB Output is correct
26 Correct 2298 ms 9280 KB Output is correct
27 Correct 2317 ms 8464 KB Output is correct
28 Correct 3191 ms 188728 KB Output is correct
29 Correct 3357 ms 137604 KB Output is correct
30 Correct 3744 ms 31684 KB Output is correct
31 Correct 3279 ms 25420 KB Output is correct
32 Correct 818 ms 10812 KB Output is correct
33 Correct 1116 ms 11504 KB Output is correct
34 Correct 1424 ms 35740 KB Output is correct
35 Correct 4061 ms 181964 KB Output is correct
36 Correct 5895 ms 191864 KB Output is correct
37 Correct 5146 ms 189896 KB Output is correct
38 Correct 5169 ms 189764 KB Output is correct
39 Correct 4684 ms 186048 KB Output is correct
40 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 597 ms 7512 KB Output is correct
13 Correct 288 ms 7772 KB Output is correct
14 Correct 956 ms 4688 KB Output is correct
15 Correct 1081 ms 4348 KB Output is correct
16 Correct 746 ms 3520 KB Output is correct
17 Correct 1056 ms 4692 KB Output is correct
18 Correct 986 ms 4040 KB Output is correct
19 Correct 1102 ms 11392 KB Output is correct
20 Correct 2803 ms 6160 KB Output is correct
21 Correct 527 ms 1192 KB Output is correct
22 Correct 3000 ms 6740 KB Output is correct
23 Correct 863 ms 8776 KB Output is correct
24 Correct 1600 ms 5768 KB Output is correct
25 Correct 2714 ms 9380 KB Output is correct
26 Correct 2251 ms 9744 KB Output is correct
27 Correct 2264 ms 8784 KB Output is correct
28 Correct 3160 ms 188880 KB Output is correct
29 Correct 3243 ms 137584 KB Output is correct
30 Correct 3869 ms 31684 KB Output is correct
31 Correct 3310 ms 25628 KB Output is correct
32 Correct 793 ms 10832 KB Output is correct
33 Correct 1139 ms 11452 KB Output is correct
34 Correct 1062 ms 35636 KB Output is correct
35 Correct 4138 ms 182012 KB Output is correct
36 Correct 6062 ms 191976 KB Output is correct
37 Correct 5104 ms 189908 KB Output is correct
38 Correct 5208 ms 189812 KB Output is correct
39 Correct 3654 ms 208480 KB Output is correct
40 Correct 4519 ms 165784 KB Output is correct
41 Correct 5847 ms 60120 KB Output is correct
42 Correct 5284 ms 46360 KB Output is correct
43 Correct 1753 ms 67928 KB Output is correct
44 Correct 1275 ms 12364 KB Output is correct
45 Correct 4778 ms 185980 KB Output is correct
46 Correct 7242 ms 211744 KB Output is correct
47 Correct 7078 ms 211804 KB Output is correct
48 Correct 7120 ms 211916 KB Output is correct
49 Correct 0 ms 348 KB Output is correct