답안 #1032110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1032110 2024-07-23T11:51:02 Z noyancanturk 게임 (IOI13_game) C++17
80 / 100
1551 ms 256000 KB
#include "game.h"

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;
}

#include<iostream>
struct Nd{
    long long val=0;
    int ch[2]{0,0};
}tree[19800000];
int nx=1;
int L,R;
long long ANS;
int n,m;
int P;
long long VAL;
struct segtree {
    int root;
    void update(int l,int r,int&node){
        if(!node){
            node=nx++;
        }
        if(l==r){
            tree[node].val=VAL;
            return;
        }
        int mid=(l+r)>>1;
        if(P<=mid){
            update(l,mid,tree[node].ch[0]);
        }else{
            update(mid+1,r,tree[node].ch[1]);
        }
        tree[node].val=gcd2(tree[tree[node].ch[0]].val,tree[tree[node].ch[1]].val);
    }
    void update(int p,long long val){
        P=p;
        update(0,m-1,root);
    }
    void insert(int l,int r,int&node,int node1,int node2){
        if(!node){
            node=nx++;
        }
        tree[node].val=gcd2(tree[node1].val,tree[node2].val);
        if(l==r)return;
        int mid=(l+r)>>1;
        if(P<=mid){
            insert(l,mid,tree[node].ch[0],tree[node1].ch[0],tree[node2].ch[0]);
        }else{
            insert(mid+1,r,tree[node].ch[1],tree[node1].ch[1],tree[node2].ch[1]);
        }
    }
    void insert(int p,int node1,int node2){
        P=p;
        insert(0,m-1,root,node1,node2);
    }
    void query(int l,int r,int node){
        if(L<=l&r<=R){
            ANS=gcd2(ANS,tree[node].val);
            return;
        }
        if(r<L||R<l)return;
        int mid=(l+r)>>1;
        if(tree[node].ch[0])query(l,mid,tree[node].ch[0]);
        if(tree[node].ch[1])query(mid+1,r,tree[node].ch[1]);
    }
    void query(int l,int r){
        L=l,R=r;
        query(0,m-1,root);
    }
};

struct {
    struct {
        segtree sst;
        int ch[2]{0,0};
    }subtree[1000000];
    int nxx=1;
    void init(int N,int M){
        n=N,m=M;
    }
    int P1,P2;
    void update(int l,int r,int&node){
        if(!node){
            node=++nxx;
        }
        if(l==r){
            subtree[node].sst.update(P2,VAL);
            return;
        }
        int mid=(l+r)>>1;
        if(P1<=mid){
            update(l,mid,subtree[node].ch[0]);
        }else{
            update(mid+1,r,subtree[node].ch[1]);
        }
        subtree[node].sst.insert(P2,subtree[subtree[node].ch[0]].sst.root,subtree[subtree[node].ch[1]].sst.root);
    }
    void update(int p1,int p2,long long val){
        P1=p1,P2=p2,VAL=val;
        int root=1;
        update(0,n-1,root);
    }
    int L1,R1,L2,R2;
    void query(int l,int r,int node){
        if(L1<=l&&r<=R1){
            subtree[node].sst.query(L2,R2);
            return;
        }
        if(r<L1||R1<l)return;
        int mid=(l+r)>>1;
        if(subtree[node].ch[0])query(l,mid,subtree[node].ch[0]);
        if(subtree[node].ch[1])query(mid+1,r,subtree[node].ch[1]);
    }
    long long query(int l1,int r1,int l2,int r2){
        L1=l1,R1=r1,L2=l2,R2=r2;
        ANS=0;
        query(0,n-1,1);
        return ANS;
    }
}st;

void init(int R, int C) {
    st.init(R,C);
}

void update(int P, int Q, long long K) {
    st.update(P,Q,K);
}

long long calculate(int P, int Q, int U, int V) {
    long long val=st.query(P,U,Q,V);
    return val;
}

Compilation message

