답안 #647347

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
647347 2022-10-02T09:27:16 Z Karuk Regions (IOI09_regions) C++14
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
using namespace std;
const int bucket=450;
int parent[200001];
vector<int>children[200001];
int reg[200001];///regions
vector<int>index[25001];
vector<int>regions[25001];
int ticker=0;
int beg[200001],en[200001];
void dfs(int n) {
    index[reg[n]].push_back(ticker);
    beg[n]=ticker++;
    for(int i:children[n]) {
        dfs(i);
    }
    en[n]=ticker-1;
}
vector<int>large;
int num[25001];
map<pair<int,int>,int>ans;
void dfs1(int n) {
    for(int i:large) {
        ans[{i,reg[n]}]+=num[i];
    }
    num[reg[n]]++;
    for(int i:children[n]) {
        dfs1(i);
    }
    num[reg[n]]--;

}
int main() {
    int n,r,q;cin>>n>>r>>q;
    cin>>reg[1];
    regions[reg[1]].push_back(1);
    for(int i=2;i<=n;i++) {
        cin>>parent[i]>>reg[i];
        children[parent[i]].push_back(i);
        regions[reg[i]].push_back(i);
    }
    dfs(1);
    for(int i=1;i<=r;i++) {
        if(index[i].size()>=bucket)large.push_back(i);
    }
    dfs1(1);
    for(int i=0;i<q;i++) {
        int x,y;cin>>x>>y;
        if(index[x].size()>=bucket)cout<<ans[{x,y}]<<endl;
        else {
            int anss=0;
            for(int ind:regions[x]) {
                int pos1=upper_bound(index[y].begin(),index[y].end(),beg[ind])-index[y].begin();
                int pos2=upper_bound(index[y].begin(),index[y].end(),en[ind])-index[y].begin();
                anss+=pos2-pos1;

            }
            cout<<anss<<endl;
        }
    }
    return 0;
}

Compilation message

regions.cpp:7:23: error: 'std::vector<int> index [25001]' redeclared as different kind of entity
    7 | vector<int>index[25001];
      |                       ^
In file included from /usr/include/string.h:432,
                 from /usr/include/c++/10/cstring:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:48,
                 from regions.cpp:1:
/usr/include/strings.h:61:1: note: previous declaration 'const char* index(const char*, int)'
   61 | index (const char *__s, int __c) __THROW
      | ^~~~~
regions.cpp: In function 'void dfs(int)':
regions.cpp:12:10: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   12 |     index[reg[n]].push_back(ticker);
      |          ^
regions.cpp: In function 'int main()':
regions.cpp:44:17: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   44 |         if(index[i].size()>=bucket)large.push_back(i);
      |                 ^
regions.cpp:49:17: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   49 |         if(index[x].size()>=bucket)cout<<ans[{x,y}]<<endl;
      |                 ^
regions.cpp:53:43: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   53 |                 int pos1=upper_bound(index[y].begin(),index[y].end(),beg[ind])-index[y].begin();
      |                                           ^
regions.cpp:53:60: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   53 |                 int pos1=upper_bound(index[y].begin(),index[y].end(),beg[ind])-index[y].begin();
      |                                                            ^
regions.cpp:53:85: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   53 |                 int pos1=upper_bound(index[y].begin(),index[y].end(),beg[ind])-index[y].begin();
      |                                                                                     ^
regions.cpp:54:43: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   54 |                 int pos2=upper_bound(index[y].begin(),index[y].end(),en[ind])-index[y].begin();
      |                                           ^
regions.cpp:54:60: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   54 |                 int pos2=upper_bound(index[y].begin(),index[y].end(),en[ind])-index[y].begin();
      |                                                            ^
regions.cpp:54:84: error: invalid types '<unresolved overloaded function type>[int]' for array subscript
   54 |                 int pos2=upper_bound(index[y].begin(),index[y].end(),en[ind])-index[y].begin();
      |                                                                                    ^