답안 #1090836

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1090836 2024-09-18T21:37:24 Z vjudge1 게임 (IOI13_game) C++17
0 / 100
165 ms 256000 KB
#include <bits/stdc++.h>
#include "game.h"
using namespace std;
int n,m;
struct xnod
{
    xnod(int tl,int tr):tl(tl),tr(tr),l(NULL),r(NULL),value(0LL){}
    xnod *l,*r;
    int tl,tr;
    long long int value;
};
struct ynod
{
    ynod():l(NULL),r(NULL),xst(0,n-1){}
    ynod *l,*r;
    xnod xst;
};
ynod *root;
void init(int R,int C)
{
    n=R;
    m=C;
    root=new ynod();
}
void updatex(xnod *nod,int vx,long long int k)
{
    int l=nod->tl,r=nod->tr,m=(l+r)/2;;
    if(l==r)
    {
        nod->value=k;
        return;
    }
    xnod **koce=&(vx<=m?nod->l:nod->r);
    if(*koce==NULL)
    {
        *koce=new xnod(vx,vx);
        (*koce)->value=k;
    }
    else if((*koce)->tl<=vx&&vx<=(*koce)->tr)updatex(*koce,vx,k);
    else
    {
        do
        {
            if(vx<=m)
            {
                r=m;
            }
            else
            {
                l=m+1;
            }
            m=(l+r)/2;
        }while((vx<=m)==((*koce)->tr<=m));
        xnod *temp=new xnod(l,r);
        if((*koce)->tr<=m)temp->l=*koce;
        else{temp->r=*koce;}
        *koce=temp;
        updatex(*koce,vx,k);
    }
    nod->value=gcd(nod->l?nod->l->value:0,nod->r?nod->r->value:0);
}
long long int queryx(xnod *nod,int vxl,int vxr)
{
    if(nod==NULL||nod->tl>vxr||nod->tr<vxl)
    {
        return 0;
    }
    if(vxl<=nod->tl&&nod->tr<=vxr)
    {
        return nod->value;
    }
    return gcd(queryx(nod->l,vxl,vxr),queryx(nod->r,vxl,vxr));
}
long long int queryy(ynod *nod,int vyl,int vyr,int vxl,int vxr,int tl,int tr)
{
    if(nod==NULL||tl>vyr||tr<vyl)return 0;
    if(vyl<=tl&&tr<=vyr)
    {
        return queryx(&nod->xst,vxl,vxr);
    }
    int m=(tl+tr)/2;
    return gcd(queryy(nod->l,vyl,vyr,vxl,vxr,tl,m),queryy(nod->r,vyl,vyr,vxl,vxr,m+1,tr));
}
void updatey(ynod *nod,int vx,int vy,long long int k,int tl,int tr)
{
    if(tl==tr)
    {
        updatex(&nod->xst,vx,k);
    }
    int m=(tl+tr)/2;
    if(vy<=m)
    {
        if(nod->l==NULL)nod->l=new ynod();
        updatey(nod->l,vx,vy,k,tl,m);
    }
    else
    {
        if(nod->r==NULL)nod->r=new ynod();
        updatey(nod->l,vx,vy,k,m+1,tr);
    }
    long long int k1=gcd(nod->l?queryx(&nod->l->xst,vx,vx):0,nod->l?queryx(&nod->r->xst,vx,vx):0);
    updatex(&nod->xst,vy,k1);
}
long long int calculate(int r1,int r2,int c1,int c2)
{
    return queryy(root,r2,c2,r1,c1,0,m-1);
}
void update(int R,int C,long long int k)
{
      updatey(root,R,C,k,0,m-1);
}

Compilation message

game.cpp: In constructor 'xnod::xnod(int, int)':
game.cpp:9:12: warning: 'xnod::tr' will be initialized after [-Wreorder]
    9 |     int tl,tr;
      |            ^~
game.cpp:8:11: warning:   'xnod* xnod::l' [-Wreorder]
    8 |     xnod *l,*r;
      |           ^
game.cpp:7:5: warning:   when initialized here [-Wreorder]
    7 |     xnod(int tl,int tr):tl(tl),tr(tr),l(NULL),r(NULL),value(0LL){}
      |     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Runtime error 144 ms 256000 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 153 ms 256000 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 165 ms 256000 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 153 ms 256000 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 161 ms 256000 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -