답안 #159639

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
159639 2019-10-23T16:20:02 Z mhy908 게임 (IOI13_game) C++14
100 / 100
11536 ms 73440 KB
#include "game.h"
#include <bits/stdc++.h>
const int MAXR=10+1e9;
using namespace std;
typedef long long LL;
LL gcd(LL a, LL b){return b?gcd(b, a%b):a;}
struct SEGMENT_TREE
{
    struct NODE{
        NODE *l, *r;
        LL p, lazy;
        int st, fin, num;
        NODE(int s, int e) : st(s), fin(e), l(NULL), r(NULL), num(0), p(0), lazy(0) {}
    }*root;
    SEGMENT_TREE(){root=new NODE(1, MAXR);}
    void update(NODE* here, int num, LL in){
        //printf("INY %d %d\n", here->st, here->fin);
        if(here->st==here->fin){
            here->num=num;
            here->lazy=in;
            here->p=in;
            //printf("INLAZY : %d %lld\n", here->num, here->lazy);
            return;
        }
        int mid=(here->st+here->fin)/2;
        if(here->num<=0){
            here->num=num;
            here->lazy=in;
            //printf("INLAZY : %d %lld\n", here->num, here->lazy);
        }
        else if(num==here->num)here->lazy=in;
        else if(mid>=num){
            if(here->l==NULL)here->l=new NODE(here->st, mid);
            update(here->l, num, in);
        }
        else{
            if(here->r==NULL)here->r=new NODE(mid+1, here->fin);
            update(here->r, num, in);
        }
        LL ll=here->l==nullptr?0:here->l->p;
        LL rr=here->r==nullptr?0:here->r->p;
        here->p=gcd(gcd(ll, rr), here->lazy);
        //printf("Point : %d %d -> %lld\n", here->st, here->fin, here->p);
    }
    LL query(NODE* here, int st, int fin){
        if(here->p==0)return 0;
        if(here->st>=st&&here->fin<=fin)return here->p;
        if(here->st>fin||here->fin<st)return 0;
        LL ll=here->l==nullptr?0:query(here->l, st, fin);
        LL rr=here->r==nullptr?0:query(here->r, st, fin);
        if(here->num>=st&&here->num<=fin)return gcd(gcd(ll, rr), here->lazy);
        else return gcd(ll, rr);
    }
    /*void update(NODE* here, int num, LL in){
        //printf("INY %d %d\n", here->st, here->fin);
        if(here->st==here->fin){
            here->p=in;
            return;
        }
        int mid=(here->st+here->fin)/2;
        if(mid>=num){
            if(here->l==NULL)here->l=new NODE(here->st, mid);
            update(here->l, num, in);
        }
        else{
            if(here->r==NULL)here->r=new NODE(mid+1, here->fin);
            update(here->r, num, in);
        }
        LL ll=here->l==nullptr?0:here->l->p;
        LL rr=here->r==nullptr?0:here->r->p;
        here->p=gcd(ll, rr);
    }
    LL query(NODE* here, int st, int fin){
        if(here->st>=st&&here->fin<=fin)return here->p;
        if(here->st>fin||here->fin<st)return 0;
        LL ll=here->l==nullptr?0:query(here->l, st, fin);
        LL rr=here->r==nullptr?0:query(here->r, st, fin);
        return gcd(ll, rr);
    }*/
    void update(int num, LL in){update(root, num, in);}
    LL query(int st, int fin){return query(root, st, fin);}
};
struct TWOSEG
{
    struct NODE{
        NODE *l, *r;
        SEGMENT_TREE seg;
        int st, fin;
        NODE(int s, int e) : st(s), fin(e), l(NULL), r(NULL), seg(){}
    }*root;
    TWOSEG(){root=new NODE(1, MAXR);}
    void update(NODE* here, int numx, int numy, LL in){
        //printf("INX : %d %d : %d %lld\n", here->st, here->fin, numy, in);
        if(here->st==here->fin){
            here->seg.update(numy, in);
            return;
        }
        int mid=(here->st+here->fin)/2;
        if(mid>=numx){
            if(here->l==NULL)here->l=new NODE(here->st, mid);
            update(here->l, numx, numy, in);
        }
        else{
            if(here->r==NULL)here->r=new NODE(mid+1, here->fin);
            update(here->r, numx, numy, in);
        }
        LL ll=here->l==NULL?0:here->l->seg.query(numy, numy);
        LL rr=here->r==NULL?0:here->r->seg.query(numy, numy);
        here->seg.update(numy, gcd(ll, rr));
    }
    LL query(NODE* here, int stx, int finx, int sty, int finy){
        if(here->st>=stx&&here->fin<=finx)return here->seg.query(sty, finy);
        if(here->st>finx||here->fin<stx)return 0;
        LL ll=(here->l==nullptr?0:query(here->l, stx, finx, sty, finy));
        LL rr=(here->r==nullptr?0:query(here->r, stx, finx, sty, finy));
        return gcd(ll, rr);
    }
    void update(int numx, int numy, LL in){update(root, numx, numy, in);}
    LL query(int stx, int finx, int sty, int finy){return query(root, stx, finx, sty, finy);}
}tseg;
void init(int r, int c){}
void update(int p, int q, LL k){
    tseg.update(p+1, q+1, k);
    //puts("=====");
}
LL calculate(int p, int u, int q, int v){
    return tseg.query(p+1, q+1, u+1, v+1);
}

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;
      ^~~