game.cpp: In member function 'void segtree::query(int, int, int)':
game.cpp:64:13: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
   64 |         if(L<=l&r<=R){
      |            ~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12124 KB Output is correct
2 Correct 4 ms 12124 KB Output is correct
3 Correct 4 ms 12120 KB Output is correct
4 Correct 4 ms 12124 KB Output is correct
5 Correct 4 ms 12124 KB Output is correct
6 Correct 4 ms 12124 KB Output is correct
7 Correct 4 ms 12124 KB Output is correct
8 Correct 5 ms 12124 KB Output is correct
9 Correct 4 ms 12124 KB Output is correct
10 Correct 4 ms 12124 KB Output is correct
11 Correct 4 ms 12124 KB Output is correct
12 Correct 4 ms 11948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 12124 KB Output is correct
2 Correct 4 ms 12124 KB Output is correct
3 Correct 4 ms 12124 KB Output is correct
4 Correct 307 ms 20156 KB Output is correct
5 Correct 172 ms 20560 KB Output is correct
6 Correct 211 ms 17488 KB Output is correct
7 Correct 237 ms 17220 KB Output is correct
8 Correct 183 ms 16180 KB Output is correct
9 Correct 240 ms 17236 KB Output is correct
10 Correct 214 ms 16868 KB Output is correct
11 Correct 5 ms 12120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 12124 KB Output is correct
2 Correct 5 ms 12124 KB Output is correct
3 Correct 4 ms 12100 KB Output is correct
4 Correct 4 ms 12052 KB Output is correct
5 Correct 5 ms 12052 KB Output is correct
6 Correct 4 ms 12124 KB Output is correct
7 Correct 5 ms 12004 KB Output is correct
8 Correct 4 ms 12140 KB Output is correct
9 Correct 5 ms 12124 KB Output is correct
10 Correct 4 ms 12124 KB Output is correct
11 Correct 5 ms 12124 KB Output is correct
12 Correct 440 ms 21772 KB Output is correct
13 Correct 560 ms 15216 KB Output is correct
14 Correct 154 ms 12624 KB Output is correct
15 Correct 569 ms 16472 KB Output is correct
16 Correct 98 ms 21328 KB Output is correct
17 Correct 370 ms 18260 KB Output is correct
18 Correct 507 ms 21588 KB Output is correct
19 Correct 498 ms 21844 KB Output is correct
20 Correct 467 ms 21268 KB Output is correct
21 Correct 5 ms 12376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 12120 KB Output is correct
2 Correct 7 ms 12124 KB Output is correct
3 Correct 5 ms 12136 KB Output is correct
4 Correct 6 ms 12124 KB Output is correct
5 Correct 5 ms 12124 KB Output is correct
6 Correct 5 ms 12124 KB Output is correct
7 Correct 6 ms 12124 KB Output is correct
8 Correct 5 ms 12152 KB Output is correct
9 Correct 5 ms 12124 KB Output is correct
10 Correct 4 ms 12124 KB Output is correct
11 Correct 4 ms 12124 KB Output is correct
12 Correct 265 ms 20248 KB Output is correct
13 Correct 174 ms 20560 KB Output is correct
14 Correct 223 ms 17332 KB Output is correct
15 Correct 224 ms 16980 KB Output is correct
16 Correct 184 ms 16076 KB Output is correct
17 Correct 232 ms 17236 KB Output is correct
18 Correct 238 ms 17004 KB Output is correct
19 Correct 413 ms 21840 KB Output is correct
20 Correct 540 ms 15188 KB Output is correct
21 Correct 138 ms 12628 KB Output is correct
22 Correct 645 ms 16540 KB Output is correct
23 Correct 101 ms 21332 KB Output is correct
24 Correct 396 ms 18260 KB Output is correct
25 Correct 516 ms 21584 KB Output is correct
26 Correct 497 ms 21892 KB Output is correct
27 Correct 475 ms 21076 KB Output is correct
28 Correct 364 ms 135248 KB Output is correct
29 Correct 718 ms 150352 KB Output is correct
30 Correct 1551 ms 112304 KB Output is correct
31 Correct 1515 ms 88800 KB Output is correct
32 Correct 215 ms 12884 KB Output is correct
33 Correct 313 ms 14128 KB Output is correct
34 Correct 197 ms 147540 KB Output is correct
35 Correct 538 ms 80976 KB Output is correct
36 Correct 913 ms 147848 KB Output is correct
37 Correct 783 ms 147812 KB Output is correct
38 Correct 762 ms 147536 KB Output is correct
39 Correct 615 ms 116308 KB Output is correct
40 Correct 4 ms 12120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 12124 KB Output is correct
2 Correct 5 ms 12124 KB Output is correct
3 Correct 4 ms 12008 KB Output is correct
4 Correct 5 ms 12124 KB Output is correct
5 Correct 5 ms 12124 KB Output is correct
6 Correct 4 ms 12208 KB Output is correct
7 Correct 4 ms 12032 KB Output is correct
8 Correct 4 ms 12124 KB Output is correct
9 Correct 4 ms 12124 KB Output is correct
10 Correct 4 ms 12124 KB Output is correct
11 Correct 5 ms 12124 KB Output is correct
12 Correct 279 ms 20220 KB Output is correct
13 Correct 175 ms 20560 KB Output is correct
14 Correct 242 ms 17488 KB Output is correct
15 Correct 243 ms 16980 KB Output is correct
16 Correct 186 ms 15952 KB Output is correct
17 Correct 234 ms 17236 KB Output is correct
18 Correct 222 ms 16720 KB Output is correct
19 Correct 397 ms 21752 KB Output is correct
20 Correct 534 ms 15320 KB Output is correct
21 Correct 140 ms 12624 KB Output is correct
22 Correct 573 ms 16436 KB Output is correct
23 Correct 100 ms 21336 KB Output is correct
24 Correct 376 ms 18352 KB Output is correct
25 Correct 576 ms 21916 KB Output is correct
26 Correct 498 ms 21880 KB Output is correct
27 Correct 477 ms 21200 KB Output is correct
28 Correct 311 ms 135284 KB Output is correct
29 Correct 763 ms 150412 KB Output is correct
30 Correct 1527 ms 112464 KB Output is correct
31 Correct 1419 ms 88660 KB Output is correct
32 Correct 199 ms 12880 KB Output is correct
33 Correct 308 ms 14140 KB Output is correct
34 Correct 205 ms 147536 KB Output is correct
35 Correct 539 ms 80976 KB Output is correct
36 Correct 846 ms 148060 KB Output is correct
37 Correct 721 ms 147796 KB Output is correct
38 Correct 689 ms 147280 KB Output is correct
39 Runtime error 407 ms 256000 KB Execution killed with signal 9
40 Halted 0 ms 0 KB -