#include<bits/stdc++.h>
#include "game.h"
#define MAXN 25007
using namespace std;
const int maxs=1e9;
unordered_map<int,int> mp;
struct node{
int l,r;
long long val;
};
int num;
node tree[400*MAXN];
struct ST{
int root;
void init(){
num++;
root=num;
}
void addnode(){
num++;
}
void update(int v,int l,int r,int pos,long long val){
if(l==r){
tree[v].val=val;
}else{
int tt=(l+r)/2;
if(pos<=tt){
if(tree[v].l==0){
addnode(); tree[v].l=num;
}
update(tree[v].l,l,tt,pos,val);
}else{
if(tree[v].r==0){
addnode(); tree[v].r=num;
}
update(tree[v].r,tt+1,r,pos,val);
}
tree[v].val=__gcd(tree[tree[v].l].val,tree[tree[v].r].val);
}
}
long long getgcd(int v,int l,int r,int ll,int rr){
if(v==0 or ll>rr)return 0;
if(l==ll and r==rr){
return tree[v].val;
}else{
int tt=(l+r)/2;
return __gcd( getgcd(tree[v].l,l,tt,ll,min(tt,rr)) , getgcd(tree[v].r,tt+1,r,max(tt+1,ll),rr) );
}
}
void upd(int pos,long long val){
update(root,1,maxs,pos,val);
}
long long query(int l,int r){
return getgcd(root,1,maxs,l,r);
}
};
int last,currid;
ST col[MAXN];
struct ST2D{
struct node{
int l,r;
ST t;
};
node tree[35*MAXN];
int num;
void init(){
tree[1].t.init();
num=1;
}
void addnode(){
num++;
tree[num].t.init();
}
void update(int v,int l,int r,int posx,int posy,long long val){
if(l==r){
tree[v].t.upd(posy,val);
}else{
int tt=(l+r)/2;
if(posx<=tt){
if(tree[v].l==0){
addnode(); tree[v].l=num;
}
update(tree[v].l,l,tt,posx,posy,val);
}else{
if(tree[v].r==0){
addnode(); tree[v].r=num;
}
update(tree[v].r,tt+1,r,posx,posy,val);
}
long long newval = col[currid].query(l,r);
tree[v].t.upd(posy,newval);
}
}
long long getgcd(int v,int l,int r,int lx,int rx,int ly,int ry){
if(v==0 or lx>rx)return 0;
if(l==lx and r==rx){
return tree[v].t.query(ly,ry);
}else{
int tt=(l+r)/2;
return __gcd( getgcd(tree[v].l,l,tt,lx,min(tt,rx),ly,ry) , getgcd(tree[v].r,tt+1,r,max(tt+1,lx),rx,ly,ry) );
}
}
void upd(int x,int y,long long val){
update(1,1,maxs,x,y,val);
}
long long query(int a,int b,int c,int d){
return getgcd(1,1,maxs,a,c,b,d);
}
}seg;
void init(int R, int C) {
seg.init();
}
void update(int P, int Q, long long K) {
P++; Q++;
if(mp[Q]==0){
last++; mp[Q]=last;
col[last].init();
}
currid=mp[Q];
col[currid].upd(P,K);
seg.upd(P,Q,K);
}
long long calculate(int P, int Q, int U, int V) {
P++; Q++; U++; V++;
return seg.query(P,Q,U,V);
}
/*int main(){
init(10,10);
update(0,0,20);
update(0,2,15);
update(1,1,12);
cout<<calculate(0,0,0,2)<<"\n";
cout<<calculate(0,0,1,1)<<"\n";
update(0,1,6);
update(1,1,14);
cout<<calculate(0,0,0,2)<<"\n";
cout<<calculate(0,0,1,1)<<"\n";
return 0;
}*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2648 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
2 ms |
2552 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
2 ms |
4432 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
2 ms |
4432 KB |
Output is correct |
12 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
1 ms |
2384 KB |
Output is correct |
3 |
Correct |
1 ms |
2384 KB |
Output is correct |
4 |
Correct |
490 ms |
35576 KB |
Output is correct |
5 |
Correct |
362 ms |
34632 KB |
Output is correct |
6 |
Correct |
489 ms |
31560 KB |
Output is correct |
7 |
Correct |
508 ms |
31272 KB |
Output is correct |
8 |
Correct |
364 ms |
20636 KB |
Output is correct |
9 |
Correct |
533 ms |
31308 KB |
Output is correct |
10 |
Correct |
476 ms |
30856 KB |
Output is correct |
11 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2384 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
2 ms |
2896 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
2 ms |
4656 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
2 ms |
4600 KB |
Output is correct |
12 |
Correct |
811 ms |
14964 KB |
Output is correct |
13 |
Correct |
1075 ms |
8008 KB |
Output is correct |
14 |
Correct |
384 ms |
3136 KB |
Output is correct |
15 |
Correct |
1135 ms |
10820 KB |
Output is correct |
16 |
Correct |
358 ms |
16456 KB |
Output is correct |
17 |
Correct |
746 ms |
12272 KB |
Output is correct |
18 |
Correct |
1110 ms |
16744 KB |
Output is correct |
19 |
Correct |
1045 ms |
17992 KB |
Output is correct |
20 |
Correct |
1018 ms |
16200 KB |
Output is correct |
21 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2384 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
1 ms |
2384 KB |
Output is correct |
8 |
Correct |
1 ms |
2384 KB |
Output is correct |
9 |
Correct |
2 ms |
4432 KB |
Output is correct |
10 |
Correct |
1 ms |
2516 KB |
Output is correct |
11 |
Correct |
2 ms |
4432 KB |
Output is correct |
12 |
Correct |
524 ms |
35656 KB |
Output is correct |
13 |
Correct |
406 ms |
34632 KB |
Output is correct |
14 |
Correct |
528 ms |
31412 KB |
Output is correct |
15 |
Correct |
536 ms |
31304 KB |
Output is correct |
16 |
Correct |
414 ms |
20632 KB |
Output is correct |
17 |
Correct |
528 ms |
31304 KB |
Output is correct |
18 |
Correct |
510 ms |
30860 KB |
Output is correct |
19 |
Correct |
793 ms |
15028 KB |
Output is correct |
20 |
Correct |
1080 ms |
8012 KB |
Output is correct |
21 |
Correct |
407 ms |
3128 KB |
Output is correct |
22 |
Correct |
1152 ms |
10824 KB |
Output is correct |
23 |
Correct |
383 ms |
16596 KB |
Output is correct |
24 |
Correct |
772 ms |
12376 KB |
Output is correct |
25 |
Correct |
1118 ms |
16712 KB |
Output is correct |
26 |
Correct |
1018 ms |
18088 KB |
Output is correct |
27 |
Correct |
994 ms |
16272 KB |
Output is correct |
28 |
Correct |
509 ms |
135860 KB |
Output is correct |
29 |
Correct |
1072 ms |
153540 KB |
Output is correct |
30 |
Correct |
2267 ms |
109512 KB |
Output is correct |
31 |
Correct |
2207 ms |
84620 KB |
Output is correct |
32 |
Correct |
336 ms |
3144 KB |
Output is correct |
33 |
Correct |
433 ms |
9288 KB |
Output is correct |
34 |
Correct |
303 ms |
145236 KB |
Output is correct |
35 |
Correct |
787 ms |
75976 KB |
Output is correct |
36 |
Correct |
1427 ms |
145596 KB |
Output is correct |
37 |
Correct |
1172 ms |
151344 KB |
Output is correct |
38 |
Correct |
1212 ms |
150660 KB |
Output is correct |
39 |
Correct |
947 ms |
112828 KB |
Output is correct |
40 |
Correct |
1 ms |
2384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2552 KB |
Output is correct |
2 |
Correct |
2 ms |
2640 KB |
Output is correct |
3 |
Correct |
2 ms |
2640 KB |
Output is correct |
4 |
Correct |
1 ms |
2384 KB |
Output is correct |
5 |
Correct |
1 ms |
2384 KB |
Output is correct |
6 |
Correct |
2 ms |
2640 KB |
Output is correct |
7 |
Correct |
1 ms |
2552 KB |
Output is correct |
8 |
Correct |
1 ms |
2552 KB |
Output is correct |
9 |
Correct |
2 ms |
4544 KB |
Output is correct |
10 |
Correct |
1 ms |
2384 KB |
Output is correct |
11 |
Correct |
1 ms |
4432 KB |
Output is correct |
12 |
Correct |
517 ms |
35408 KB |
Output is correct |
13 |
Correct |
407 ms |
34660 KB |
Output is correct |
14 |
Correct |
545 ms |
31560 KB |
Output is correct |
15 |
Correct |
512 ms |
31200 KB |
Output is correct |
16 |
Correct |
348 ms |
20552 KB |
Output is correct |
17 |
Correct |
520 ms |
31376 KB |
Output is correct |
18 |
Correct |
504 ms |
30856 KB |
Output is correct |
19 |
Correct |
797 ms |
15176 KB |
Output is correct |
20 |
Correct |
1027 ms |
7972 KB |
Output is correct |
21 |
Correct |
373 ms |
3124 KB |
Output is correct |
22 |
Correct |
1137 ms |
10852 KB |
Output is correct |
23 |
Correct |
349 ms |
16456 KB |
Output is correct |
24 |
Correct |
737 ms |
12316 KB |
Output is correct |
25 |
Correct |
1129 ms |
16764 KB |
Output is correct |
26 |
Correct |
1039 ms |
18176 KB |
Output is correct |
27 |
Correct |
1006 ms |
16200 KB |
Output is correct |
28 |
Correct |
475 ms |
135752 KB |
Output is correct |
29 |
Correct |
1107 ms |
148044 KB |
Output is correct |
30 |
Correct |
2450 ms |
109556 KB |
Output is correct |
31 |
Correct |
2406 ms |
88568 KB |
Output is correct |
32 |
Correct |
339 ms |
3144 KB |
Output is correct |
33 |
Correct |
426 ms |
9288 KB |
Output is correct |
34 |
Correct |
314 ms |
145176 KB |
Output is correct |
35 |
Correct |
790 ms |
81224 KB |
Output is correct |
36 |
Correct |
1529 ms |
145400 KB |
Output is correct |
37 |
Correct |
1263 ms |
145736 KB |
Output is correct |
38 |
Correct |
1193 ms |
145072 KB |
Output is correct |
39 |
Runtime error |
801 ms |
256000 KB |
Execution killed with signal 9 |
40 |
Halted |
0 ms |
0 KB |
- |