Submission #1031144

#TimeUsernameProblemLanguageResultExecution timeMemory
1031144vjudge1Game (IOI13_game)C++17
37 / 100
13070 ms173228 KiB
#include "game.h" 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; } #include<iostream> #include<cassert> struct { struct Node{ long long val=0; int ch[4]{0,0,0,0}; }tree[7000000]; int nx=1; int n,m; void init(int N,int M){ n=N,m=M; } int P1,P2; long long VAL; void update(int l1,int r1,int l2,int r2,int&node){ if(r1<l1||r2<l2)return; assert(l1<=r1&&l2<=r2); if(!node){ node=++nx; } if(l1==r1&&l2==r2){ tree[node].val=VAL; return; } int mid1=(l1+r1)>>1,mid2=(l2+r2)>>1; if(P1<=mid1){ if(P2<=mid2){ update(l1,mid1,l2,mid2,tree[node].ch[0]); }else{ update(l1,mid1,mid2+1,r2,tree[node].ch[1]); } }else{ if(P2<=mid2){ update(mid1+1,r1,l2,mid2,tree[node].ch[2]); }else{ update(mid1+1,r1,mid2+1,r2,tree[node].ch[3]); } } tree[node].val=0; for(int i=0;i<4;i++)if(tree[node].ch[i])tree[node].val=gcd2(tree[node].val,tree[tree[node].ch[i]].val); } void update(int p1,int p2,long long val){ P1=p1,P2=p2,VAL=val; int root=1; update(0,n-1,0,m-1,root); } int L1,R1,L2,R2; long long ANS; void query(int l1,int r1,int l2,int r2,int node){ if(r1<l1||r2<l2)return; if(!node)return; if(L1<=l1&&r1<=R1&&L2<=l2&&r2<=R2){ ANS=gcd2(ANS,tree[node].val); return; } if(r1<L1||R1<l1||r2<L2||R2<l2)return; int mid1=(l1+r1)>>1,mid2=(l2+r2)>>1; query(l1,mid1,l2,mid2,tree[node].ch[0]); if(mid2+1<=r2)query(l1,mid1,mid2+1,r2,tree[node].ch[1]); if(mid1+1<=r1)query(mid1+1,r1,l2,mid2,tree[node].ch[2]); if(mid1+1<=r1&&mid2+1<=r2)query(mid1+1,r1,mid2+1,r2,tree[node].ch[3]); } long long query(int l1,int r1,int l2,int r2){ L1=l1,R1=r1,L2=l2,R2=r2; ANS=0; query(0,n-1,0,m-1,1); return ANS; } }st; void init(int R, int C) { //std::cerr<<"ok\n"; st.init(R,C); //std::cerr<<"ok1\n"; } void update(int P, int Q, long long K) { //std::cerr<<"up ok\n"; st.update(P,Q,K); //std::cerr<<"up ok1\n"; } long long calculate(int P, int Q, int U, int V) { //std::cerr<<"begun\n"; long long val=st.query(P,U,Q,V); //std::cerr<<"ended\n"; return val; }
#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...