답안 #97326

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97326 2019-02-15T06:19:31 Z songc 게임 (IOI13_game) C++14
컴파일 오류
0 ms 0 KB
#include "game.h"
typedef long long LL;

int R, C;

LL GCD(LL A, LL B){
    if (!B) return A;
    return GCD(B, A%B);
}

struct Ynode{
    LL val=0;
    Ynode *lc=NULL, *rc=NULL;

    void update(int s, int e, int t, LL v){
        if (e < t || t < s) return;
        if(s == e){
            val = v;
            return;
        }
        int mid = (s+e)/2;
        if (lc == NULL) lc = new Ynode;
        if (rc == NULL) rc = new Ynode;
        lc->update(s, mid, t, v);
        rc->update(mid+1, e, t, v);
        val = GCD(lc->val, rc->val);
    }

    LL query(int s, int e, int ts, int te){
        if (te < s || e < ts) return 0;
        if (ts <= s && e <= te) return val;
        int mid = (s+e)/2;
        if (lc != NULL) return GCD(lc->query(s, mid, ts, te), rc->query(mid+1, e, ts, te));
        return 0;
    }
};

struct Xnode{
    Ynode *Ytree=NULL;
    Xnode *lc=NULL, *rc=NULL;

    LL update(int s, int e, int xt, int yt, LL v){
        if (e < xt || xt < s) return Ytree->query(0, C-1, yt, yt);
        if(s == e){
            Ytree->update(0, C-1, yt, v);
            return v;
        }
        int mid = (s+e)/2;
        if (lc == NULL){
            lc = new Xnode;
            lc->Ytree = new Ynode;
        }
        if (rc == NULL){
            rc = new Xnode;
            rc->Ytree = new Ynode;
        }
        LL ret = lc->update(s, mid, xt, yt, v);
        ret = GCD(ret, rc->update(mid+1, e, xt, yt, v));
        Ytree->update(0, C-1, yt, ret);
        return ret;
    }

    LL query(int s, int e, int xts, int xte, int yts, int yte){
        if (xte < s || e < xts) return 0;
        if (xts <= s && e <= xte) return Ytree->query(0, C-1, yts, yte);
        int mid = (s+e)/2;
        if (lc != NULL) return GCD(lc->query(s, mid, xts, xte, yts, yte), rc->query(mid+1, e, xts, xte, yts, yte));
        return 0;
    }
} *Xtree;

void init(int r, int c){
    R = r, C = c;
    Xtree = new Xnode;
    Xtree->Ytree = new Ynode;
}

void update(int x, int y, LL k){
    Xtree->update(0, R-1, x, y, k);
}

LL calculate(int x1, int y1, int x2, int y2){
    return Xtree->query(0, R-1, x1, x2, y1, y2);
}

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:13:15: error: 'NULL' was not declared in this scope
     Ynode *lc=NULL, *rc=NULL;
               ^~~~
game.cpp:13:15: note: suggested alternative: 'LL'
     Ynode *lc=NULL, *rc=NULL;
               ^~~~
               LL
game.cpp:13:25: error: 'NULL' was not declared in this scope
     Ynode *lc=NULL, *rc=NULL;
                         ^~~~
game.cpp:13:25: note: suggested alternative: 'LL'
     Ynode *lc=NULL, *rc=NULL;
                         ^~~~
                         LL
game.cpp: In member function 'void Ynode::update(int, int, int, LL)':
game.cpp:22:19: error: 'NULL' was not declared in this scope
         if (lc == NULL) lc = new Ynode;
                   ^~~~
game.cpp:22:19: note: suggested alternative: 'LL'
         if (lc == NULL) lc = new Ynode;
                   ^~~~
                   LL
game.cpp:23:19: error: 'NULL' was not declared in this scope
         if (rc == NULL) rc = new Ynode;
                   ^~~~
game.cpp:23:19: note: suggested alternative: 'LL'
         if (rc == NULL) rc = new Ynode;
                   ^~~~
                   LL
game.cpp: In member function 'LL Ynode::query(int, int, int, int)':
game.cpp:33:19: error: 'NULL' was not declared in this scope
         if (lc != NULL) return GCD(lc->query(s, mid, ts, te), rc->query(mid+1, e, ts, te));
                   ^~~~
game.cpp:33:19: note: suggested alternative: 'LL'
         if (lc != NULL) return GCD(lc->query(s, mid, ts, te), rc->query(mid+1, e, ts, te));
                   ^~~~
                   LL
game.cpp: At global scope:
game.cpp:39:18: error: 'NULL' was not declared in this scope
     Ynode *Ytree=NULL;
                  ^~~~
game.cpp:39:18: note: suggested alternative: 'LL'
     Ynode *Ytree=NULL;
                  ^~~~
                  LL
game.cpp:40:15: error: 'NULL' was not declared in this scope
     Xnode *lc=NULL, *rc=NULL;
               ^~~~
game.cpp:40:15: note: suggested alternative: 'LL'
     Xnode *lc=NULL, *rc=NULL;
               ^~~~
               LL
game.cpp:40:25: error: 'NULL' was not declared in this scope
     Xnode *lc=NULL, *rc=NULL;
                         ^~~~
game.cpp:40:25: note: suggested alternative: 'LL'
     Xnode *lc=NULL, *rc=NULL;
                         ^~~~
                         LL
game.cpp: In member function 'LL Xnode::update(int, int, int, int, LL)':
game.cpp:49:19: error: 'NULL' was not declared in this scope
         if (lc == NULL){
                   ^~~~
game.cpp:49:19: note: suggested alternative: 'LL'
         if (lc == NULL){
                   ^~~~
                   LL
game.cpp:53:19: error: 'NULL' was not declared in this scope
         if (rc == NULL){
                   ^~~~
game.cpp:53:19: note: suggested alternative: 'LL'
         if (rc == NULL){
                   ^~~~
                   LL
game.cpp: In member function 'LL Xnode::query(int, int, int, int, int, int)':
game.cpp:67:19: error: 'NULL' was not declared in this scope
         if (lc != NULL) return GCD(lc->query(s, mid, xts, xte, yts, yte), rc->query(mid+1, e, xts, xte, yts, yte));
                   ^~~~
game.cpp:67:19: note: suggested alternative: 'LL'
         if (lc != NULL) return GCD(lc->query(s, mid, xts, xte, yts, yte), rc->query(mid+1, e, xts, xte, yts, yte));
                   ^~~~
                   LL