답안 #477784

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477784 2021-10-03T17:19:03 Z andrey27_sm 게임 (IOI13_game) C++17
컴파일 오류
0 ms 0 KB
#include "game.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int c, rl;
int y,y1,y2;
ll vals;
int x;
ll gcd(ll x,ll y){
    if(x == 0 or y == 0) return max(x,y);
    return __gcd(x,y);
}
struct Node{
    Node* lS;
    Node* rS;
    int l, r, m;
    ll val;
    ll tmp_val;
    Node(){
        val = 0;
        lS = nullptr;
        rS = nullptr;
        l = 0;
        r = 0;
        m = 0;
    }
    Node(int l1,int r1){
        val = 0;
        lS = nullptr;
        rS = nullptr;
        l = l1;
        r = r1;
        m = (l+r)/2;
    }
    ll get(int tl,int tr){
        if(tl <= l and r <= tr) return val;
        if(tr <= m){
            if(lS) return lS->get(tl,tr);
            return 0;
        }
        else if(tl > m){
            if(rS) return rS->get(tl,tr);
            return 0;
        }else{
            tmp_val = 0;
            if(lS) tmp_val = lS->get(tl,m);
            if(rS) tmp_val = gcd(tmp_val,(rS->get(m,tr)));
            return tmp_val;
        }
    }
    void update(int y,ll vals){
        if(l == r) {
            val = vals;
            return;
        }
        if(y <= m){
            if(!lS) lS = new Node(l,m);
            lS->update(y,vals);
        }
        if(y > m){
            if(!rS) rS = new Node(m+1,r);
            rS->update(y,vals);
        }
        val = 0;
        if(lS) val = lS->val;
        if(rS) val = gcd(val,rS->val);
    }
};
struct Node2{
    Node2 *lS;
    Node2 *rS;
    Node *root;
    int l,r,m;
    ll tmp_val;
    Node2(){
        lS = nullptr;
        rS = nullptr;
        l = r = 0;
        root = new Node(0,c);
    }
    Node2(int l1,int r1){
        lS = nullptr;
        rS = nullptr;
        l = l1;
        r = r1;
        m = (l+r)/2;
        root = new Node(0,c);
    }
    ll get(int x1,int x2){
        if(x1 <= l and r <= x2) return root->get(y1,y2);
        if(x2 <= m){
            if(lS) return lS->get(x1,x2);
            return 0;
        }
        else if(x1 > m){
            if(rS) return rS->get(x1,x2);
            return 0;
        }else{
            tmp_val = 0;
            if(lS) tmp_val = lS->get(x1,m);
            if(rS) tmp_val = gcd(tmp_val,(rS->get(m+1,x2)));
            return tmp_val;
        }
    }
    void update(){
        if(l == r){
            root->update(y,vals);
            return;
        }
        if(x <= m){
            if(!lS) lS = new Node2(l,m);
            lS->update();
        }
        if(x > m){
            if(!rS) rS = new Node2(m+1,r);
            rS->update();
        }
        tmp_val = 0;
        if(lS) tmp_val = lS->root->get(y,y);
        if(rS) tmp_val = gcd(tmp_val,rS->root->get(y,y));
        root->update(y,tmp_val);
    }
};

Node2 *root = nullptr;
void init(int R,int C){
    rl = R-1;
    c = C-1;
    root = new Node2(0,rl);
}
void update(int P,int Q,ll K){
    y = Q;
    vals = K;
    x = P;
    root->update();
}
ll calculate(int P,int Q,int U,int V){
    y1 = U;
    y2 = V;
    return root->get(P,U);
}
/*
int main(){
    int t1,t2,t3;
    cin >> t1 >> t2 >> t3;
    init(t1,t2);
    while (t3--){
        int type;
        cin >> type;
        if(type == 1){
            int x,y;
            ll val;
            cin >> x >> y >> val;
            update(x,y,val);
        }
        if(type == 2){
            int x1,y1,x2,y2;
            cin >> x1 >> y1 >> x2 >> y2;
            cout << calculate(x1,y1,x2,y2) << "\n";
        }
    }
    return 0;
}*/

Compilation message

game.cpp:9:7: error: 'int y1' redeclared as different kind of entity
    9 | int y,y1,y2;
      |       ^~
In file included from /usr/include/features.h:461,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/c++config.h:518,
                 from /usr/include/c++/10/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from game.cpp:2:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:221:1: note: previous declaration 'double y1(double)'
  221 | __MATHCALL (y1,, (_Mdouble_));
      | ^~~~~~~~~~
game.cpp: In member function 'll Node2::get(int, int)':
game.cpp:93:50: error: invalid conversion from 'double (*)(double) noexcept' to 'int' [-fpermissive]
   93 |         if(x1 <= l and r <= x2) return root->get(y1,y2);
      |                                                  ^~
      |                                                  |
      |                                                  double (*)(double) noexcept
game.cpp:38:16: note:   initializing argument 1 of 'll Node::get(int, int)'
   38 |     ll get(int tl,int tr){
      |            ~~~~^~
game.cpp: In function 'll calculate(int, int, int, int)':
game.cpp:141:8: error: assignment of function 'double y1(double)'
  141 |     y1 = U;
      |     ~~~^~~