Submission #133339

#TimeUsernameProblemLanguageResultExecution timeMemory
133339amiratouGame (IOI13_game)C++14
63 / 100
2914 ms133904 KiB
#pragma GCC optimize("O3")
#include "game.h"
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int n,m;
ll st[8005][8005],st2[45][400002];
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;
}

void init(int R, int C) {
    n=R,m=C;
}
void update_y(int node,int l,int r,int node_x,int lx,int rx,int y,ll val){
    if(l>y||r<y)
        return ;
    if(l==r){
        if(lx==rx)st[node_x][node]=val;
        else st[node_x][node]=gcd2(st[node_x<<1][node],st[(node_x<<1)+1][node]);
        return ;
    }
    int med=((l+r)>>1);
    update_y((node<<1),l,med,node_x,lx,rx,y,val);
    update_y((node<<1)+1,med+1,r,node_x,lx,rx,y,val);
    st[node_x][node]=gcd2(st[node_x][(node<<1)],st[node_x][(node<<1)+1]);
}
void update_y2(int node,int l,int r,int node_x,int lx,int rx,int y,ll val){
    if(l>y||r<y)
        return ;
    if(l==r){
        if(lx==rx)st2[node_x][node]=val;
        else st2[node_x][node]=gcd2(st2[node_x<<1][node],st2[(node_x<<1)+1][node]);
        return ;
    }
    int med=((l+r)>>1);
    update_y2((node<<1),l,med,node_x,lx,rx,y,val);
    update_y2((node<<1)+1,med+1,r,node_x,lx,rx,y,val);
    st2[node_x][node]=gcd2(st2[node_x][(node<<1)],st2[node_x][(node<<1)+1]);
}
void update_x2(int node,int l,int r,int x,int y,ll val){
    if(l>x||r<x)
        return ;
    if(l!=r){
        int med=((l+r)>>1);
        update_x2((node<<1),l,med,x,y,val);
        update_x2((node<<1)+1,med+1,r,x,y,val);
    }
    update_y2(1,0,m-1,node,l,r,y,val);
}
void update_x(int node,int l,int r,int x,int y,ll val){
    if(l>x||r<x)
        return ;
    if(l!=r){
        int med=((l+r)>>1);
        update_x((node<<1),l,med,x,y,val);
        update_x((node<<1)+1,med+1,r,x,y,val);
    }
    update_y(1,0,m-1,node,l,r,y,val);
}
ll query_y(int node,int l,int r,int node_x,int y1,int y2){
    if(l>y2||r<y1)
        return 0LL;
    if(l>=y1&&r<=y2)
        return st[node_x][node];
    int med=((l+r)>>1);
    return gcd2(query_y((node<<1),l,med,node_x,y1,y2),query_y((node<<1)+1,med+1,r,node_x,y1,y2));
}
ll query_y2(int node,int l,int r,int node_x,int y1,int y2){
    if(l>y2||r<y1)
        return 0LL;
    if(l>=y1&&r<=y2)
        return st2[node_x][node];
    int med=((l+r)>>1);
    return gcd2(query_y2((node<<1),l,med,node_x,y1,y2),query_y2((node<<1)+1,med+1,r,node_x,y1,y2));
}
ll query_x2(int node,int l,int r,int x1,int y1,int x2,int y2){
    if(l>x2||r<x1)
        return 0LL;
    if(l>=x1&&r<=x2)
        return query_y2(1,0,m-1,node,y1,y2);
    int med=((l+r)>>1);
    return gcd2(query_x2((node<<1),l,med,x1,y1,x2,y2),query_x2((node<<1)+1,med+1,r,x1,y1,x2,y2));
}
ll query_x(int node,int l,int r,int x1,int y1,int x2,int y2){
    if(l>x2||r<x1)
        return 0LL;
    if(l>=x1&&r<=x2)
        return query_y(1,0,m-1,node,y1,y2);
    int med=((l+r)>>1);
    return gcd2(query_x((node<<1),l,med,x1,y1,x2,y2),query_x((node<<1)+1,med+1,r,x1,y1,x2,y2));
}
void update(int P, int Q, ll K) {
    if(n<=10&&m<=100000)update_x2(1,0,n-1,P,Q,K);
    else update_x(1,0,n-1,P,Q,K);
}

long long calculate(int P, int Q, int U, int V) {
    if(n<=10&&m<=100000)return query_x2(1,0,n-1,P,Q,U,V);
    return query_x(1,0,n-1,P,Q,U,V);
}

Compilation message (stderr)

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 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...