# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
753144 |
2023-06-04T16:38:34 Z |
jamielim |
Game (IOI13_game) |
C++14 |
|
2593 ms |
93588 KB |
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb emplace_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)x.size()
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ii,ii> i4;
typedef vector<int> vi;
const int MOD=1000000007;
const int INF=1012345678;
const ll LLINF=1012345678012345678LL;
const double PI=3.1415926536;
const double EPS=1e-14;
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;
}
struct node{
int s,e,m;
ll v;
node *l,*r;
node(int S,int E){
s=S;e=E;m=(s+e)/2;
v=0;l=r=NULL;
}
node(int x,node *n){
int b=(n->e-n->s+1);
if(n->s>x){
e=n->e;
while(e+1-b>x)b<<=1;
s=e+1-b;
l=new node(x,x);r=n;
v=r->v;
}else{
s=n->s;
while(s+b-1<x)b<<=1;
e=s+b-1;
l=n;r=new node(x,x);
v=l->v;
}
m=(s+e)/2;
}
void upd(int x,ll val){
if(s==e){v=val;return;}
if(x<=m){
if(l==NULL)l=new node(x,x);
else if(l->s>x||x>l->e)l=new node(x,l);
l->upd(x,val);
}else{
if(r==NULL)r=new node(x,x);
else if(r->s>x||x>r->e)r=new node(x,r);
r->upd(x,val);
}
v=gcd2((l?l->v:0),(r?r->v:0));
}
ll qry(int x1,int x2){
if(s>=x1&&e<=x2)return v;
if(x2<=m)return (l?l->qry(x1,x2):0);
if(x1>m)return (r?r->qry(x1,x2):0);
return gcd2((l?l->qry(x1,x2):0),(r?r->qry(x1,x2):0));
}
};
struct node2d{
int s,e,m;
node *n;
node2d *l,*r;
node2d(int S,int E){
s=S;e=E;m=(s+e)/2;
n=new node(0,(1<<30)-1);l=r=NULL;
}
void upd(int x,int y,ll val){
if(s==e){
n->upd(y,val);
return;
}
if(x<=m){
if(l==NULL)l=new node2d(s,m);
l->upd(x,y,val);
}else{
if(r==NULL)r=new node2d(m+1,e);
r->upd(x,y,val);
}
ll nv=gcd2((l?l->n->qry(y,y):0),(r?r->n->qry(y,y):0));
n->upd(y,nv);
}
ll qry(int x1,int y1,int x2,int y2){
if(s>=x1&&e<=x2)return (n?n->qry(y1,y2):0);
if(x2<=m)return (l?l->qry(x1,y1,x2,y2):0);
if(x1>m)return (r?r->qry(x1,y1,x2,y2):0);
return gcd2((l?l->qry(x1,y1,x2,y2):0),(r?r->qry(x1,y1,x2,y2):0));
}
}*root=new node2d(0,(1<<30)-1);
void init(int R, int C) {}
void update(int P, int Q, long long K) {
root->upd(P,Q,K);
}
long long calculate(int P, int Q, int U, int V) {
return root->qry(P,Q,U,V);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
424 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
428 KB |
Output is correct |
12 |
Correct |
1 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
528 ms |
36480 KB |
Output is correct |
5 |
Correct |
343 ms |
36216 KB |
Output is correct |
6 |
Correct |
665 ms |
33816 KB |
Output is correct |
7 |
Correct |
688 ms |
33516 KB |
Output is correct |
8 |
Correct |
434 ms |
19736 KB |
Output is correct |
9 |
Correct |
779 ms |
33608 KB |
Output is correct |
10 |
Correct |
696 ms |
33360 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
428 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
428 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
2 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
811 ms |
17596 KB |
Output is correct |
13 |
Correct |
1304 ms |
10820 KB |
Output is correct |
14 |
Correct |
232 ms |
5596 KB |
Output is correct |
15 |
Correct |
1290 ms |
13924 KB |
Output is correct |
16 |
Correct |
383 ms |
17928 KB |
Output is correct |
17 |
Correct |
638 ms |
14544 KB |
Output is correct |
18 |
Correct |
1455 ms |
19400 KB |
Output is correct |
19 |
Correct |
1143 ms |
19560 KB |
Output is correct |
20 |
Correct |
1106 ms |
19064 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
436 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
428 KB |
Output is correct |
7 |
Correct |
1 ms |
300 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
523 ms |
36508 KB |
Output is correct |
13 |
Correct |
336 ms |
36172 KB |
Output is correct |
14 |
Correct |
595 ms |
33784 KB |
Output is correct |
15 |
Correct |
647 ms |
33620 KB |
Output is correct |
16 |
Correct |
369 ms |
19740 KB |
Output is correct |
17 |
Correct |
628 ms |
33612 KB |
Output is correct |
18 |
Correct |
668 ms |
33276 KB |
Output is correct |
19 |
Correct |
717 ms |
17528 KB |
Output is correct |
20 |
Correct |
1275 ms |
10888 KB |
Output is correct |
21 |
Correct |
242 ms |
5732 KB |
Output is correct |
22 |
Correct |
1325 ms |
13976 KB |
Output is correct |
23 |
Correct |
309 ms |
17984 KB |
Output is correct |
24 |
Correct |
622 ms |
14676 KB |
Output is correct |
25 |
Correct |
1482 ms |
19360 KB |
Output is correct |
26 |
Correct |
1190 ms |
19544 KB |
Output is correct |
27 |
Correct |
953 ms |
18888 KB |
Output is correct |
28 |
Correct |
435 ms |
48716 KB |
Output is correct |
29 |
Correct |
1217 ms |
50964 KB |
Output is correct |
30 |
Correct |
1782 ms |
38316 KB |
Output is correct |
31 |
Correct |
1648 ms |
30804 KB |
Output is correct |
32 |
Correct |
274 ms |
10216 KB |
Output is correct |
33 |
Correct |
382 ms |
10728 KB |
Output is correct |
34 |
Correct |
461 ms |
44716 KB |
Output is correct |
35 |
Correct |
793 ms |
29864 KB |
Output is correct |
36 |
Correct |
1680 ms |
48812 KB |
Output is correct |
37 |
Correct |
1363 ms |
49048 KB |
Output is correct |
38 |
Correct |
1244 ms |
48468 KB |
Output is correct |
39 |
Correct |
1122 ms |
39992 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
2 ms |
424 KB |
Output is correct |
7 |
Correct |
1 ms |
304 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
557 ms |
36588 KB |
Output is correct |
13 |
Correct |
348 ms |
36240 KB |
Output is correct |
14 |
Correct |
616 ms |
33836 KB |
Output is correct |
15 |
Correct |
732 ms |
33632 KB |
Output is correct |
16 |
Correct |
389 ms |
19768 KB |
Output is correct |
17 |
Correct |
629 ms |
33572 KB |
Output is correct |
18 |
Correct |
622 ms |
33352 KB |
Output is correct |
19 |
Correct |
763 ms |
17516 KB |
Output is correct |
20 |
Correct |
1246 ms |
10844 KB |
Output is correct |
21 |
Correct |
230 ms |
5636 KB |
Output is correct |
22 |
Correct |
1277 ms |
14076 KB |
Output is correct |
23 |
Correct |
335 ms |
17984 KB |
Output is correct |
24 |
Correct |
648 ms |
14644 KB |
Output is correct |
25 |
Correct |
1334 ms |
19456 KB |
Output is correct |
26 |
Correct |
1192 ms |
19576 KB |
Output is correct |
27 |
Correct |
1061 ms |
18964 KB |
Output is correct |
28 |
Correct |
534 ms |
48772 KB |
Output is correct |
29 |
Correct |
1289 ms |
51000 KB |
Output is correct |
30 |
Correct |
1820 ms |
38304 KB |
Output is correct |
31 |
Correct |
1607 ms |
31052 KB |
Output is correct |
32 |
Correct |
307 ms |
10272 KB |
Output is correct |
33 |
Correct |
489 ms |
10724 KB |
Output is correct |
34 |
Correct |
466 ms |
44756 KB |
Output is correct |
35 |
Correct |
813 ms |
29888 KB |
Output is correct |
36 |
Correct |
1916 ms |
48872 KB |
Output is correct |
37 |
Correct |
1355 ms |
49036 KB |
Output is correct |
38 |
Correct |
1304 ms |
48516 KB |
Output is correct |
39 |
Correct |
617 ms |
92620 KB |
Output is correct |
40 |
Correct |
2093 ms |
93588 KB |
Output is correct |
41 |
Correct |
2593 ms |
73540 KB |
Output is correct |
42 |
Correct |
2287 ms |
57304 KB |
Output is correct |
43 |
Correct |
756 ms |
88508 KB |
Output is correct |
44 |
Correct |
346 ms |
10792 KB |
Output is correct |
45 |
Correct |
1035 ms |
40108 KB |
Output is correct |
46 |
Correct |
2333 ms |
92560 KB |
Output is correct |
47 |
Correct |
2416 ms |
92520 KB |
Output is correct |
48 |
Correct |
2244 ms |
92008 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |