# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
157027 |
2019-10-09T07:01:08 Z |
topology |
Game (IOI13_game) |
C++17 |
|
3105 ms |
256004 KB |
#include <bits/stdc++.h>
#ifdef TOPOLOGY
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#include "game.h"
#define debug(...)
#endif
using namespace std;
int rr, cc;
long long gcd2(long long X, long long Y);
struct node {
long long g;
node *l, *r;
node() : g(), l(), r() {
}
long long upd(int qi, int vi, int q, long long k) {
if (q < qi || vi < q) return this->g;
if (qi == vi) {
return this->g = k;
}
if (q <= ((qi + vi) >> 1) && !this->l) this->l = new node();
if (q > ((qi + vi) >> 1) && !this->r) this->r = new node();
return this->g = gcd2(
this->l ? this->l->upd(qi, (qi + vi) >> 1, q, k) : 0,
this->r ? this->r->upd(((qi + vi) >> 1) + 1, vi, q, k) : 0
);
}
long long gcd(int qi, int vi, int q, int v) {
if (vi < q || qi > v) return 0LL;
if (q <= qi && vi <= v) {
return this->g;
}
return gcd2(
this->l ? this->l->gcd(qi, (qi + vi) >> 1, q, v) : 0LL,
this->r ? this->r->gcd(((qi + vi) >> 1) + 1, vi, q, v) : 0LL
);
}
};
struct hnode {
node *seg;
hnode *l, *r;
hnode() : l(), r() {
this->seg = new node();
}
long long upd(int pi, int ui, int p, int q, long long k) {
if (p < pi || ui < p) {
return this->seg->gcd(0, cc - 1, q, q);
} else if (pi < ui) {
if (p <= ((pi + ui) >> 1) && !this->l) this->l = new hnode();
if (p > ((pi + ui) >> 1) && !this->r) this->r = new hnode();
long long l = gcd2(
this->l ? this->l->upd(pi, (pi + ui) >> 1, p, q, k) : 0,
this->r ? this->r->upd(((pi + ui) >> 1) + 1, ui, p, q, k) : 0
);
this->seg->upd(0, cc - 1, q, l);
return l;
} else {
this->seg->upd(0, cc - 1, q, k);
return k;
}
}
long long gcd(int pi, int ui, int p, int q, int u, int v) {
if (ui < p || pi > u) return 0LL;
if (p <= pi && ui <= u) {
return this->seg->gcd(0, cc - 1, q, v);
}
return gcd2(
this->l ? this->l->gcd(pi, (pi + ui) >> 1, p, q, u, v) : 0LL,
this->r ? this->r->gcd(((pi + ui) >> 1) + 1, ui, p, q, u, v) : 0LL
);
}
} *root;
long long gcd2(long long X, long long Y) {
long long tmp;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
void init(int r, int c) {
rr = r;
cc = c;
root = new hnode();
}
void update(int p, int q, long long k) {
root->upd(0, rr - 1, p, q, k);
}
long long calculate(int p, int q, int u, int v) {
/* ... */
return root->gcd(0, rr - 1, p, q, u, v);
}
#ifdef TOPOLOGY
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int R, C, N;
cin >> R >> C >> N;
init(R, C);
cout << "init(" << R << ", " << C << ")\n";
for (int i = 0; i < N; i++) {
int D;
cin >> D;
if (D == 1) {
int P, Q;
long long K;
cin >> P >> Q >> K;
update(P, Q, K);
cout << "update(" << P << ", " << Q << ", " << K << ")\n";
} else {
int P, Q, U, V;
cin >> P >> Q >> U >> V;
long long res = calculate(P, Q, U, V);
cout << "calculate(" << P << ", " << Q << ", " << U << ", " << V << ") " << res << '\n';
}
}
return 0;
}
#endif
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 |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
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 |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
739 ms |
12772 KB |
Output is correct |
5 |
Correct |
465 ms |
13148 KB |
Output is correct |
6 |
Correct |
736 ms |
10176 KB |
Output is correct |
7 |
Correct |
797 ms |
9804 KB |
Output is correct |
8 |
Correct |
530 ms |
6884 KB |
Output is correct |
9 |
Correct |
886 ms |
9872 KB |
Output is correct |
10 |
Correct |
685 ms |
9532 KB |
Output is correct |
11 |
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 |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
3 ms |
292 KB |
Output is correct |
9 |
Correct |
3 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
404 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
1288 ms |
15976 KB |
Output is correct |
13 |
Correct |
2660 ms |
6644 KB |
Output is correct |
14 |
Correct |
359 ms |
1048 KB |
Output is correct |
15 |
Correct |
3059 ms |
8992 KB |
Output is correct |
16 |
Correct |
279 ms |
18552 KB |
Output is correct |
17 |
Correct |
1307 ms |
11672 KB |
Output is correct |
18 |
Correct |
2047 ms |
18844 KB |
Output is correct |
19 |
Correct |
1803 ms |
19044 KB |
Output is correct |
20 |
Correct |
1681 ms |
18400 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
380 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
392 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
252 KB |
Output is correct |
9 |
Correct |
3 ms |
424 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
739 ms |
12864 KB |
Output is correct |
13 |
Correct |
475 ms |
13140 KB |
Output is correct |
14 |
Correct |
757 ms |
10036 KB |
Output is correct |
15 |
Correct |
816 ms |
9856 KB |
Output is correct |
16 |
Correct |
546 ms |
6832 KB |
Output is correct |
17 |
Correct |
836 ms |
10076 KB |
Output is correct |
18 |
Correct |
716 ms |
9604 KB |
Output is correct |
19 |
Correct |
1186 ms |
16168 KB |
Output is correct |
20 |
Correct |
2633 ms |
6456 KB |
Output is correct |
21 |
Correct |
358 ms |
1144 KB |
Output is correct |
22 |
Correct |
3101 ms |
9032 KB |
Output is correct |
23 |
Correct |
276 ms |
18424 KB |
Output is correct |
24 |
Correct |
1321 ms |
11800 KB |
Output is correct |
25 |
Correct |
2419 ms |
18760 KB |
Output is correct |
26 |
Correct |
1990 ms |
18848 KB |
Output is correct |
27 |
Correct |
1879 ms |
18324 KB |
Output is correct |
28 |
Correct |
1223 ms |
256000 KB |
Output is correct |
29 |
Runtime error |
2336 ms |
256004 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
3 ms |
380 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
504 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
739 ms |
14852 KB |
Output is correct |
13 |
Correct |
472 ms |
15124 KB |
Output is correct |
14 |
Correct |
735 ms |
12024 KB |
Output is correct |
15 |
Correct |
828 ms |
11808 KB |
Output is correct |
16 |
Correct |
526 ms |
8828 KB |
Output is correct |
17 |
Correct |
806 ms |
12084 KB |
Output is correct |
18 |
Correct |
674 ms |
11692 KB |
Output is correct |
19 |
Correct |
1115 ms |
18056 KB |
Output is correct |
20 |
Correct |
2690 ms |
8680 KB |
Output is correct |
21 |
Correct |
358 ms |
3192 KB |
Output is correct |
22 |
Correct |
3105 ms |
11020 KB |
Output is correct |
23 |
Correct |
284 ms |
20560 KB |
Output is correct |
24 |
Correct |
1309 ms |
13324 KB |
Output is correct |
25 |
Correct |
2205 ms |
19912 KB |
Output is correct |
26 |
Correct |
1881 ms |
20000 KB |
Output is correct |
27 |
Correct |
1658 ms |
19448 KB |
Output is correct |
28 |
Correct |
1352 ms |
256000 KB |
Output is correct |
29 |
Runtime error |
2473 ms |
256000 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
30 |
Halted |
0 ms |
0 KB |
- |