Submission #1031088

# Submission time Handle Problem Language Result Execution time Memory
1031088 2024-07-22T14:42:00 Z vjudge1 Game (IOI13_game) C++17
0 / 100
94 ms 211736 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;
        }
        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) {
    return st.query(P,U,Q,V);
}

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:69:40: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   69 |         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:69:40: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   69 |         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:69:40: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   69 |         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:69:40: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   69 |         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:69:40: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   69 |         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:69:40: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   69 |         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:69:40: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   69 |         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:69:40: warning: array subscript 4 is above array bounds of 'int [4]' [-Warray-bounds]
   69 |         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};
      |             ^~
# Verdict Execution time Memory Grader output
1 Incorrect 87 ms 211536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 211680 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 94 ms 211712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 211536 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 91 ms 211736 KB Output isn't correct
2 Halted 0 ms 0 KB -