# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
395875 |
2021-04-29T05:06:59 Z |
pure_mem |
Game (IOI13_game) |
C++14 |
|
1687 ms |
81348 KB |
#pragma GCC optimize("Ofast")
#include "game.h"
#include <iostream>
#include <algorithm>
#define ll long long
#define X first
#define Y second
#define MP make_pair
using namespace std;
const int MAXN = 1e6;
ll gcd(ll x, ll y) {
if(x < y)
swap(x, y);
while(y){
x %= y;
swap(x, y);
}
return x;
}
int n, m, dl, dr, ptr;
struct node{
node* p[2] = {nullptr, nullptr};
node* p1[2] = {nullptr, nullptr};
ll val = 0;
node* getp(int v);
node* getp1(int v);
void merge(int tl, int tr, node* L, node* R, int pos);
void upd1(int tl, int tr, int pos, ll _val);
ll get1(int tl, int tr, int l, int r);
void upd(int tl, int tr, int pos, ll _val);
ll get(int tl, int tr, int l, int r);
}root, baz[MAXN];
node* node::getp(int v){
if(!p[v])
p[v] = &baz[ptr++];
return p[v];
}
node* node::getp1(int v){
if(!p1[v])
p1[v] = &baz[ptr++];
return p1[v];
}
void node::merge(int tl, int tr, node* L, node* R, int pos){
if(!L && !R)
return;
if(tl == tr){
val = 0;
if(L)
val = gcd(L->val, val);
if(R)
val = gcd(R->val, val);
return;
}
int tm = (tl + tr) / 2;
if(pos <= tm){
if(L)
L = L->p1[0];
if(R)
R = R->p1[0];
getp1(0)->merge(tl, tm, L, R, pos);
}
else{
if(L)
L = L->p1[1];
if(R)
R = R->p1[1];
getp1(1)->merge(tm + 1, tr, L, R, pos);
}
val = 0;
if(p1[0])
val = gcd(p1[0]->val, val);
if(p1[1])
val = gcd(p1[1]->val, val);
//cerr << tl << " " << tr << " " << val << " " << this << "s\n";
}
void node::upd1(int tl, int tr, int pos, ll _val){
if(tl == tr)
return void(val = _val);
int tm = (tl + tr) / 2;
//cerr << tl << " s " << tr << "\n";
if(pos <= tm)
getp1(0)->upd1(tl, tm, pos, _val);
else
getp1(1)->upd1(tm + 1, tr, pos, _val);
val = 0;
if(p1[0])
val = gcd(p1[0]->val, val);
if(p1[1])
val = gcd(p1[1]->val, val);
}
ll node::get1(int tl, int tr, int l, int r){
if(tl > r || l > tr)
return 0;
if(tl >= l && tr <= r)
return val;
int tm = (tl + tr) / 2;
return gcd((p1[0] ? p1[0]->get1(tl, tm, l, r): 0), (p1[1] ? p1[1]->get1(tm + 1, tr, l, r): 0));
}
void node::upd(int tl, int tr, int pos, ll _val){
//cerr << tl << " " << tr << " b " << this << "\n";
if(tl == tr){
return void(upd1(1, m, dl, _val));
}
int tm = (tl + tr) / 2;
if(pos <= tm)
getp(0)->upd(tl, tm, pos, _val);
else
getp(1)->upd(tm + 1, tr, pos, _val);
merge(1, m, p[0], p[1], dl);
}
ll node::get(int tl, int tr, int l, int r){
if(tl > r || l > tr)
return 0;
if(tl >= l && tr <= r)
return get1(1, m, dl, dr);
int tm = (tl + tr) / 2;
//cerr << tl << " " << tr << " " << left << " z " << right << "\n";
return gcd((p[0] ? p[0]->get(tl, tm, l, r): 0), (p[1] ? p[1]->get(tm + 1, tr, l, r): 0));
}
void init(int R, int C) {
n = R, m = C;
}
void update(int P, int Q, ll K) {
// cerr << "was1\n";
dl = Q + 1;
//cerr << P + 1 << " " << Q + 1 << "\n";
root.upd(1, n, P + 1, K);
// cerr << "was\n";
}
long long calculate(int P, int Q, int U, int V) {
/* ... */
//cerr << "were\n";
dl = Q + 1, dr = V + 1;
//cerr << P + 1 << " " << U + 1 << " " << dl << " " << dr << "\n";
ll tmp = root.get(1, n, P + 1, U + 1);
// cerr << tmp << "\n";
return tmp;
}
# |
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 |
1 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 |
300 KB |
Output is correct |
12 |
Correct |
1 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 |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
574 ms |
15060 KB |
Output is correct |
5 |
Correct |
417 ms |
15300 KB |
Output is correct |
6 |
Correct |
481 ms |
12320 KB |
Output is correct |
7 |
Correct |
534 ms |
12088 KB |
Output is correct |
8 |
Correct |
371 ms |
8292 KB |
Output is correct |
9 |
Correct |
505 ms |
12116 KB |
Output is correct |
10 |
Correct |
485 ms |
11716 KB |
Output is correct |
11 |
Correct |
1 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 |
432 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 |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
917 ms |
19000 KB |
Output is correct |
13 |
Correct |
1413 ms |
7692 KB |
Output is correct |
14 |
Correct |
291 ms |
1328 KB |
Output is correct |
15 |
Correct |
1687 ms |
11172 KB |
Output is correct |
16 |
Correct |
210 ms |
22800 KB |
Output is correct |
17 |
Correct |
810 ms |
14220 KB |
Output is correct |
18 |
Correct |
1380 ms |
23124 KB |
Output is correct |
19 |
Correct |
1180 ms |
23364 KB |
Output is correct |
20 |
Correct |
1114 ms |
22720 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
300 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 |
1 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 |
332 KB |
Output is correct |
12 |
Correct |
577 ms |
15080 KB |
Output is correct |
13 |
Correct |
418 ms |
15300 KB |
Output is correct |
14 |
Correct |
479 ms |
12324 KB |
Output is correct |
15 |
Correct |
529 ms |
12232 KB |
Output is correct |
16 |
Correct |
363 ms |
8272 KB |
Output is correct |
17 |
Correct |
530 ms |
12200 KB |
Output is correct |
18 |
Correct |
482 ms |
11864 KB |
Output is correct |
19 |
Correct |
905 ms |
18976 KB |
Output is correct |
20 |
Correct |
1402 ms |
7608 KB |
Output is correct |
21 |
Correct |
298 ms |
1348 KB |
Output is correct |
22 |
Correct |
1678 ms |
10956 KB |
Output is correct |
23 |
Correct |
213 ms |
22688 KB |
Output is correct |
24 |
Correct |
810 ms |
14184 KB |
Output is correct |
25 |
Correct |
1373 ms |
23144 KB |
Output is correct |
26 |
Correct |
1169 ms |
23404 KB |
Output is correct |
27 |
Correct |
1094 ms |
22672 KB |
Output is correct |
28 |
Runtime error |
101 ms |
81348 KB |
Execution killed with signal 11 |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
224 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 |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
564 ms |
14700 KB |
Output is correct |
13 |
Correct |
424 ms |
15056 KB |
Output is correct |
14 |
Correct |
474 ms |
11920 KB |
Output is correct |
15 |
Correct |
535 ms |
11716 KB |
Output is correct |
16 |
Correct |
363 ms |
7940 KB |
Output is correct |
17 |
Correct |
522 ms |
11844 KB |
Output is correct |
18 |
Correct |
488 ms |
11332 KB |
Output is correct |
19 |
Correct |
922 ms |
18728 KB |
Output is correct |
20 |
Correct |
1399 ms |
7456 KB |
Output is correct |
21 |
Correct |
294 ms |
964 KB |
Output is correct |
22 |
Correct |
1674 ms |
10740 KB |
Output is correct |
23 |
Correct |
208 ms |
22340 KB |
Output is correct |
24 |
Correct |
814 ms |
13892 KB |
Output is correct |
25 |
Correct |
1378 ms |
22804 KB |
Output is correct |
26 |
Correct |
1180 ms |
22968 KB |
Output is correct |
27 |
Correct |
1086 ms |
22272 KB |
Output is correct |
28 |
Runtime error |
103 ms |
81228 KB |
Execution killed with signal 11 |
29 |
Halted |
0 ms |
0 KB |
- |