# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
93111 |
2019-01-06T13:50:57 Z |
Bodo171 |
Game (IOI13_game) |
C++14 |
|
3 ms |
504 KB |
#include "game.h"
#include <climits>
#include <iostream>
#include <algorithm>
#include <map>
#define mp make_pair
using namespace std;
struct aint
{
aint *ls,*rs,*nxt;
long long val;
aint()
{
ls=rs=nxt=0;
val=0;
}
}*rad;
long long ans;
int R,C;
int X1,Y1,X2,Y2;
long long gcd(long long X, long long Y) {
long long tmp;
if(!X) return Y;
while (X != Y && Y != 0) {
tmp = X;
X = Y;
Y = tmp % Y;
}
return X;
}
void init(int Rr, int Cc) {
R=Rr;C=Cc;
rad=new aint;
}
void updY(aint* &nod,int l,int r,int poz,long long val)
{
if(l==r)
{
nod->val=val;
return;
}
int m=(l+r)/2;
if(poz<=m)
{
if(!nod->ls) nod->ls=new aint;
updY(nod->ls,l,m,poz,val);
}
else
{
if(!nod->rs) nod->rs=new aint;
updY(nod->rs,m+1,r,poz,val);
}
nod->val=0;
if(nod->ls) nod->val=gcd(nod->val,nod->ls->val);
if(nod->rs) nod->val=gcd(nod->val,nod->rs->val);
}
void updX(aint* &nod,int l,int r,int poz,int y,long long val)
{
if(!nod->nxt) nod->nxt=new aint;
updY(nod->nxt,1,C,y,val);
if(l==r) return;
int m=(l+r)/2;
if(poz<=m)
{
if(!nod->ls) nod->ls=new aint;
updX(nod->ls,l,m,poz,y,val);
}
else
{
if(!nod->rs) nod->rs=new aint;
updX(nod->rs,m+1,r,poz,y,val);
}
}
void qrY(aint* &nod,int l,int r)
{
if(Y1<=l&&r<=Y2)
{
ans=gcd(ans,nod->val);
return;
}
int m=(l+r)/2;
if(Y1<=m&&nod->ls) qrY(nod->ls,l,m);
if(m<Y2&&nod->rs) qrY(nod->rs,m+1,r);
}
void qrX(aint* &nod,int l,int r)
{
if(X1<=l&&r<=X2)
{
if(nod->nxt) qrY(nod->nxt,1,C);
return;
}
int m=(l+r)/2;
if(X1<=m&&nod->ls) qrX(nod->ls,l,m);
if(m<X2&&nod->rs) qrX(nod->rs,m+1,r);
}
void update(int P, int Q, long long K) {
P++,Q++;
updX(rad,1,R,P,Q,K);
}
long long calculate(int P, int Q, int U, int V) {
ans=0;
P++,Q++,U++,V++;
X1=P;Y1=Q;X2=U;Y2=V;
qrX(rad,1,R);
return ans;
}
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 |
3 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
256 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |