# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
485528 |
2021-11-08T04:26:51 Z |
DiTenix |
Game (IOI13_game) |
C++14 |
|
3961 ms |
256000 KB |
#include <bits/stdc++.h>
#include "game.h"
using namespace std;
using ll = long long;
const int maxn = 1e5 + 5;
long long gcd(long long X, long long Y) {
long long tmp;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
struct Node {
ll val;
int lef, rig;
} a[maxn * 140];
#define lef(x) (a[x].lef)
#define rig(x) (a[x].rig)
#define val(x) (a[x].val)
#define Node int&
void comb(int x) {
val(x) = gcd(val(lef(x)), val(rig(x)));
}
int new_node(ll v) {
static int sz = 0;
++sz;
return sz;
}
int root2d, R, C;
unordered_map<int, int> root;
void set1d(int l, int r, Node x, Node r1, Node r2, int k, ll v) {
if (!x) x = new_node(0);
if (l == r) {
if (!r1 & !r2) {
val(x) = v;
} else {
val(x) = gcd(val(r1), val(r2));
}
} else {
int m = (l + r) >> 1;
if (k <= m) set1d(l, m, lef(x), lef(r1), lef(r2), k, v);
else set1d(m + 1, r, rig(x), rig(r1), rig(r2), k, v);
comb(x);
}
}
void set2d(int l, int r, Node x, int _x, int _y, ll v) {
if (!x) x = new_node(0);
if (l != r) {
int m = (l + r) >> 1;
if (_x <= m) set2d(l, m, lef(x), _x, _y, v);
else set2d(m + 1, r, rig(x), _x, _y, v);
}
set1d(0, C - 1, root[x], root[lef(x)], root[rig(x)], _y, v);
}
ll qry1d(int l, int r, Node x, int L, int R) {
// printf("qry1d %d %d %d\n", l, r, x);
if (!x) return 0;
if (l > R || r < L) return 0;
if (l >= L && r <= R) return val(x);
int m = (l + r) >> 1;
return gcd(qry1d(l, m, lef(x), L, R), qry1d(m + 1, r, rig(x), L, R));
}
ll qry2d(int l, int r, Node x, int L, int R, int _L, int _R) {
if (!x) return 0;
if (l > R || r < L) return 0;
// printf("qry2d %d %d %d %d %d\n", l, r, L, R, x);
if (l >= L && r <= R) return qry1d(0, C - 1, root[x], _L, _R);
int m = (l + r) >> 1;
return gcd(qry2d(l, m, lef(x), L, R, _L, _R), qry2d(m + 1, r, rig(x), L, R, _L, _R));
}
void init(int R, int C) {
::R = R;
::C = C;
}
void update(int P, int Q, long long K) {
set2d(0, R - 1, root2d, P, Q, K);
}
long long calculate(int P, int Q, int U, int V) {
if (P > U) swap(P, U);
if (Q > V) swap(Q, V);
return qry2d(0, R - 1, root2d, P, U, Q, V);
}
/*
signed main() {
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
cin.tie(0)->sync_with_stdio(false);
int m;
cin >> R >> C >> m;
// printf("%d %d %d\n", R, C, m);
while (m--) {
int op;
cin >> op;
// printf("%d\n", op);
if (op == 1) {
int x, y;
ll v;
cin >> x >> y >> v;
modify(x, y, v);
} else {
int x1, y1, x2, y2;
cin >> x1 >> y1 >> x2 >> y2;
if (x1 > x2) swap(x1, x2);
if (y1 > y2) swap(y1, y2);
ll res = qry(x1, x2, y1, y2);
cout << res << "\n";
}
}
// printf("%d %d\n", root2d, root[root2d]);
}*/
/*
1 1 64
2 0 0 0 0
2 0 0 0 0
2 0 0 0 0
1 0 0 5352072091165800
2 0 0 0 0
1 0 0 15571253006461152
1 0 0 36204425277916896
1 0 0 80686018200191040
1 0 0 720602986354563312
2 0 0 0 0
1 0 0 90705271009665312
2 0 0 0 0
1 0 0 583803309300971760
1 0 0 3317329660750560
2 0 0 0 0
2 0 0 0 0
2 0 0 0 0
1 0 0 84776821924066272
1 0 0 581927323100969664
1 0 0 93139161501610224
1 0 0 28340661117472704
1 0 0 74529074218959360
2 0 0 0 0
1 0 0 462419028676725120
1 0 0 4416867915235776
1 0 0 840475934823549024
1 0 0 8247617084266560
1 0 0 117571055091706944
1 0 0 839204903894797440
1 0 0 820805176764813240
1 0 0 82688722861897152
1 0 0 136422472061715840
1 0 0 555837014267982720
1 0 0 935087613488388360
1 0 0 17770822018565616
1 0 0 10726679222715456
1 0 0 621229604181863040
1 0 0 12477973789689408
2 0 0 0 0
1 0 0 227153207069268480
1 0 0 262037449583477568
1 0 0 562837835495871936
1 0 0 131875056326325312
1 0 0 922430858108760
1 0 0 763487168205041280
2 0 0 0 0
2 0 0 0 0
1 0 0 551850903114166656
1 0 0 243713152409807808
1 0 0 306811355534716032
1 0 0 115604757169181280
2 0 0 0 0
1 0 0 29254579698314880
1 0 0 35080064244441216
1 0 0 97819409912384160
1 0 0 34259332503876480
2 0 0 0 0
2 0 0 0 0
1 0 0 159548730492191040
1 0 0 11555364984947784
2 0 0 0 0
1 0 0 3373083100427040
2 0 0 0 0
2 0 0 0 0*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
296 KB |
Output is correct |
4 |
Correct |
474 ms |
12788 KB |
Output is correct |
5 |
Correct |
336 ms |
12652 KB |
Output is correct |
6 |
Correct |
381 ms |
10312 KB |
Output is correct |
7 |
Correct |
399 ms |
9948 KB |
Output is correct |
8 |
Correct |
318 ms |
8516 KB |
Output is correct |
9 |
Correct |
392 ms |
10052 KB |
Output is correct |
10 |
Correct |
351 ms |
9728 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
436 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
759 ms |
14256 KB |
Output is correct |
13 |
Correct |
1281 ms |
7848 KB |
Output is correct |
14 |
Correct |
260 ms |
5472 KB |
Output is correct |
15 |
Correct |
1603 ms |
9376 KB |
Output is correct |
16 |
Correct |
169 ms |
14012 KB |
Output is correct |
17 |
Correct |
679 ms |
11480 KB |
Output is correct |
18 |
Correct |
1084 ms |
15428 KB |
Output is correct |
19 |
Correct |
952 ms |
15504 KB |
Output is correct |
20 |
Correct |
909 ms |
14932 KB |
Output is correct |
21 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
1 ms |
296 KB |
Output is correct |
12 |
Correct |
444 ms |
12844 KB |
Output is correct |
13 |
Correct |
347 ms |
12756 KB |
Output is correct |
14 |
Correct |
379 ms |
10200 KB |
Output is correct |
15 |
Correct |
444 ms |
9976 KB |
Output is correct |
16 |
Correct |
289 ms |
8468 KB |
Output is correct |
17 |
Correct |
386 ms |
10068 KB |
Output is correct |
18 |
Correct |
377 ms |
9720 KB |
Output is correct |
19 |
Correct |
758 ms |
14368 KB |
Output is correct |
20 |
Correct |
1308 ms |
7824 KB |
Output is correct |
21 |
Correct |
253 ms |
5472 KB |
Output is correct |
22 |
Correct |
1578 ms |
9464 KB |
Output is correct |
23 |
Correct |
169 ms |
14020 KB |
Output is correct |
24 |
Correct |
651 ms |
11648 KB |
Output is correct |
25 |
Correct |
1018 ms |
15424 KB |
Output is correct |
26 |
Correct |
870 ms |
15568 KB |
Output is correct |
27 |
Correct |
875 ms |
14968 KB |
Output is correct |
28 |
Correct |
715 ms |
145112 KB |
Output is correct |
29 |
Correct |
1661 ms |
159820 KB |
Output is correct |
30 |
Correct |
3961 ms |
113720 KB |
Output is correct |
31 |
Correct |
3625 ms |
88176 KB |
Output is correct |
32 |
Correct |
476 ms |
10176 KB |
Output is correct |
33 |
Correct |
618 ms |
11524 KB |
Output is correct |
34 |
Correct |
390 ms |
153444 KB |
Output is correct |
35 |
Correct |
1146 ms |
84752 KB |
Output is correct |
36 |
Correct |
2173 ms |
157860 KB |
Output is correct |
37 |
Correct |
1755 ms |
158100 KB |
Output is correct |
38 |
Correct |
1746 ms |
157272 KB |
Output is correct |
39 |
Correct |
1485 ms |
122680 KB |
Output is correct |
40 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
452 ms |
12832 KB |
Output is correct |
13 |
Correct |
359 ms |
12740 KB |
Output is correct |
14 |
Correct |
372 ms |
10180 KB |
Output is correct |
15 |
Correct |
444 ms |
9972 KB |
Output is correct |
16 |
Correct |
301 ms |
8508 KB |
Output is correct |
17 |
Correct |
397 ms |
9984 KB |
Output is correct |
18 |
Correct |
395 ms |
9624 KB |
Output is correct |
19 |
Correct |
819 ms |
14284 KB |
Output is correct |
20 |
Correct |
1293 ms |
7472 KB |
Output is correct |
21 |
Correct |
255 ms |
5492 KB |
Output is correct |
22 |
Correct |
1527 ms |
9420 KB |
Output is correct |
23 |
Correct |
164 ms |
14152 KB |
Output is correct |
24 |
Correct |
635 ms |
11472 KB |
Output is correct |
25 |
Correct |
1012 ms |
15600 KB |
Output is correct |
26 |
Correct |
904 ms |
15728 KB |
Output is correct |
27 |
Correct |
799 ms |
15172 KB |
Output is correct |
28 |
Correct |
662 ms |
145100 KB |
Output is correct |
29 |
Correct |
1482 ms |
159932 KB |
Output is correct |
30 |
Correct |
3803 ms |
113696 KB |
Output is correct |
31 |
Correct |
3559 ms |
88312 KB |
Output is correct |
32 |
Correct |
470 ms |
10492 KB |
Output is correct |
33 |
Correct |
622 ms |
11520 KB |
Output is correct |
34 |
Correct |
402 ms |
153552 KB |
Output is correct |
35 |
Correct |
1151 ms |
84856 KB |
Output is correct |
36 |
Correct |
2148 ms |
157968 KB |
Output is correct |
37 |
Correct |
1798 ms |
157788 KB |
Output is correct |
38 |
Correct |
1776 ms |
157436 KB |
Output is correct |
39 |
Runtime error |
1029 ms |
256000 KB |
Execution killed with signal 11 |
40 |
Halted |
0 ms |
0 KB |
- |