답안 #1101490

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1101490 2024-10-16T09:05:39 Z alexander707070 게임 (IOI13_game) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#include "game.h"
 
#define MAXN 25007
using namespace std;
 
const int maxs=1e9;

unordered_map<int,int> mp;

struct node{
    int l,r;
    long long val;
};

int num;
node tree[400*MAXN];

struct ST{

    int root;

    void init(){
        num++;
        root=num;
    }

    void addnode(){
        num++;
    }

    void update(int v,int l,int r,int pos,long long val){
        if(l==r){
            tree[v].val=val;
        }else{
            int tt=(l+r)/2;

            if(pos<=tt){
                if(tree[v].l==0){
                    addnode(); tree[v].l=num;
                }
                update(tree[v].l,l,tt,pos,val);
            }else{
                if(tree[v].r==0){
                    addnode(); tree[v].r=num;
                }
                update(tree[v].r,tt+1,r,pos,val);
            }

            tree[v].val=__gcd(tree[tree[v].l].val,tree[tree[v].r].val);
        }
    }

    long long getgcd(int v,int l,int r,int ll,int rr){
        if(v==0 or ll>rr)return 0;
        if(l==ll and r==rr){
            return tree[v].val;
        }else{
            int tt=(l+r)/2;
            return __gcd( getgcd(tree[v].l,l,tt,ll,min(tt,rr)) , getgcd(tree[v].r,tt+1,r,max(tt+1,ll),rr) );
        }
    }

    void upd(int pos,long long val){
        update(root,1,maxs,pos,val);
    }

    long long query(int l,int r){
        return getgcd(root,1,maxs,l,r);
    }
};

int last,currid;
ST col[MAXN];
 
struct ST2D{
 
    struct node{
        int l,r;
        ST t;
    };
 
    node tree[35*MAXN];
    vector< pair<int,long long> > w[35*MAXN];
    int num;
 
    void init(){
        tree[1].t.init();
        num=1;
    }
 
    void addnode(){
        num++;
        tree[num].t.init();
    }
 
    void update(int v,int l,int r,int posx,int posy,long long val){
        if(l==r){
            if(w.empty()){
                w.push_back({[posy,val]});
                return;
            }

            for(int i=0;i<w.size();i++){
                if(w[i].first==posy)w[i].second=val;
                else if(i==w.size()-1){
                    w.push_back({posy,val});
                    break;
                }
            }

        }else{
            int tt=(l+r)/2;

            if(posx<=tt){
                if(tree[v].l==0){
                    addnode(); tree[v].l=num;
                }
                update(tree[v].l,l,tt,posx,posy,val);
            }else{
                if(tree[v].r==0){
                    addnode(); tree[v].r=num;
                }
                update(tree[v].r,tt+1,r,posx,posy,val);
            }
 
            long long newval = col[currid].query(l,r);
            tree[v].t.upd(posy,newval);
        }
    }
 
    long long getgcd(int v,int l,int r,int lx,int rx,int ly,int ry){
        if(v==0 or lx>rx)return 0;
 
        if(l==lx and r==rx){
            if(l!=r)return tree[v].t.query(ly,ry);
            else{
                long long res=0;
                for(int i=0;i<w[v].size();i++){
                    if(w[v][i].first<ly or w[v][i].first>ry)continue;
                    res=__gcd(res,w[v][i].second);
                }
                
                return res;
            }
        }else{
            int tt=(l+r)/2;
            return __gcd( getgcd(tree[v].l,l,tt,lx,min(tt,rx),ly,ry) , getgcd(tree[v].r,tt+1,r,max(tt+1,lx),rx,ly,ry) );
        }
    }
 
    void upd(int x,int y,long long val){
        update(1,1,maxs,x,y,val);
    }
 
    long long query(int a,int b,int c,int d){
        return getgcd(1,1,maxs,a,c,b,d);
    }
}seg;
 
void init(int R, int C) {
    seg.init();
}
 
void update(int P, int Q, long long K) {
    P++; Q++;

    if(mp[Q]==0){
        last++; mp[Q]=last;
        col[last].init();
    }

    currid=mp[Q];
    col[currid].upd(P,K);

    seg.upd(P,Q,K);
}
 
long long calculate(int P, int Q, int U, int V) {
    P++; Q++; U++; V++;
    return seg.query(P,Q,U,V);
}
 
/*int main(){
 
    init(10,10);
 
    update(0,0,20);
    update(0,2,15);
    update(1,1,12);
 
    cout<<calculate(0,0,0,2)<<"\n";
    cout<<calculate(0,0,1,1)<<"\n";
    
    update(0,1,6);
    update(1,1,14);
 
    cout<<calculate(0,0,0,2)<<"\n";
    cout<<calculate(0,0,1,1)<<"\n";
 
	return 0;
}*/

Compilation message

game.cpp: In member function 'void ST2D::update(int, int, int, int, int, long long int)':
game.cpp:99:18: error: request for member 'empty' in '((ST2D*)this)->ST2D::w', which is of non-class type 'std::vector<std::pair<int, long long int> > [875245]'
   99 |             if(w.empty()){
      |                  ^~~~~
game.cpp:100:19: error: request for member 'push_back' in '((ST2D*)this)->ST2D::w', which is of non-class type 'std::vector<std::pair<int, long long int> > [875245]'
  100 |                 w.push_back({[posy,val]});
      |                   ^~~~~~~~~
game.cpp: In lambda function:
game.cpp:100:40: error: expected '{' before '}' token
  100 |                 w.push_back({[posy,val]});
      |                                        ^
game.cpp: In member function 'void ST2D::update(int, int, int, int, int, long long int)':
game.cpp:104:29: error: request for member 'size' in '((ST2D*)this)->ST2D::w', which is of non-class type 'std::vector<std::pair<int, long long int> > [875245]'
  104 |             for(int i=0;i<w.size();i++){
      |                             ^~~~
game.cpp:105:25: error: 'class std::vector<std::pair<int, long long int> >' has no member named 'first'
  105 |                 if(w[i].first==posy)w[i].second=val;
      |                         ^~~~~
game.cpp:105:42: error: 'class std::vector<std::pair<int, long long int> >' has no member named 'second'
  105 |                 if(w[i].first==posy)w[i].second=val;
      |                                          ^~~~~~
game.cpp:106:30: error: request for member 'size' in '((ST2D*)this)->ST2D::w', which is of non-class type 'std::vector<std::pair<int, long long int> > [875245]'
  106 |                 else if(i==w.size()-1){
      |                              ^~~~
game.cpp:107:23: error: request for member 'push_back' in '((ST2D*)this)->ST2D::w', which is of non-class type 'std::vector<std::pair<int, long long int> > [875245]'
  107 |                     w.push_back({posy,val});
      |                       ^~~~~~~~~
game.cpp: In member function 'long long int ST2D::getgcd(int, int, int, int, int, int, int)':
game.cpp:139:30: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  139 |                 for(int i=0;i<w[v].size();i++){
      |                             ~^~~~~~~~~~~~