#include "game.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd2(ll X, ll Y) {
ll tmp;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
int n;
struct NodeY{
int s,e;
ll v;
NodeY *l = NULL;
NodeY *r = NULL;
NodeY(int _s, int _e){
s=_s;e=_e;
v=0;
}
void makeL(){
if (l!=NULL){
return;
}
l = new NodeY(s,(s+e)/2);
}
void makeR(){
if (r!=NULL){
return;
}
r = new NodeY((s+e)/2+1,e);
}
ll getL(){
if (l==NULL){
return 0;
}
return l->v;
}
ll getR(){
if (r==NULL){
return 0;
}
return r->v;
}
void update(int ind, ll val){
//cout<<"y "<<s<<' '<<e<<'\n';
//cout<<"u "<<ind<<' '<<val<<'\n';
if (s==e){
v=val;
return;
}
if (ind<=(s+e)/2){
makeL();
l->update(ind,val);
} else {
makeR();
r->update(ind,val);
}
v=gcd2(getL(),getR());
}
ll queryL(int ya, int yb){
if (l==NULL){
return 0;
}
return l->query(ya,yb);
}
ll queryR(int ya, int yb){
if (r==NULL){
return 0;
}
return r->query(ya,yb);
}
ll query(int ya, int yb){
if (s==ya&&e==yb){
return v;
}
int m = (s+e)/2;
if (yb<=m){
return queryL(ya,yb);
} else if (m<ya){
return queryR(ya,yb);
} else {
return gcd2(queryL(ya,m),queryR(m+1,yb));
}
}
void combine(NodeY *lc, NodeY *rc, int ind){
//cout<<s<<' '<<e<<' '<<"com\n";
int m = (s+e)/2;
if (s==e){
v=gcd2((lc==NULL)?0:lc->v,(rc==NULL)?0:rc->v);
return;
}
if (ind<=m){
makeL();
l->combine((lc==NULL)?(NodeY*)NULL:lc->l,(rc==NULL)?(NodeY*)NULL:rc->l,ind);
} else {
makeR();
r->combine((lc==NULL)?(NodeY*)NULL:lc->r,(rc==NULL)?(NodeY*)NULL:rc->r,ind);
}
v=gcd2((l==NULL)?0:l->v,(r==NULL)?0:r->v);
}
};
struct NodeX{
int s,e;
NodeY *v;
NodeX *l = NULL;
NodeX *r = NULL;
NodeX(int _s, int _e){
s=_s;e=_e;
v=new NodeY(0,n-1);
}
void makeL(){
if (l!=NULL){
return;
}
l = new NodeX(s,(s+e)/2);
}
void makeR(){
if (r!=NULL){
return;
}
r = new NodeX((s+e)/2+1,e);
}
void update(int indx, int indy, ll val){
//cout<<"x "<<s<<' '<<e<<'\n';
//cout<<"u "<<indx<<' '<<indy<<' '<<val<<'\n';
if (s==e){
v->update(indy,val);
return;
}
makeL();makeR();
if (indx<=(s+e)/2){
l->update(indx,indy,val);
} else {
r->update(indx,indy,val);
}
//cout<<"combine\n";
v->combine(l->v,r->v,indy); //???
}
ll queryL(int xa, int xb, int ya, int yb){
if (l==NULL){
return 0;
}
return l->query(xa,xb,ya,yb);
}
ll queryR(int xa, int xb, int ya, int yb){
if (r==NULL){
return 0;
}
return r->query(xa,xb,ya,yb);
}
ll query(int xa, int xb, int ya, int yb){
int m = (s+e)/2;
assert(xa<=xb&&ya<=yb);
if (s==xa&&e==xb){
return v->query(ya,yb);
}
if (xb<=m){
return queryL(xa,xb,ya,yb);
} else if (m<xa){
return queryR(xa,xb,ya,yb);
} else {
return gcd2(queryL(xa,m,ya,yb),queryR(m+1,xb,ya,yb));
}
}
};
NodeX *root;
int x,y;
void init(int R, int C) {
/* ... */
x=R;y=C;
n=y;
root = new NodeX(0,x-1);
}
void update(int P, int Q, long long K) {
/* ... */
root->update(P,Q,K);
}
long long calculate(int P, int Q, int U, int V) {
/* ... */
return root->query(P,U,Q,V);
}
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;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
512 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 |
512 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
0 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
552 ms |
18924 KB |
Output is correct |
5 |
Correct |
377 ms |
18296 KB |
Output is correct |
6 |
Correct |
512 ms |
15352 KB |
Output is correct |
7 |
Correct |
579 ms |
15096 KB |
Output is correct |
8 |
Correct |
380 ms |
10232 KB |
Output is correct |
9 |
Correct |
588 ms |
15224 KB |
Output is correct |
10 |
Correct |
519 ms |
14840 KB |
Output is correct |
11 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 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 |
512 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
861 ms |
22508 KB |
Output is correct |
13 |
Correct |
1409 ms |
9680 KB |
Output is correct |
14 |
Correct |
357 ms |
2040 KB |
Output is correct |
15 |
Correct |
1686 ms |
13432 KB |
Output is correct |
16 |
Correct |
262 ms |
27768 KB |
Output is correct |
17 |
Correct |
968 ms |
17528 KB |
Output is correct |
18 |
Correct |
1618 ms |
28152 KB |
Output is correct |
19 |
Correct |
1465 ms |
28524 KB |
Output is correct |
20 |
Correct |
1311 ms |
27708 KB |
Output is correct |
21 |
Correct |
0 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
0 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
552 ms |
19064 KB |
Output is correct |
13 |
Correct |
383 ms |
18424 KB |
Output is correct |
14 |
Correct |
513 ms |
15480 KB |
Output is correct |
15 |
Correct |
564 ms |
14968 KB |
Output is correct |
16 |
Correct |
393 ms |
10264 KB |
Output is correct |
17 |
Correct |
555 ms |
15352 KB |
Output is correct |
18 |
Correct |
522 ms |
14712 KB |
Output is correct |
19 |
Correct |
883 ms |
22908 KB |
Output is correct |
20 |
Correct |
1404 ms |
10360 KB |
Output is correct |
21 |
Correct |
310 ms |
2272 KB |
Output is correct |
22 |
Correct |
1643 ms |
13944 KB |
Output is correct |
23 |
Correct |
269 ms |
28152 KB |
Output is correct |
24 |
Correct |
1022 ms |
17596 KB |
Output is correct |
25 |
Correct |
1710 ms |
28608 KB |
Output is correct |
26 |
Correct |
1366 ms |
28776 KB |
Output is correct |
27 |
Correct |
1253 ms |
28072 KB |
Output is correct |
28 |
Runtime error |
677 ms |
256004 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
29 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
512 KB |
Output is correct |
4 |
Correct |
0 ms |
256 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
0 ms |
256 KB |
Output is correct |
9 |
Correct |
1 ms |
512 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
713 ms |
18296 KB |
Output is correct |
13 |
Correct |
388 ms |
18040 KB |
Output is correct |
14 |
Correct |
545 ms |
15216 KB |
Output is correct |
15 |
Correct |
590 ms |
14584 KB |
Output is correct |
16 |
Correct |
381 ms |
9848 KB |
Output is correct |
17 |
Correct |
563 ms |
14844 KB |
Output is correct |
18 |
Correct |
539 ms |
14328 KB |
Output is correct |
19 |
Correct |
843 ms |
22392 KB |
Output is correct |
20 |
Correct |
1407 ms |
9464 KB |
Output is correct |
21 |
Correct |
330 ms |
1776 KB |
Output is correct |
22 |
Correct |
1613 ms |
13460 KB |
Output is correct |
23 |
Correct |
253 ms |
27640 KB |
Output is correct |
24 |
Correct |
988 ms |
17272 KB |
Output is correct |
25 |
Correct |
1839 ms |
28232 KB |
Output is correct |
26 |
Correct |
1438 ms |
28564 KB |
Output is correct |
27 |
Correct |
1262 ms |
27740 KB |
Output is correct |
28 |
Runtime error |
656 ms |
256008 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
29 |
Halted |
0 ms |
0 KB |
- |