Submission #962913

#TimeUsernameProblemLanguageResultExecution timeMemory
962913simona1230Game (IOI13_game)C++17
37 / 100
787 ms32200 KiB
#include <bits/stdc++.h> #include "game.h" using namespace std; int r,c; long long a[128][128]; bool subt1,subt2; void init(int R,int C) { r=R; c=C; if(max(r,c)<=100)subt1=1; else subt2=1; } long long x,y,v; long long t[10][400000]; void upd(int i,int l,int r) { if(l==r) { t[x][i]=v; return; } int m=(l+r)/2; if(y<=m)upd(i*2,l,m); else upd(i*2+1,m+1,r); long long lf=t[x][i*2]; long long rt=t[x][i*2+1]; if(lf==0)t[x][i]=rt; else if(rt==0)t[x][i]=lf; else t[x][i]=__gcd(lf,rt); } int idx; long long query(int i,int l,int r,int ql,int qr) { if(ql>qr)return 0; if(ql<=l&&r<=qr)return t[idx][i]; int m=(l+r)/2; long long lf=query(i*2,l,m,ql,min(qr,m)); long long rt=query(i*2+1,m+1,r,max(ql,m+1),qr); if(lf==0)return rt; if(rt==0)return lf; return __gcd(rt,lf); } void update(int X,int Y,long long V) { x=X; y=Y; v=V; if(subt1) { a[x][y]=v; return; } upd(1,0,c-1); } long long calculate(int p,int q,int u,int v) { if(subt1) { long long ans=0; for(int i=p; i<=u; i++) { for(int j=q; j<=v; j++) { if(a[i][j]!=0) { if(ans==0)ans=a[i][j]; else ans=__gcd(ans,a[i][j]); } } } //cout<<ans<<endl; return ans; } long long ans=0; for(int i=p;i<=u;i++) { //cout<<i<<"/"<<endl; idx=i; long long qr=query(1,0,c-1,q,v); if(qr==0)continue; if(ans==0)ans=qr; else ans=__gcd(ans,qr); } return ans; }
#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...