#pragma GCC optimize("Ofast")
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
long long gcd2(long long X, long long Y) {
long long tmp;
if(X==0&&Y==0) return 0;
if(X==0) return Y;
if(Y==0) return X;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
int R, C;
struct colNode {
int l, r;
ll st;
colNode *left, *right;
colNode(int lv, int rv): left(NULL), right(NULL), st(0) {l=lv; r=rv;};
};
set<pair<int, int>> isNew;
ll query(int x, int y, colNode *cur) {
if(cur == NULL) return 0;
if(x >= cur->r || y <= cur->l) return 0;
if(y >= cur->r && x <= cur->l) return cur->st;
if(cur->right==NULL) return query(x, y, cur->left);
if(cur->left==NULL) return query(x, y, cur->right);
return gcd2(query(x, y, cur->left),
query(x, y, cur->right));
}
void update(int j, ll val, colNode *cur, colNode *rowL, colNode *rowR) {
if(cur == NULL) return;
if(j < cur->l || j >= cur->r) return;
if(cur->l + 1 == cur->r) {
if(rowL == NULL && rowR == NULL) cur->st = val;
else if(rowL == NULL) cur->st = query(j, j+1, rowR);
else if(rowR == NULL) cur->st = query(j, j+1, rowL);
else cur->st = gcd2(query(j, j+1, rowL), query(j, j+1, rowR));
return;
}
int mid = (cur->l + cur->r)/2;
if(j < mid) {
if(cur->left == NULL) {
cur->left = new colNode(j, j+1);
} else if(cur->left->l != cur->l || cur->left->r != mid) {
int mid2 = (cur->l+mid)/2;
if(cur->left->l < mid2) {
cur->left->left = new colNode(cur->left->l, cur->left->r);
cur->left->left->st = cur->left->st;
} else {
cur->left->right = new colNode(cur->left->l, cur->left->r);
cur->left->right->st = cur->left->st;
}
cur->left->l = cur->l;
cur->left->r = mid;
}
update(j, val, cur->left, rowL, rowR);
} else {
if(cur->right == NULL) {
cur->right = new colNode(j, j+1);
} else if(cur->right->l != mid || cur->right->r != cur->r) {
int mid2 = (cur->r+mid)/2;
if(cur->right->l < mid2) {
cur->right->left = new colNode(cur->right->l, cur->right->r);
cur->right->left->st = cur->right->st;
} else {
cur->right->right = new colNode(cur->right->l, cur->right->r);
cur->right->right->st = cur->right->st;
}
cur->right->l = mid;
cur->right->r = cur->r;
}
update(j, val, cur->right, rowL, rowR);
}
if(cur->left==NULL) cur->st = cur->right->st;
else if(cur->right==NULL) cur->st = cur->left->st;
else cur->st = gcd2(cur->left->st, cur->right->st);
}
struct rowNode {
int l, r;
rowNode *left, *right;
colNode *col;
rowNode(int lv, int rv): left(NULL), right(NULL) {l=lv; r=rv; col = new colNode(0, C);};
};
void update(int i, int j, ll val, rowNode *cur) {
if(cur == NULL) return;
if(i < cur->l || i >= cur->r) return;
int mid = (cur->l + cur->r)/2;
if(cur->l+1 == cur-> r) {
} else if(i < mid) {
if(cur->left == NULL)
cur->left = new rowNode(cur->l, mid);
update(i, j, val, cur->left);
} else {
if(cur->right == NULL)
cur->right = new rowNode(mid, cur->r);
update(i, j, val, cur->right);
}
if(cur->left == NULL && cur->right == NULL) update(j, val, cur->col, NULL, NULL);
else if(cur->left == NULL) update(j, val, cur->col, NULL, cur->right->col);
else if(cur->right == NULL) update(j, val, cur->col, cur->left->col, NULL);
else update(j, val, cur->col, cur->left->col, cur->right->col);
}
ll query(int x, int y, int nx, int ny, rowNode *cur) {
if(cur == NULL) return 0;
if(x >= cur->r || y <= cur->l) return 0;
if(y >= cur->r && x <= cur->l) return query(nx, ny, cur->col);
if(cur->right==NULL) return query(x, y, nx, ny, cur->left);
if(cur->left==NULL) return query(x, y, nx, ny, cur->right);
return gcd2(query(x, y, nx, ny, cur->left),
query(x, y, nx, ny, cur->right));
}
rowNode root(0,1);
void init(signed r, signed c) {
R = r;
C = c;
root = *(new rowNode(0, R));
}
void update(signed P, signed Q, long long K) {
update(P, Q, K, &root);
}
long long calculate(signed P, signed Q, signed U, signed V) {
return query(P, U+1, Q, V+1, &root);;
}
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;
^~~
game.cpp: In constructor 'colNode::colNode(int, int)':
game.cpp:24:21: warning: 'colNode::right' will be initialized after [-Wreorder]
colNode *left, *right;
^~~~~
game.cpp:23:8: warning: 'long long int colNode::st' [-Wreorder]
ll st;
^~
game.cpp:25:5: warning: when initialized here [-Wreorder]
colNode(int lv, int rv): left(NULL), right(NULL), st(0) {l=lv; r=rv;};
^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Output is correct |
2 |
Correct |
3 ms |
484 KB |
Output is correct |
3 |
Correct |
3 ms |
560 KB |
Output is correct |
4 |
Correct |
2 ms |
560 KB |
Output is correct |
5 |
Correct |
2 ms |
560 KB |
Output is correct |
6 |
Correct |
3 ms |
560 KB |
Output is correct |
7 |
Correct |
2 ms |
560 KB |
Output is correct |
8 |
Correct |
2 ms |
560 KB |
Output is correct |
9 |
Correct |
2 ms |
560 KB |
Output is correct |
10 |
Correct |
3 ms |
560 KB |
Output is correct |
11 |
Correct |
2 ms |
560 KB |
Output is correct |
12 |
Correct |
2 ms |
560 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
560 KB |
Output is correct |
2 |
Correct |
2 ms |
620 KB |
Output is correct |
3 |
Correct |
2 ms |
620 KB |
Output is correct |
4 |
Correct |
633 ms |
9484 KB |
Output is correct |
5 |
Correct |
418 ms |
9756 KB |
Output is correct |
6 |
Correct |
771 ms |
9756 KB |
Output is correct |
7 |
Correct |
943 ms |
9756 KB |
Output is correct |
8 |
Correct |
480 ms |
9756 KB |
Output is correct |
9 |
Correct |
906 ms |
9756 KB |
Output is correct |
10 |
Correct |
738 ms |
9756 KB |
Output is correct |
11 |
Correct |
3 ms |
9756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
9756 KB |
Output is correct |
2 |
Correct |
4 ms |
9756 KB |
Output is correct |
3 |
Correct |
4 ms |
9756 KB |
Output is correct |
4 |
Correct |
2 ms |
9756 KB |
Output is correct |
5 |
Correct |
2 ms |
9756 KB |
Output is correct |
6 |
Correct |
3 ms |
9756 KB |
Output is correct |
7 |
Correct |
3 ms |
9756 KB |
Output is correct |
8 |
Correct |
3 ms |
9756 KB |
Output is correct |
9 |
Correct |
3 ms |
9756 KB |
Output is correct |
10 |
Correct |
2 ms |
9756 KB |
Output is correct |
11 |
Correct |
3 ms |
9756 KB |
Output is correct |
12 |
Correct |
1206 ms |
13196 KB |
Output is correct |
13 |
Correct |
2956 ms |
13196 KB |
Output is correct |
14 |
Correct |
423 ms |
13196 KB |
Output is correct |
15 |
Correct |
3379 ms |
13196 KB |
Output is correct |
16 |
Correct |
325 ms |
13196 KB |
Output is correct |
17 |
Correct |
1260 ms |
13196 KB |
Output is correct |
18 |
Correct |
2375 ms |
13196 KB |
Output is correct |
19 |
Correct |
2115 ms |
13196 KB |
Output is correct |
20 |
Correct |
1875 ms |
13196 KB |
Output is correct |
21 |
Correct |
3 ms |
13196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
13196 KB |
Output is correct |
2 |
Correct |
3 ms |
13196 KB |
Output is correct |
3 |
Correct |
3 ms |
13196 KB |
Output is correct |
4 |
Correct |
2 ms |
13196 KB |
Output is correct |
5 |
Correct |
2 ms |
13196 KB |
Output is correct |
6 |
Correct |
3 ms |
13196 KB |
Output is correct |
7 |
Correct |
2 ms |
13196 KB |
Output is correct |
8 |
Correct |
2 ms |
13196 KB |
Output is correct |
9 |
Correct |
2 ms |
13196 KB |
Output is correct |
10 |
Correct |
2 ms |
13196 KB |
Output is correct |
11 |
Correct |
3 ms |
13196 KB |
Output is correct |
12 |
Correct |
633 ms |
13196 KB |
Output is correct |
13 |
Correct |
416 ms |
13196 KB |
Output is correct |
14 |
Correct |
682 ms |
13196 KB |
Output is correct |
15 |
Correct |
823 ms |
13196 KB |
Output is correct |
16 |
Correct |
476 ms |
13196 KB |
Output is correct |
17 |
Correct |
762 ms |
13196 KB |
Output is correct |
18 |
Correct |
644 ms |
13196 KB |
Output is correct |
19 |
Correct |
1096 ms |
13224 KB |
Output is correct |
20 |
Correct |
2835 ms |
13224 KB |
Output is correct |
21 |
Correct |
348 ms |
13224 KB |
Output is correct |
22 |
Correct |
3040 ms |
13224 KB |
Output is correct |
23 |
Correct |
366 ms |
13224 KB |
Output is correct |
24 |
Correct |
1186 ms |
13224 KB |
Output is correct |
25 |
Correct |
2225 ms |
13224 KB |
Output is correct |
26 |
Correct |
1831 ms |
13224 KB |
Output is correct |
27 |
Correct |
1632 ms |
13224 KB |
Output is correct |
28 |
Correct |
766 ms |
48632 KB |
Output is correct |
29 |
Correct |
1836 ms |
48632 KB |
Output is correct |
30 |
Correct |
4738 ms |
48632 KB |
Output is correct |
31 |
Correct |
4925 ms |
82148 KB |
Output is correct |
32 |
Correct |
611 ms |
82148 KB |
Output is correct |
33 |
Correct |
966 ms |
82148 KB |
Output is correct |
34 |
Correct |
421 ms |
82148 KB |
Output is correct |
35 |
Correct |
1546 ms |
82148 KB |
Output is correct |
36 |
Correct |
3031 ms |
82148 KB |
Output is correct |
37 |
Correct |
2291 ms |
82148 KB |
Output is correct |
38 |
Correct |
2428 ms |
82148 KB |
Output is correct |
39 |
Correct |
1876 ms |
82148 KB |
Output is correct |
40 |
Correct |
2 ms |
82148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
82148 KB |
Output is correct |
2 |
Correct |
3 ms |
82148 KB |
Output is correct |
3 |
Correct |
3 ms |
82148 KB |
Output is correct |
4 |
Correct |
2 ms |
82148 KB |
Output is correct |
5 |
Correct |
2 ms |
82148 KB |
Output is correct |
6 |
Correct |
2 ms |
82148 KB |
Output is correct |
7 |
Correct |
2 ms |
82148 KB |
Output is correct |
8 |
Correct |
2 ms |
82148 KB |
Output is correct |
9 |
Correct |
2 ms |
82148 KB |
Output is correct |
10 |
Correct |
2 ms |
82148 KB |
Output is correct |
11 |
Correct |
2 ms |
82148 KB |
Output is correct |
12 |
Correct |
732 ms |
82148 KB |
Output is correct |
13 |
Correct |
581 ms |
82148 KB |
Output is correct |
14 |
Correct |
832 ms |
82148 KB |
Output is correct |
15 |
Correct |
919 ms |
82148 KB |
Output is correct |
16 |
Correct |
474 ms |
82148 KB |
Output is correct |
17 |
Correct |
709 ms |
82148 KB |
Output is correct |
18 |
Correct |
616 ms |
82148 KB |
Output is correct |
19 |
Correct |
1035 ms |
82148 KB |
Output is correct |
20 |
Correct |
2600 ms |
82148 KB |
Output is correct |
21 |
Correct |
341 ms |
82148 KB |
Output is correct |
22 |
Correct |
3036 ms |
82148 KB |
Output is correct |
23 |
Correct |
261 ms |
82148 KB |
Output is correct |
24 |
Correct |
1095 ms |
82148 KB |
Output is correct |
25 |
Correct |
2061 ms |
82148 KB |
Output is correct |
26 |
Correct |
1650 ms |
82148 KB |
Output is correct |
27 |
Correct |
1574 ms |
82148 KB |
Output is correct |
28 |
Correct |
750 ms |
82148 KB |
Output is correct |
29 |
Correct |
1697 ms |
82148 KB |
Output is correct |
30 |
Correct |
4878 ms |
82148 KB |
Output is correct |
31 |
Correct |
4709 ms |
82148 KB |
Output is correct |
32 |
Correct |
678 ms |
82148 KB |
Output is correct |
33 |
Correct |
874 ms |
82148 KB |
Output is correct |
34 |
Correct |
427 ms |
82148 KB |
Output is correct |
35 |
Correct |
1856 ms |
82148 KB |
Output is correct |
36 |
Correct |
2879 ms |
82148 KB |
Output is correct |
37 |
Correct |
2384 ms |
82148 KB |
Output is correct |
38 |
Correct |
2787 ms |
82148 KB |
Output is correct |
39 |
Correct |
1128 ms |
106360 KB |
Output is correct |
40 |
Correct |
3391 ms |
106360 KB |
Output is correct |
41 |
Correct |
6552 ms |
106360 KB |
Output is correct |
42 |
Correct |
6336 ms |
168832 KB |
Output is correct |
43 |
Correct |
757 ms |
168832 KB |
Output is correct |
44 |
Correct |
856 ms |
168832 KB |
Output is correct |
45 |
Correct |
1945 ms |
168832 KB |
Output is correct |
46 |
Correct |
3925 ms |
168832 KB |
Output is correct |
47 |
Correct |
4172 ms |
168832 KB |
Output is correct |
48 |
Correct |
3722 ms |
168832 KB |
Output is correct |
49 |
Correct |
2 ms |
168832 KB |
Output is correct |