답안 #69010

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
69010 2018-08-19T13:19:28 Z MKopchev 게임 (IOI13_game) C++14
0 / 100
5 ms 2680 KB
#include<bits/stdc++.h>
#include "game.h"
using namespace std;
vector< vector<long long> > tree;
long long my_gcd(long long a,long long b)
{
    if(a==0||b==0)return a+b;
    long long r=a%b;
    while(r)
    {
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}
int r,c;
void init(int R, int C)
{
    r=R;
    c=C;
    int u=1;
    while(u<C)u=u*2;
    u=u*4+5;

    int v=1;
    while(v<R)v=v*2;
    v=v*4+5;

    vector<long long> help={};
    for(int j=0;j<v;j++)help.push_back(0);
    for(int i=0;i<u;i++)
        {
        tree.push_back(help);
        }

}
void upd(int ind,int node,int l,int r,int pos,long long val)
{
    if(l==r)
    {
        assert(l==pos);
        tree[ind][node]=val;
        return;
    }
    int av=(l+r)/2;
    if(pos<=av)upd(ind,node*2,l,av,pos,val);
    else upd(ind,node*2+1,av+1,r,pos,val);
    tree[ind][node]=my_gcd(tree[ind][node*2],tree[ind][node*2+1]);
}
void my_update(int node,int lx,int rx,int x,int y,long long val)
{
    upd(node,1,0,c-1,y,val);
    if(lx==rx)
    {
        assert(lx==x);
        return;
    }
    int av=(lx+rx)/2;
    if(x<=av)my_update(node*2,lx,av,x,y,val);
    else my_update(node*2+1,av+1,rx,x,y,val);
}
void update(int P, int Q, long long K)
{
    my_update(1,0,r-1,P,Q,K);
}
long long que(int ind,int node,int l,int r,int lq,int rq)
{
    if(l==lq&&r==rq)return tree[ind][node];
    int av=(l+r)/2;
    long long ans=0;
    if(lq<=av)ans=my_gcd(ans,que(ind,node*2,l,av,lq,min(av,rq)));
    if(av<rq)ans=my_gcd(ans,que(ind,node*2+1,av+1,r,max(av+1,lq),rq));
    return ans;
}
int lq_x,rq_x,lq_y,rq_y;
long long my_query(int node,int l,int r,int lq,int rq)
{
    /*
    cout<<lx<<" "<<rx<<" "<<ly<<" "<<ry<<endl;
    cout<<"query: "<<lq_x<<" "<<rq_x<<" "<<lq_y<<" "<<rq_y<<endl;
    */
    if(l==lq&&r==rq)return que(node,1,0,c-1,lq_y,rq_y);
    int av=(l+r)/2;
    long long ans=0;
    if(lq<=av)ans=my_gcd(ans,my_query(node*2,l,av,lq,min(av,rq)));
    if(av<rq)ans=my_gcd(ans,my_query(node*2+1,av+1,r,max(av+1,lq),rq));
    return ans;
}
long long calculate(int P, int Q, int U, int V)
{
    lq_x=P;
    lq_y=Q;
    rq_x=U;
    rq_y=V;
    long long ans=my_query(1,0,r-1,lq_x,rq_x);
    /*
    for(int i=P;i<=U;i++)
        ans=my_gcd(ans,my_query(i,1,0,c-1,Q,V));
    */
    return ans;
}
/*
int main()
{
init(2,3);
update(0,0,20);
update(0,2,15);
update(1,1,12);
cout<<calculate(0,0,0,2)<<endl;//5
cout<<calculate(0,0,1,1)<<endl;//4
update(0,1,6);
update(1,1,14);
cout<<calculate(0,0,0,2)<<endl;//1
cout<<calculate(0,0,1,1)<<endl;//2
}
*/

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;
      ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 248 KB Output is correct
2 Incorrect 5 ms 2536 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2536 KB Output is correct
2 Incorrect 2 ms 2536 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2536 KB Output is correct
2 Incorrect 5 ms 2620 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2620 KB Output is correct
2 Incorrect 5 ms 2648 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 2648 KB Output is correct
2 Incorrect 4 ms 2680 KB Output isn't correct
3 Halted 0 ms 0 KB -