Submission #1051630

#TimeUsernameProblemLanguageResultExecution timeMemory
1051630LudisseyRegions (IOI09_regions)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() using namespace std; vector<vector<int>> child; vector<int> parent; vector<vector<pair<int,int>>> up; unordered_map<int,int> conv; vector<int> rg; vector<vector<int>> pr; int need; int sq; vector<int> tin; vector<int> out; int timer=0; vector<int> setup_down(int x){ vector<int> cv(sq); for (auto u : child[x]) { vector<int> v=setup_down(u); for (int i=0; i<sq; i++) { down[conv[rg[x]]][i]+=v[i]; cv[i]+=v[i]; } } if(conv[rg[x]]<sq){ down[conv[rg[x]]][conv[rg[x]]]++; cv[conv[rg[x]]]++; } return cv; } void setup_up(int x, vector<int> rm){ for (int i=0; i<sz(rm); i++) { up[conv[rg[x]]][i]+=rm[i]; } if(conv[rg[x]]<sq){ up[conv[rg[x]]][conv[rg[x]]]++; rm[conv[rg[x]]]++; } for (auto u : child[x]) setup_up(u,rm); return; } void setup_euler(int x){ tin[x]=timer++; for (auto u : child[x]) setup_euler(u); out[x]=timer++; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int N,R,Q; cin >> N >> R >> Q; sq=500; child.resize(N); parent.resize(N); up.resize(R,vector<int>(sq)); down.resize(R,vector<int>(sq)); rg.resize(N); tin.resize(N); out.resize(N); pr.resize(R); cin >> rg[0]; rg[0]--; vector<pair<int,int>> cnt(R); pr[rg[0]].push_back(0); cnt[rg[0]].first++; for (int i = 1; i < N; i++) { cin >> parent[i] >> rg[i]; parent[i]--; rg[i]--; child[parent[i]].push_back(i); pr[rg[i]].push_back(i); cnt[rg[i]].first++; } for (int i = 0; i < R; i++) cnt[i].second=i; sort(all(cnt),[&](auto &aa, auto &bb){return aa>bb; }); for (int i = 0; i < sz(cnt); i++) { conv[cnt[i].second]=i; } vector<int> ep(sq); timer=0; setup_euler(0); //setup_up(0,ep); //setup_down(0); for (int i = 0; i < Q; i++) { int sm=0; int e1,e2; cin >> e1>>e2; e1--; e2--; vector<pair<int,pair<int,int>>> tos; vector<int> forCONV; unordered_map<int,int> conv2; for (int j = 0; j < sz(pr[e1]); j++) { int in1=tin[pr[e1][j]], out1=out[pr[e1][j]]; forCONV.push_back(in1); forCONV.push_back(out1); } for (int j = 0; j < sz(pr[e2]); j++) { int in1=tin[pr[e2][j]], out1=out[pr[e2][j]]; forCONV.push_back(in1); forCONV.push_back(out1); } sort(all(forCONV)); for (int j = 0; j < sz(forCONV); j++) { conv2[forCONV[j]]=j; } for (int j = 0; j < sz(pr[e1]); j++) { int in1=tin[pr[e1][j]], out1=out[pr[e1][j]]; tos.push_back({conv2[in1],{conv2[out1],1}}); } for (int j = 0; j < sz(pr[e2]); j++) { int in1=tin[pr[e2][j]], out1=out[pr[e2][j]]; tos.push_back({conv2[in1],{conv2[out1],2}}); } sort(all(tos)); vector<int> t; t.resize(sz(forCONV)*2+1,0); int ones=0; for (int j = 0; j < sz(tos); j++) { if(tos[j].second.second==1) { ones++; int p=tos[j].second.first; int value=1; for (t[p += sz(forCONV)] = value; p > 1; p >>= 1) t[p>>1] = t[p] + t[p^1]; } else{ int csum=0; int l=0; int r=tos[j].second.first+1; for (l += sz(forCONV), r += sz(forCONV); l < r; l >>= 1, r >>= 1) { if (l&1) csum += t[l++]; if (r&1) csum += t[--r]; } sm+=ones-csum; } } cout << sm << endl; } return 0; }

Compilation message (stderr)

regions.cpp: In function 'std::vector<int> setup_down(int)':
regions.cpp:26:13: error: 'down' was not declared in this scope
   26 |             down[conv[rg[x]]][i]+=v[i];
      |             ^~~~
regions.cpp:31:9: error: 'down' was not declared in this scope
   31 |         down[conv[rg[x]]][conv[rg[x]]]++;
      |         ^~~~
regions.cpp: In function 'void setup_up(int, std::vector<int>)':
regions.cpp:40:27: error: no match for 'operator+=' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'})
   40 |         up[conv[rg[x]]][i]+=rm[i];
regions.cpp:43:37: error: no 'operator++(int)' declared for postfix '++' [-fpermissive]
   43 |         up[conv[rg[x]]][conv[rg[x]]]++;
regions.cpp: In function 'int main()':
regions.cpp:62:32: error: no matching function for call to 'std::vector<std::vector<std::pair<int, int> > >::resize(int&, std::vector<int>)'
   62 |     up.resize(R,vector<int>(sq));
      |                                ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from regions.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:937:7: note: candidate: 'void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type) [with _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
  937 |       resize(size_type __new_size)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:937:7: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/10/bits/stl_vector.h:957:7: note: candidate: 'void std::vector<_Tp, _Alloc>::resize(std::vector<_Tp, _Alloc>::size_type, const value_type&) [with _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >; std::vector<_Tp, _Alloc>::size_type = long unsigned int; std::vector<_Tp, _Alloc>::value_type = std::vector<std::pair<int, int> >]'
  957 |       resize(size_type __new_size, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_vector.h:957:54: note:   no known conversion for argument 2 from 'std::vector<int>' to 'const value_type&' {aka 'const std::vector<std::pair<int, int> >&'}
  957 |       resize(size_type __new_size, const value_type& __x)
      |                                    ~~~~~~~~~~~~~~~~~~^~~
regions.cpp:63:5: error: 'down' was not declared in this scope
   63 |     down.resize(R,vector<int>(sq));
      |     ^~~~