Submission #581440

#TimeUsernameProblemLanguageResultExecution timeMemory
581440ggohGame (IOI13_game)C++14
63 / 100
1628 ms256000 KiB
#include "game.h" #include <bits/stdc++.h> using namespace std; int R, C, N, ch, P, Q, U, V; int px,qx,py,qy; int xco, yco; long long v; long long K; struct Y { Y *left, *right ; Y(){left=right=NULL;val=0ll;} long long val; }; struct X { X *left, *right; Y *ynode; X(){left=right=NULL;ynode=NULL;} }*inix; long long gcd2(long long xx, long long yy) { if (yy == 0) return xx; return gcd2(yy, xx % yy); } void yup(Y *y, int s,int e) { if (s == e) { y->val = v; return; } if ((s + e) / 2 >= yco) { if (!y->left) { y->left=new Y(); } yup(y->left, s,(s+e)/2); } else { if (!y->right) { y->right=new Y(); } yup(y->right, (s+e)/2+1,e); } long long l = 0, r = 0; if (y->left) l = y->left->val; if (y->right) r = y->right->val; y->val = gcd2(l, r); } void hardyup(Y *y, int s,int e, Y *ly, Y *ry) { long long l = 0, r = 0; if (ly) { l =ly->val; } if (ry) { r = ry->val; } y->val = gcd2(l, r); if (s == e) return; if (yco <= (s + e) / 2) { if (!y->left) { y->left = new Y(); } hardyup(y->left, s,(s+e)/2,ly?ly->left:NULL, ry?ry->left:NULL); } else { if (!y->right) { y->right = new Y(); } hardyup(y->right, (s+e)/2+1,e,ly?ly->right:NULL, ry?ry->right:NULL); } } void xup(X *x, int s,int e) { if(!x->ynode)x->ynode=new Y(); if (s == e) { yup(x->ynode, 0,C-1); return; } if ((s + e) / 2 >= xco) { if (!x->left) { x->left = new X(); } xup(x->left, s,(s+e)/2); } else { if (!x->right) { x->right = new X(); } xup(x->right, (s+e)/2+1,e); } hardyup(x->ynode, 0,C-1,x->left?x->left->ynode:NULL, x->right?x->right->ynode:NULL); } long long yans(Y *y, int s,int e) { if (s > qy || e < py) return 0ll; if (py <= s && e <= qy) return y->val; long long l = 0, r = 0; if (y->left) l = yans(y->left,s,(s+e)/2); if (y->right) r = yans(y->right, (s+e)/2+1,e); return gcd2(l, r); } long long xans(X *x, int s,int e) { if(!x->ynode) return 0ll; if (s > qx || e < px) return 0ll; if (px <= s && e <= qx) { return yans(x->ynode, 0,C-1); } long long l = 0, r = 0; if (x->left) l = xans(x->left, s,(s+e)/2); if (x->right) r = xans(x->right,(s+e)/2+1,e); return gcd2(l, r); } void init(int RR, int CC) { R=RR; C=CC; inix=new X(); } void update(int P,int Q,long long K) { xco=P; yco=Q; v=K; xup(inix, 0,R-1); } long long calculate(int P,int Q,int U,int V) { px=P; qx=U; py=Q; qy=V; return xans(inix, 0,R-1); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...