답안 #218665

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
218665 2020-04-02T13:27:37 Z urd05 게임 (IOI13_game) C++14
80 / 100
4082 ms 256000 KB
#include <bits/stdc++.h>
#include "game.h"
using namespace std;
 
typedef pair<int,int> P;
typedef pair<int,P> iP;
typedef pair<P,P> PP;
int r,c;
const int siz=1<<30;
 
long long gcd(long long a,long long b) {
    if (b==0) {
        return a;
    }
    return gcd(b,a%b);
}
 
struct Node {
    long long val;
    int lr;
};

Node seg[19500000];
int s=0;
int sz=0;
const long long INF=2e18;
int root[680000];
    void init0(int node) {
        root[node]=sz;
        seg[sz++]={2*INF,-1};
    }
    void update0(int y,long long v,int node,int nodel=0,int noder=c-1) {
        if (nodel==noder) {
            seg[node].val=(seg[node].val/INF)*INF+v;
            return;
        }
        int mid=(nodel+noder)/2;
        if (y<=mid) {
            if (seg[node].val/INF==0) {
                update0(y,v,node+1,nodel,mid);
            }
            if (seg[node].val/INF==1) {
                if (seg[node].lr==-1) {
                    seg[node].lr=sz;
                    seg[sz++]={2*INF,-1};
                }
                update0(y,v,seg[node].lr,nodel,mid);
            }
            if (seg[node].val/INF==2) {
                seg[node].val-=2*INF;
                seg[sz++]={2*INF,-1};
                update0(y,v,node+1,nodel,mid);
            }
        }
        else {
            if (seg[node].val/INF==0) {
                if (seg[node].lr==-1) {
                    seg[node].lr=sz;
                    seg[sz++]={2*INF,-1};
                }
                update0(y,v,seg[node].lr,mid+1,noder);
            }
            if (seg[node].val/INF==1) {
                update0(y,v,node+1,mid+1,noder);
            }
            if (seg[node].val/INF==2) {
                seg[node].val-=INF;
                seg[sz++]={2*INF,-1};
                update0(y,v,node+1,mid+1,noder);
            }
        }
        long long x=0;
        if (seg[node].val/INF==0) {
            x=gcd(x,seg[node+1].val%INF);
        }
        else if (seg[node].lr!=-1) {
            x=gcd(x,seg[seg[node].lr].val%INF);
        }
        if (seg[node].val/INF==1) {
            x=gcd(x,seg[node+1].val%INF);
        }
        else if (seg[node].lr!=-1) {
            x=gcd(x,seg[seg[node].lr].val%INF);
        }
        seg[node].val=(seg[node].val/INF)*INF+x;
    }
    long long sum0(int l,int r,int node,int nodel=0,int noder=c-1) {
        if (r<nodel||l>noder) {
            return 0;
        }
        if (l<=nodel&&noder<=r) {
            //printf("   %lld\n",seg[node].val);
            return seg[node].val%INF;
        }
        long long ret=0;
        int mid=(nodel+noder)/2;
        if (seg[node].val/INF==0) {
            ret=gcd(sum0(l,r,node+1,nodel,mid),ret);
        }
        else if (seg[node].lr!=-1) {
            ret=gcd(sum0(l,r,seg[node].lr,nodel,mid),ret);
        }
        if (seg[node].val/INF==1) {
            ret=gcd(sum0(l,r,node+1,mid+1,noder),ret);
        }
        else if (seg[node].lr!=-1) {
            ret=gcd(sum0(l,r,seg[node].lr,mid+1,noder),ret);
        }
        //printf("%lld\n",ret);
        return ret;
    }
