// And you curse yourself for things you never done
#include<bits/stdc++.h>
#include "game.h"
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf = 1e9 + 10;
int N, M;
struct node{
ll g = 0, x = 0;
node *L = 0, *R = 0;
int pos = 0, S = 0, MN, MX;
node(int _pos, ll _g){
pos = _pos, g = _g, x = _g, MN = MX = _pos;
S = 1;
}
void rest(int _pos, ll _g){
pos = _pos, g = _g, x = _g, MN = MX = _pos;
S = 1;
}
ll ask(int _pos){
if(pos == _pos)
return x;
if(_pos < pos)
return (L ? L->ask(_pos) : 0);
else
return (R ? R->ask(_pos) : 0);
}
ll ask(int f, int s){
if(f <= MN && MX < s)
return g;
if(s <= MN || MX < f)
return 0;
ll ans = 0;
if(f <= pos && pos < s)
ans = x;
if(L)
ans = __gcd(ans, L->ask(f, s));
if(R)
ans = __gcd(ans, R->ask(f, s));
return ans;
}
};
void build(node* nw){
nw->S = (nw->L ? nw->L->S : 0) + (nw->R ? nw->R->S : 0) + 1;
nw->g = __gcd(nw->x, __gcd( nw->L ? nw->L->g : 0, nw->R ? nw->R->g : 0 ));
nw->MN = min({nw->pos, nw->L ? nw->L->MN : inf, nw->R ? nw->R->MN : inf});
nw->MX = max({nw->pos, nw->L ? nw->L->MX : -inf, nw->R ? nw->R->MX : -inf});
}
pair<node*, node*> split(node* nw, int x){
if(nw == 0)
return {0, 0};
if(nw->pos < x){
auto it = split(nw->R, x);
nw->R = it.F;
build(nw);
return {nw, it.S};
}
else{
auto it = split(nw->L, x);
nw->L = it.S;
build(nw);
return {it.F, nw};
}
assert(0);
}
node* merge(node *A, node *B){
if(A == 0)
return B;
if(B == 0)
return A;
if((rand() % (A->S + B->S)) < A->S){
A->R = merge(A->R, B);
build(A);
return A;
}
else{
B->L = merge(A, B->L);
build(B);
return B;
}
assert(0);
}
node* _put(node *nw, int pos, ll x){
auto A = split(nw, pos);
auto B = split(A.S, pos+1);
node* r = B.F;
if(r == 0)
r = new node(pos, x);
else
r->rest(pos, x);
return merge(A.F, merge(r, B.S));
}
struct node2{
node* g = 0;
node2 *L = 0, *R = 0;
void put(int posx, int posy, ll x, int l = 0, int r = N){
ll num = x;
if(r-l > 1){
int mid = (l+r) >> 1;
if(posx < mid){
if(!L)
L = new node2();
L->put(posx, posy, x, l, mid);
}
else{
if(!R)
R = new node2();
R->put(posx, posy, x, mid, r);
}
num = __gcd(L ? L->g->ask(posy) : 0, R ? R->g->ask(posy) : 0);
}
if(!g)
g = new node(posy, num);
else
g = _put(g, posy, num);
}
ll ask(int f, int s, int ff, int ss, int l = 0, int r = N){
if(r <= f || s <= l)
return 0;
if(f <= l && r <= s)
return g ? g->ask(ff, ss) : 0;
int mid = (l+r) >> 1;
return __gcd(L ? L->ask(f, s, ff, ss, l, mid) : 0, R ? R->ask(f, s, ff, ss, mid, r) : 0);
}
};
node2* root;
void init(int N, int M){
srand(time(0));
::N = N, ::M = M;
root = new node2();
}
void update(int x, int y, ll w){
root->put(x, y, w);
}
ll calculate(int x, int y, int xx, int yy){
return root->ask(x, ++xx, y, ++yy);
}
Compilation message
grader.c: In function 'int main()':
grader.c:18:6: warning: variable 'res' set but not used [-Wunused-but-set-variable]
18 | int res;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
1 ms |
256 KB |
Output is correct |
4 |
Correct |
674 ms |
8536 KB |
Output is correct |
5 |
Correct |
356 ms |
8828 KB |
Output is correct |
6 |
Correct |
738 ms |
5580 KB |
Output is correct |
7 |
Correct |
828 ms |
5260 KB |
Output is correct |
8 |
Correct |
537 ms |
4728 KB |
Output is correct |
9 |
Correct |
774 ms |
5520 KB |
Output is correct |
10 |
Correct |
760 ms |
5112 KB |
Output is correct |
11 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
926 ms |
11448 KB |
Output is correct |
13 |
Correct |
1405 ms |
5544 KB |
Output is correct |
14 |
Correct |
327 ms |
2296 KB |
Output is correct |
15 |
Correct |
1570 ms |
6304 KB |
Output is correct |
16 |
Correct |
363 ms |
8568 KB |
Output is correct |
17 |
Correct |
914 ms |
6264 KB |
Output is correct |
18 |
Correct |
1780 ms |
9464 KB |
Output is correct |
19 |
Correct |
1490 ms |
9724 KB |
Output is correct |
20 |
Correct |
1376 ms |
9104 KB |
Output is correct |
21 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
695 ms |
8472 KB |
Output is correct |
13 |
Correct |
359 ms |
9280 KB |
Output is correct |
14 |
Correct |
710 ms |
5496 KB |
Output is correct |
15 |
Correct |
812 ms |
5280 KB |
Output is correct |
16 |
Correct |
470 ms |
4856 KB |
Output is correct |
17 |
Correct |
775 ms |
5364 KB |
Output is correct |
18 |
Correct |
766 ms |
4984 KB |
Output is correct |
19 |
Correct |
1008 ms |
11376 KB |
Output is correct |
20 |
Correct |
1409 ms |
5480 KB |
Output is correct |
21 |
Correct |
320 ms |
2552 KB |
Output is correct |
22 |
Correct |
1586 ms |
6408 KB |
Output is correct |
23 |
Correct |
344 ms |
8824 KB |
Output is correct |
24 |
Correct |
895 ms |
6520 KB |
Output is correct |
25 |
Correct |
1845 ms |
9692 KB |
Output is correct |
26 |
Correct |
1545 ms |
9956 KB |
Output is correct |
27 |
Correct |
1473 ms |
8400 KB |
Output is correct |
28 |
Correct |
579 ms |
28464 KB |
Output is correct |
29 |
Correct |
1609 ms |
30948 KB |
Output is correct |
30 |
Correct |
1836 ms |
22920 KB |
Output is correct |
31 |
Correct |
1699 ms |
17504 KB |
Output is correct |
32 |
Correct |
498 ms |
2168 KB |
Output is correct |
33 |
Correct |
651 ms |
2424 KB |
Output is correct |
34 |
Correct |
451 ms |
26692 KB |
Output is correct |
35 |
Correct |
1202 ms |
15232 KB |
Output is correct |
36 |
Correct |
2724 ms |
27436 KB |
Output is correct |
37 |
Correct |
2155 ms |
27840 KB |
Output is correct |
38 |
Correct |
2157 ms |
27888 KB |
Output is correct |
39 |
Correct |
1799 ms |
22840 KB |
Output is correct |
40 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
416 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
701 ms |
8312 KB |
Output is correct |
13 |
Correct |
501 ms |
8568 KB |
Output is correct |
14 |
Correct |
689 ms |
5292 KB |
Output is correct |
15 |
Correct |
773 ms |
5156 KB |
Output is correct |
16 |
Correct |
462 ms |
4548 KB |
Output is correct |
17 |
Correct |
740 ms |
5240 KB |
Output is correct |
18 |
Correct |
710 ms |
4856 KB |
Output is correct |
19 |
Correct |
988 ms |
11164 KB |
Output is correct |
20 |
Correct |
1434 ms |
5256 KB |
Output is correct |
21 |
Correct |
338 ms |
2536 KB |
Output is correct |
22 |
Correct |
1654 ms |
5968 KB |
Output is correct |
23 |
Correct |
426 ms |
8648 KB |
Output is correct |
24 |
Correct |
917 ms |
6776 KB |
Output is correct |
25 |
Correct |
2015 ms |
9556 KB |
Output is correct |
26 |
Correct |
1666 ms |
9724 KB |
Output is correct |
27 |
Correct |
1799 ms |
9064 KB |
Output is correct |
28 |
Correct |
588 ms |
29176 KB |
Output is correct |
29 |
Correct |
1784 ms |
31424 KB |
Output is correct |
30 |
Correct |
2224 ms |
23088 KB |
Output is correct |
31 |
Correct |
1802 ms |
18156 KB |
Output is correct |
32 |
Correct |
503 ms |
3448 KB |
Output is correct |
33 |
Correct |
607 ms |
3988 KB |
Output is correct |
34 |
Correct |
478 ms |
27708 KB |
Output is correct |
35 |
Correct |
1308 ms |
16876 KB |
Output is correct |
36 |
Correct |
2700 ms |
28900 KB |
Output is correct |
37 |
Correct |
2049 ms |
29432 KB |
Output is correct |
38 |
Correct |
2082 ms |
28384 KB |
Output is correct |
39 |
Correct |
812 ms |
58420 KB |
Output is correct |
40 |
Correct |
2827 ms |
60360 KB |
Output is correct |
41 |
Correct |
3069 ms |
47216 KB |
Output is correct |
42 |
Correct |
2803 ms |
36344 KB |
Output is correct |
43 |
Correct |
928 ms |
57340 KB |
Output is correct |
44 |
Correct |
737 ms |
3908 KB |
Output is correct |
45 |
Correct |
1746 ms |
23508 KB |
Output is correct |
46 |
Correct |
3711 ms |
58404 KB |
Output is correct |
47 |
Correct |
3693 ms |
57832 KB |
Output is correct |
48 |
Correct |
3598 ms |
57592 KB |
Output is correct |
49 |
Correct |
1 ms |
256 KB |
Output is correct |