답안 #701832

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701832 2023-02-22T07:20:59 Z Darren0724 The Potion of Great Power (CEOI20_potion) C++17
컴파일 오류
0 ms 0 KB
int n;
vector<int> h;
struct cmp{
    bool operator()(const int &a,const int &b){
        return h[a]<h[b];
    }
};
vector<map<int,set<int,cmp>>> s;
void init(int N, int D, int H[]) {
    n=N;
    h.resize(n);
    s.resize(n);
    for(int i=0;i<n;i++){
        h[i]=H[i];
    }
    set<int,cmp> a1;
    for(int i=0;i<n;i++){
        s[i][0]=a1;
    }
}

void curseChanges(int U, int A[], int B[]) {
    for(int i=1;i<=U;i++){
        int a=A[i-1];
        int b=B[i-1];
        set<int,cmp> a1=(--s[a].end())->second;
        set<int,cmp> b1=(--s[b].end())->second;
        if(a1.find(b)==a1.end()){
            a1.insert(b);
            b1.insert(a);
        }
        else{
            a1.erase(b);
            b1.erase(a);
        }
        s[a][i]=a1;
        s[b][i]=b1;
    }
    for(int i=0;i<n;i++){
        for(auto j:s[i]){
            cout<<i<<' '<<j.first<<':';
            for(int k:j.second){
                cout<<k<<' ';
            }
            cout<<endl;
        }
    }
}

int question(int x, int y, int v) {
    set<int,cmp> s1;
    set<int,cmp> a=(--s[x].upper_bound(v))->second;
    set<int,cmp> b=(--s[y].upper_bound(v))->second;
    auto it=a.begin();
    auto it1=b.begin();
    int ans=1000000000;
    while(it!=a.end()&&it1!=b.end()){
        cout<<*it<<' '<<*it1<<endl;
        ans=min(ans,abs(h[*it]-h[*it1]));
        if(h[*it]<h[*it1]){
            it++;
        }
        else{
            it1++;
        }
    }
    return ans;
}

Compilation message

potion.cpp:2:1: error: 'vector' does not name a type
    2 | vector<int> h;
      | ^~~~~~
potion.cpp: In member function 'bool cmp::operator()(const int&, const int&)':
potion.cpp:5:16: error: 'h' was not declared in this scope
    5 |         return h[a]<h[b];
      |                ^
potion.cpp: At global scope:
potion.cpp:8:1: error: 'vector' does not name a type
    8 | vector<map<int,set<int,cmp>>> s;
      | ^~~~~~
potion.cpp: In function 'void init(int, int, int*)':
potion.cpp:11:5: error: 'h' was not declared in this scope
   11 |     h.resize(n);
      |     ^
potion.cpp:12:5: error: 's' was not declared in this scope
   12 |     s.resize(n);
      |     ^
potion.cpp:16:5: error: 'set' was not declared in this scope
   16 |     set<int,cmp> a1;
      |     ^~~
potion.cpp:16:9: error: expected primary-expression before 'int'
   16 |     set<int,cmp> a1;
      |         ^~~
potion.cpp:18:17: error: 'a1' was not declared in this scope
   18 |         s[i][0]=a1;
      |                 ^~
potion.cpp: In function 'void curseChanges(int, int*, int*)':
potion.cpp:26:9: error: 'set' was not declared in this scope
   26 |         set<int,cmp> a1=(--s[a].end())->second;
      |         ^~~
potion.cpp:26:13: error: expected primary-expression before 'int'
   26 |         set<int,cmp> a1=(--s[a].end())->second;
      |             ^~~
potion.cpp:27:13: error: expected primary-expression before 'int'
   27 |         set<int,cmp> b1=(--s[b].end())->second;
      |             ^~~
potion.cpp:28:12: error: 'a1' was not declared in this scope; did you mean 'a'?
   28 |         if(a1.find(b)==a1.end()){
      |            ^~
      |            a
potion.cpp:30:13: error: 'b1' was not declared in this scope; did you mean 'b'?
   30 |             b1.insert(a);
      |             ^~
      |             b
potion.cpp:34:13: error: 'b1' was not declared in this scope; did you mean 'b'?
   34 |             b1.erase(a);
      |             ^~
      |             b
potion.cpp:36:9: error: 's' was not declared in this scope
   36 |         s[a][i]=a1;
      |         ^
potion.cpp:36:17: error: 'a1' was not declared in this scope; did you mean 'a'?
   36 |         s[a][i]=a1;
      |                 ^~
      |                 a
potion.cpp:37:17: error: 'b1' was not declared in this scope; did you mean 'b'?
   37 |         s[b][i]=b1;
      |                 ^~
      |                 b
potion.cpp:40:20: error: 's' was not declared in this scope
   40 |         for(auto j:s[i]){
      |                    ^
potion.cpp:41:13: error: 'cout' was not declared in this scope
   41 |             cout<<i<<' '<<j.first<<':';
      |             ^~~~
potion.cpp:45:19: error: 'endl' was not declared in this scope
   45 |             cout<<endl;
      |                   ^~~~
potion.cpp: In function 'int question(int, int, int)':
potion.cpp:51:5: error: 'set' was not declared in this scope
   51 |     set<int,cmp> s1;
      |     ^~~
potion.cpp:51:9: error: expected primary-expression before 'int'
   51 |     set<int,cmp> s1;
      |         ^~~
potion.cpp:52:9: error: expected primary-expression before 'int'
   52 |     set<int,cmp> a=(--s[x].upper_bound(v))->second;
      |         ^~~
potion.cpp:53:9: error: expected primary-expression before 'int'
   53 |     set<int,cmp> b=(--s[y].upper_bound(v))->second;
      |         ^~~
potion.cpp:54:13: error: 'a' was not declared in this scope
   54 |     auto it=a.begin();
      |             ^
potion.cpp:55:14: error: 'b' was not declared in this scope
   55 |     auto it1=b.begin();
      |              ^
potion.cpp:58:9: error: 'cout' was not declared in this scope
   58 |         cout<<*it<<' '<<*it1<<endl;
      |         ^~~~
potion.cpp:58:31: error: 'endl' was not declared in this scope
   58 |         cout<<*it<<' '<<*it1<<endl;
      |                               ^~~~
potion.cpp:59:25: error: 'h' was not declared in this scope
   59 |         ans=min(ans,abs(h[*it]-h[*it1]));
      |                         ^
potion.cpp:59:21: error: 'abs' was not declared in this scope; did you mean 'ans'?
   59 |         ans=min(ans,abs(h[*it]-h[*it1]));
      |                     ^~~
      |                     ans
potion.cpp:59:13: error: 'min' was not declared in this scope
   59 |         ans=min(ans,abs(h[*it]-h[*it1]));
      |             ^~~