답안 #97324

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
97324 2019-02-15T06:08:51 Z songc 게임 (IOI13_game) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
 
int R, C, Q;
int q[303030], X1[303030], Y1[303030], X2[303030], Y2[303030];
LL K[303030];
map<int, int> xcomp, ycomp;
 
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(1, C, yt, yt);
        if(s == e){
            Ytree->update(1, C, 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(1, C, 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(1, C, 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;
    }
};
 
int main(){
    int a, x1, y1, x2, y2;
    LL k;
    scanf("%d %d %d", &R, &C, &Q);
    Xnode *Xtree = new Xnode;
    Xtree->Ytree = new Ynode;
    for (int i=1; i<=Q; i++){
        scanf("%d", &a);
        q[i] = a;
        if (a == 1){
            scanf("%d %d %lld", &x1, &y1, &k);
            xcomp[x1], ycomp[y1];
            X1[i] = x1, Y1[i] = y1;
            K[i] = k;
        }
        else{
            scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
            xcomp[x1], ycomp[y1];
            xcomp[x2], ycomp[y2];
            X1[i] = x1, Y1[i] = y1;
            X2[i] = x2, Y2[i] = y2;
        }
    }
    int num = 1;
    for (pii it : xcomp) xcomp[it.first] = num++;
    num = 1;
    for (pii it : ycomp) ycomp[it.first] = num++;
    R = xcomp.size(); C = ycomp.size();
    for (int i=1; i<=Q; i++){
        if (q[i] == 1) Xtree->update(1, R, xcomp[X1[i]], ycomp[Y1[i]], K[i]);
        else printf("%lld\n", Xtree->query(1, R, xcomp[X1[i]], xcomp[X2[i]], ycomp[Y1[i]], ycomp[Y2[i]]));
    }
    return 0;
}

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: In function 'int main()':
game.cpp:80:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &R, &C, &Q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:84:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a);
         ~~~~~^~~~~~~~~~
game.cpp:87:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d %lld", &x1, &y1, &k);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:93:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/tmp/ccmEWGte.o: In function `main':
game.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/cct1JY9i.o:grader.c:(.text.startup+0x0): first defined here
/tmp/cct1JY9i.o: In function `main':
grader.c:(.text.startup+0x5d): undefined reference to `init'
grader.c:(.text.startup+0xb8): undefined reference to `calculate'
grader.c:(.text.startup+0x122): undefined reference to `update'
collect2: error: ld returned 1 exit status