game.cpp: In constructor 'SEGMENT_TREE::NODE::NODE(int, int)':
game.cpp:12:17: warning: 'SEGMENT_TREE::NODE::fin' will be initialized after [-Wreorder]
         int st, fin, num;
                 ^~~
game.cpp:10:15: warning:   'SEGMENT_TREE::NODE* SEGMENT_TREE::NODE::l' [-Wreorder]
         NODE *l, *r;
               ^
game.cpp:13:9: warning:   when initialized here [-Wreorder]
         NODE(int s, int e) : st(s), fin(e), l(NULL), r(NULL), num(0), p(0), lazy(0) {}
         ^~~~
game.cpp:12:22: warning: 'SEGMENT_TREE::NODE::num' will be initialized after [-Wreorder]
         int st, fin, num;
                      ^~~
game.cpp:11:12: warning:   'LL SEGMENT_TREE::NODE::p' [-Wreorder]
         LL p, lazy;
            ^
game.cpp:13:9: warning:   when initialized here [-Wreorder]
         NODE(int s, int e) : st(s), fin(e), l(NULL), r(NULL), num(0), p(0), lazy(0) {}
         ^~~~
game.cpp: In constructor 'TWOSEG::NODE::NODE(int, int)':
game.cpp:88:17: warning: 'TWOSEG::NODE::fin' will be initialized after [-Wreorder]
         int st, fin;
                 ^~~
game.cpp:86:15: warning:   'TWOSEG::NODE* TWOSEG::NODE::l' [-Wreorder]
         NODE *l, *r;
               ^
game.cpp:89:9: warning:   when initialized here [-Wreorder]
         NODE(int s, int e) : st(s), fin(e), l(NULL), r(NULL), seg(){}
         ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 2 ms 380 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 252 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 4 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 1856 ms 27092 KB Output is correct