const int I=1e6;
int arr[680000];

    void init2() {
        arr[s++]=3*I-1;
    }
    void update2(int x,int y,long long v,int node=0,int nodel=0,int noder=r-1) {
        if (nodel==noder) {
            if (root[node]==-1) {
                init0(node);
            }
            update0(y,v,root[node]);
            return;
        }
        int mid=(nodel+noder)/2;
        if (x<=mid) {
            if (arr[node]/I==0) {
                update2(x,y,v,node+1,nodel,mid);
            }
            if (arr[node]/I==1) {
                if (arr[node]%I==I-1) {
                    arr[node]=(arr[node]/I)*I+s;
                    arr[s++]=3*I-1;
                }
                update2(x,y,v,arr[node]%I,nodel,mid);
            }
            if (arr[node]/I==2) {
                arr[node]-=2*I;
                arr[s++]=3*I-1;
                update2(x,y,v,node+1,nodel,mid);
            }
        }
        else {
            if (arr[node]/I==0) {
                if (arr[node]%I==I-1) {
                    arr[node]=(arr[node]/I)*I+s;
                    arr[s++]=3*I-1;
                }
                update2(x,y,v,arr[node]%I,mid+1,noder);
            }
            if (arr[node]/I==1) {
                update2(x,y,v,node+1,mid+1,noder);
            }
            if (arr[node]/I==2) {
                arr[node]-=I;
                arr[s++]=3*I-1;
                update2(x,y,v,node+1,mid+1,noder);
            }
        }
        long long val=0;
        if (arr[node]/I==0) {
            val=gcd(sum0(y,y,root[node+1]),val);
        }
        else if (arr[node]%I!=I-1) {
            val=gcd(sum0(y,y,root[arr[node]%I]),val);
        }
        if (arr[node]/I==1) {
            val=gcd(sum0(y,y,root[node+1]),val);
        }
        else if (arr[node]%I!=I-1) {
            val=gcd(sum0(y,y,root[arr[node]%I]),val);
        }
        if (root[node]==-1) {
            init0(node);
        }
        update0(y,val,root[node]);
    }
    long long sum2(int xl,int xr,int yl,int yr,int node=0,int nodel=0,int noder=r-1) {
        if (xr<nodel||xl>noder) {
            return 0;
        }
        if (xl<=nodel&&noder<=xr) {
            return sum0(yl,yr,root[node]);
        }
        int mid=(nodel+noder)/2;
        long long ret=0;
        if (arr[node]/I==0) {
            ret=gcd(ret,sum2(xl,xr,yl,yr,node+1,nodel,mid));
        }
        else if (arr[node]%I!=I-1) {
            ret=gcd(ret,sum2(xl,xr,yl,yr,arr[node]%I,nodel,mid));
        }
        if (arr[node]/I==1) {
            ret=gcd(ret,sum2(xl,xr,yl,yr,node+1,mid+1,noder));
        }
        else if (arr[node]%I!=I-1) {
            ret=gcd(ret,sum2(xl,xr,yl,yr,arr[node]%I,mid+1,noder));
        }
        return ret;
    }
 
void init(int x,int y) {
    r=x;
    c=y;
    init2();
    memset(root,-1,sizeof(root));
}
 
void update(int p,int q,long long k) {
    update2(p,q,k);
}
 
