답안 #1031098

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1031098 2024-07-22T14:47:25 Z vjudge1 게임 (IOI13_game) C++17
0 / 100
99 ms 211676 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>
#include<cassert>

struct {
    struct Node{
        long long val=0;
        int ch[4]{0,0,0,0};
    }tree[9000000];
    int nx=1;
    int n,m;
    void init(int N,int M){
        n=N,m=M;
    }
    int P1,P2,VAL;
    int update(int l1,int r1,int l2,int r2,int node){
        //assert(!(l1<r1||l2<r2));
        //std::cerr<<l1<<" "<<r1<<" "<<l2<<" "<<r2<<"\n";
        if(!node)node=++nx;
        if(l1==r1&&l2==r2){
            tree[node].val=VAL;
            return node;
        }
        int mid1=(l1+r1)>>1,mid2=(l2+r2)>>1;
        if(P1<=mid1){
            if(P2<=mid2){
                tree[node].ch[0]=update(l1,mid1,l2,mid2,tree[node].ch[0]);
            }else{
                tree[node].ch[1]=update(l1,mid1,mid2+1,r2,tree[node].ch[1]);
            }
        }else{
            if(P2<=mid2){
                tree[node].ch[3]=update(mid1+1,r1,l2,mid2,tree[node].ch[3]);
            }else{
                tree[node].ch[4]=update(mid1+1,r1,mid2+1,r2,tree[node].ch[4]);
            }
        }
        tree[node].val=0;
        for(int i=0;i<4;i++)tree[node].val=gcd2(tree[node].val,tree[tree[node].ch[i]].val);
        return node;
    }
    void update(int p1,int p2,int val){
        P1=p1,P2=p2,VAL=val;
        update(0,n-1,0,m-1,1);
    }
    int L1,R1,L2,R2;
    long long ANS;
    void query(int l1,int r1,int l2,int r2,int node){
        if(!node)return;
        if(L1<=l1&&r1<=R1&&L2<=l2&&r2<=R2){
            ANS=gcd2(ANS,tree[node].val);
            return;
        }
        if(r1<L1||R1<l1||r2<L2||R2<l2)return;
        int mid1=(l1+r1)>>1,mid2=(l2+r2)>>1;
        query(l1,mid1,l2,mid2,tree[node].ch[0]);
        if(mid2+1<=r2)query(l1,mid1,mid2+1,r2,tree[node].ch[1]);
        if(mid1+1<=r1)query(mid1+1,r1,l2,mid2,tree[node].ch[3]);
        if(mid1+1<=r1&&mid2+1<=r2)query(mid1+1,r1,mid2+1,r2,tree[node].ch[4]);
    }
    int query(int l1,int r1,int l2,int r2){
        L1=l1,R1=r1,L2=l2,R2=r2;
        ANS=0;
        query(0,n-1,0,m-1,1);
        return ANS;
    }
}st;

void init(int R, int C) {
    //std::cerr<<"ok\n";
    st.init(R,C);
    //std::cerr<<"ok1\n";
}

void update(int P, int Q, long long K) {
    //std::cerr<<"up ok\n";
    st.update(P,Q,K);
    //std::cerr<<"up ok1\n";
}

long long calculate(int P, int Q, int U, int V) {
    //std::cerr<<"begun\n";
    long long val=st.query(P,U,Q,V);
    //std::cerr<<"ended\n";
    return val;
}

Compilation message

game.cpp: In function 'int<unnamed struct>::update(int, int, int, int, int)':
game.cpp:46:40: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   46 |                 tree[node].ch[4]=update(mid1+1,r1,mid2+1,r2,tree[node].ch[4]);
      |                                  ~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:19:13: note: while referencing '<unnamed struct>::Node::ch'
   19 |         int ch[4]{0,0,0,0};
      |             ^~
game.cpp:46:32: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   46 |                 tree[node].ch[4]=update(mid1+1,r1,mid2+1,r2,tree[node].ch[4]);
      |                 ~~~~~~~~~~~~~~~^
game.cpp:19:13: note: while referencing '<unnamed struct>::Node::ch'
   19 |         int ch[4]{0,0,0,0};
      |             ^~
game.cpp: In function 'void<unnamed struct>::query(int, int, int, int, int)':
game.cpp:70:40: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   70 |         if(mid1+1<=r1&&mid2+1<=r2)query(mid1+1,r1,mid2+1,r2,tree[node].ch[4]);
      |                                   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:19:13: note: while referencing '<unnamed struct>::Node::ch'
   19 |         int ch[4]{0,0,0,0};
      |             ^~
game.cpp:70:40: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   70 |         if(mid1+1<=r1&&mid2+1<=r2)query(mid1+1,r1,mid2+1,r2,tree[node].ch[4]);
      |                                   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:19:13: note: while referencing '<unnamed struct>::Node::ch'
   19 |         int ch[4]{0,0,0,0};
      |             ^~
game.cpp:70:40: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   70 |         if(mid1+1<=r1&&mid2+1<=r2)query(mid1+1,r1,mid2+1,r2,tree[node].ch[4]);
      |                                   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:19:13: note: while referencing '<unnamed struct>::Node::ch'
   19 |         int ch[4]{0,0,0,0};
      |             ^~
game.cpp:70:40: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   70 |         if(mid1+1<=r1&&mid2+1<=r2)query(mid1+1,r1,mid2+1,r2,tree[node].ch[4]);
      |                                   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:19:13: note: while referencing '<unnamed struct>::Node::ch'
   19 |         int ch[4]{0,0,0,0};
      |             ^~
game.cpp:70:40: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   70 |         if(mid1+1<=r1&&mid2+1<=r2)query(mid1+1,r1,mid2+1,r2,tree[node].ch[4]);
      |                                   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:19:13: note: while referencing '<unnamed struct>::Node::ch'
   19 |         int ch[4]{0,0,0,0};
      |             ^~
game.cpp:70:40: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   70 |         if(mid1+1<=r1&&mid2+1<=r2)query(mid1+1,r1,mid2+1,r2,tree[node].ch[4]);
      |                                   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:19:13: note: while referencing '<unnamed struct>::Node::ch'
   19 |         int ch[4]{0,0,0,0};
      |             ^~
game.cpp: In function 'long long int calculate(int, int, int, int)':
game.cpp:70:40: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   70 |         if(mid1+1<=r1&&mid2+1<=r2)query(mid1+1,r1,mid2+1,r2,tree[node].ch[4]);
      |                                   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:19:13: note: while referencing '<unnamed struct>::Node::ch'
   19 |         int ch[4]{0,0,0,0};
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 96 ms 211640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 99 ms 211540 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 93 ms 211536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 94 ms 211652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 96 ms 211676 KB Output isn't correct
2 Halted 0 ms 0 KB -