5 Correct 1478 ms 27128 KB Output is correct
6 Correct 1801 ms 23496 KB Output is correct
7 Correct 1990 ms 23456 KB Output is correct
8 Correct 1096 ms 15404 KB Output is correct
9 Correct 1850 ms 23376 KB Output is correct
10 Correct 1894 ms 23064 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 5 ms 504 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 4 ms 376 KB Output is correct
12 Correct 3335 ms 14748 KB Output is correct
13 Correct 5359 ms 9016 KB Output is correct
14 Correct 766 ms 4640 KB Output is correct
15 Correct 5910 ms 10024 KB Output is correct
16 Correct 1659 ms 13620 KB Output is correct
17 Correct 2297 ms 7740 KB Output is correct
18 Correct 4072 ms 10732 KB Output is correct
19 Correct 3542 ms 10924 KB Output is correct
20 Correct 3591 ms 10244 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 252 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 5 ms 504 KB Output is correct
10 Correct 3 ms 376 KB Output is correct
11 Correct 4 ms 376 KB Output is correct
12 Correct 1859 ms 24128 KB Output is correct
13 Correct 1458 ms 26052 KB Output is correct
14 Correct 1775 ms 20468 KB Output is correct
15 Correct 1975 ms 20356 KB Output is correct
16 Correct 1098 ms 14060 KB Output is correct
17 Correct 1859 ms 20236 KB Output is correct
18 Correct 1867 ms 19872 KB Output is correct
19 Correct 3502 ms 13460 KB Output is correct
20 Correct 5386 ms 8216 KB Output is correct
21 Correct 770 ms 1432 KB Output is correct
22 Correct 5990 ms 7488 KB Output is correct
23 Correct 1709 ms 12668 KB Output is correct
24 Correct 2413 ms 7628 KB Output is correct
25 Correct 4458 ms 10644 KB Output is correct
26 Correct 3506 ms 10600 KB Output is correct
27 Correct 3715 ms 10116 KB Output is correct
28 Correct 897 ms 39248 KB Output is correct
29 Correct 2564 ms 41900 KB Output is correct
30 Correct 8298 ms 29972 KB Output is correct
31 Correct 6794 ms 24672 KB Output is correct
32 Correct 641 ms 10392 KB Output is correct
33 Correct 1061 ms 10640 KB Output is correct
34 Correct 2384 ms 35600 KB Output is correct
35 Correct 1736 ms 25532 KB Output is correct
36 Correct 3057 ms 39764 KB Output is correct
37 Correct 2503 ms 39836 KB Output is correct
38 Correct 2678 ms 39376 KB Output is correct
39 Correct 2129 ms 33320 KB Output is correct
40 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 3 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 6 ms 476 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 4 ms 376 KB Output is correct
12 Correct 1835 ms 24120 KB Output is correct
13 Correct 1510 ms 25984 KB Output is correct
14 Correct 1897 ms 20512 KB Output is correct
15 Correct 1917 ms 20356 KB Output is correct
16 Correct 1099 ms 14020 KB Output is correct
17 Correct 1830 ms 20128 KB Output is correct
18 Correct 1862 ms 19780 KB Output is correct
19 Correct 3353 ms 13488 KB Output is correct
20 Correct 5337 ms 8068 KB Output is correct
21 Correct 771 ms 1460 KB Output is correct
22 Correct 6015 ms 7580 KB Output is correct
23 Correct 1721 ms 12620 KB Output is correct
24 Correct 2403 ms 7548 KB Output is correct
25 Correct 4014 ms 10432 KB Output is correct
26 Correct 3497 ms 10648 KB Output is correct
27 Correct 3432 ms 10092 KB Output is correct
28 Correct 862 ms 39156 KB Output is correct
29 Correct 2519 ms 41768 KB Output is correct
30 Correct 8367 ms 30052 KB Output is correct
31 Correct 6876 ms 24832 KB Output is correct
32 Correct 639 ms 10444 KB Output is correct
33 Correct 1048 ms 10716 KB Output is correct
34 Correct 2387 ms 35576 KB Output is correct
35 Correct 1752 ms 25336 KB Output is correct
36 Correct 2920 ms 39820 KB Output is correct
37 Correct 2564 ms 39940 KB Output is correct
38 Correct 2734 ms 39348 KB Output is correct
39 Correct 1180 ms 71304 KB Output is correct
40 Correct 4019 ms 73440 KB Output is correct
41 Correct 11536 ms 55444 KB Output is correct
42 Correct 9174 ms 43772 KB Output is correct
43 Correct 3177 ms 68232 KB Output is correct
44 Correct 1006 ms 10688 KB Output is correct
45 Correct 2150 ms 33036 KB Output is correct
46 Correct 3862 ms 72196 KB Output is correct
47 Correct 4034 ms 72220 KB Output is correct
48 Correct 4365 ms 71848 KB Output is correct
49 Correct 2 ms 380 KB Output is correct