long long calculate(int p,int q,int u,int v) {
    return sum2(p,u,q,v);
}

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 6 ms 2944 KB Output is correct
2 Correct 6 ms 3072 KB Output is correct
3 Correct 6 ms 3072 KB Output is correct
4 Correct 6 ms 2944 KB Output is correct
5 Correct 6 ms 2944 KB Output is correct
6 Correct 6 ms 3072 KB Output is correct
7 Correct 6 ms 2944 KB Output is correct
8 Correct 6 ms 3072 KB Output is correct
9 Correct 6 ms 3072 KB Output is correct
10 Correct 6 ms 3072 KB Output is correct
11 Correct 6 ms 3072 KB Output is correct
12 Correct 6 ms 2816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2944 KB Output is correct
2 Correct 5 ms 2944 KB Output is correct
3 Correct 6 ms 2944 KB Output is correct
4 Correct 690 ms 11364 KB Output is correct
5 Correct 485 ms 15564 KB Output is correct
6 Correct 565 ms 13048 KB Output is correct
7 Correct 587 ms 12792 KB Output is correct
8 Correct 432 ms 11388 KB Output is correct
9 Correct 600 ms 13304 KB Output is correct
10 Correct 540 ms 12408 KB Output is correct
11 Correct 6 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2944 KB Output is correct
2 Correct 6 ms 3072 KB Output is correct
3 Correct 6 ms 3072 KB Output is correct
4 Correct 6 ms 2944 KB Output is correct
5 Correct 6 ms 2944 KB Output is correct
6 Correct 6 ms 3072 KB Output is correct
7 Correct 6 ms 2944 KB Output is correct
8 Correct 6 ms 2944 KB Output is correct
9 Correct 6 ms 3072 KB Output is correct
10 Correct 6 ms 3072 KB Output is correct
11 Correct 6 ms 2944 KB Output is correct
12 Correct 1108 ms 17144 KB Output is correct
13 Correct 1707 ms 10360 KB Output is correct
14 Correct 350 ms 8312 KB Output is correct
15 Correct 1952 ms 12112 KB Output is correct
16 Correct 278 ms 16504 KB Output is correct
17 Correct 898 ms 14200 KB Output is correct
18 Correct 1383 ms 17912 KB Output is correct
19 Correct 1244 ms 18172 KB Output is correct
20 Correct 1159 ms 17656 KB Output is correct
21 Correct 6 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2944 KB Output is correct
2 Correct 6 ms 3072 KB Output is correct
3 Correct 7 ms 3072 KB Output is correct
4 Correct 6 ms 2944 KB Output is correct
5 Correct 6 ms 2944 KB Output is correct
6 Correct 6 ms 3072 KB Output is correct
7 Correct 6 ms 2944 KB Output is correct
8 Correct 6 ms 2944 KB Output is correct
9 Correct 6 ms 3072 KB Output is correct
10 Correct 6 ms 3072 KB Output is correct
11 Correct 6 ms 2944 KB Output is correct
12 Correct 675 ms 15736 KB Output is correct
13 Correct 485 ms 15608 KB Output is correct
14 Correct 565 ms 12920 KB Output is correct
15 Correct 601 ms 12664 KB Output is correct
16 Correct 442 ms 11256 KB Output is correct
17 Correct 586 ms 12792 KB Output is correct
18 Correct 543 ms 12408 KB Output is correct
19 Correct 1117 ms 16888 KB Output is correct
20 Correct 1728 ms 10488 KB Output is correct
21 Correct 348 ms 8312 KB Output is correct
22 Correct 1976 ms 12072 KB Output is correct
23 Correct 275 ms 16632 KB Output is correct
24 Correct 889 ms 14072 KB Output is correct
25 Correct 1392 ms 18036 KB Output is correct
26 Correct 1230 ms 18296 KB Output is correct
27 Correct 1146 ms 17600 KB Output is correct
28 Correct 769 ms 137464 KB Output is correct
29 Correct 1905 ms 152216 KB Output is correct
30 Correct 4033 ms 110908 KB Output is correct
31 Correct 3763 ms 87180 KB Output is correct
32 Correct 644 ms 13048 KB Output is correct
33 Correct 825 ms 14352 KB Output is correct
34 Correct 562 ms 145912 KB Output is correct
35 Correct 1331 ms 82168 KB Output is correct
36 Correct 2388 ms 150264 KB Output is correct
37 Correct 2011 ms 150392 KB Output is correct
38 Correct 1994 ms 149752 KB Output is correct
39 Correct 1716 ms 118520 KB Output is correct
40 Correct 6 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 2944 KB Output is correct
2 Correct 6 ms 3072 KB Output is correct
3 Correct 6 ms 3072 KB Output is correct
4 Correct 6 ms 3072 KB Output is correct
5 Correct 7 ms 3072 KB Output is correct
6 Correct 6 ms 3072 KB Output is correct
7 Correct 6 ms 2944 KB Output is correct
8 Correct 6 ms 2944 KB Output is correct
9 Correct 6 ms 3072 KB Output is correct
10 Correct 6 ms 3072 KB Output is correct
11 Correct 6 ms 2944 KB Output is correct
12 Correct 675 ms 15736 KB Output is correct
13 Correct 494 ms 15480 KB Output is correct
14 Correct 547 ms 12988 KB Output is correct
15 Correct 597 ms 12792 KB Output is correct
16 Correct 432 ms 11384 KB Output is correct
17 Correct 581 ms 12796 KB Output is correct
18 Correct 546 ms 12536 KB Output is correct
19 Correct 1079 ms 16888 KB Output is correct
20 Correct 1721 ms 10172 KB Output is correct
21 Correct 361 ms 8628 KB Output is correct
22 Correct 1978 ms 12152 KB Output is correct
23 Correct 262 ms 16504 KB Output is correct
24 Correct 884 ms 14200 KB Output is correct
25 Correct 1372 ms 18040 KB Output is correct
26 Correct 1230 ms 18160 KB Output is correct
27 Correct 1164 ms 17660 KB Output is correct
28 Correct 800 ms 137576 KB Output is correct
29 Correct 1974 ms 152104 KB Output is correct
30 Correct 4082 ms 111136 KB Output is correct
31 Correct 3756 ms 87032 KB Output is correct
32 Correct 653 ms 12920 KB Output is correct
33 Correct 838 ms 14200 KB Output is correct
34 Correct 546 ms 145912 KB Output is correct
35 Correct 1352 ms 82168 KB Output is correct
36 Correct 2500 ms 150100 KB Output is correct
37 Correct 2146 ms 150392 KB Output is correct
38 Correct 2107 ms 149720 KB Output is correct
39 Runtime error 1163 ms 256000 KB Execution killed with signal 9 (could be triggered by violating memory limits)
40 Halted 0 ms 0 KB -