Submission #1049832

#TimeUsernameProblemLanguageResultExecution timeMemory
1049832nisanduuFountain Parks (IOI21_parks)C++17
Compilation error
0 ms0 KiB
#include "parks.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; class Disjoint{ vector<int> parent,sz; public: Disjoint(int n){ parent.resize(n+1); sz.resize(n+1,1); for(int i=0;i<n+1;i++) parent[i]=i; } int findPar(int node){ if(parent[node]==node) return node; return parent[node] = findPar(parent[node]); } void uz(int node1,int node2){ int p1 = findPar(node1); int p2 = findPar(node2); if(p1==p2) return; if(sz[p1]>sz[p2]){ parent[p2]=parent[p1]; sz[p1] += sz[p2]; }else{ parent[p1]=parent[p2]; sz[p2] += sz[p1]; } } }; int construct_roads(std::vector<int> x, std::vector<int> y) { ll n = x.size(); Disjoint ds(n+10); map<ll,map<ll,ll>> hash1; map<ll,pair<ll,ll>> hash2; map<ll,ll> picked; vector<pair<int,int>> arr(n); int crInd = 0; for(int i=0;i<n;i++){ hash1[x[i]][y[i]]=crInd; hash2[crInd] = {x[i],y[i]}; } vector<int> u, v, a, b; for(int i=0;i<n;i++){ int crX = x[i]; int crY = y[i]; if(hash1[crX+2][crY]){ if(ds.findPar(i)!=ds.findPar(hash1[crX+2][crY])){ ds.uz(i,hash1[crX+2][crY]); u.push_back(i); v.push_back(hash1[crX+2][crY]); } } if(hash1[crX-2][crY]){ if(ds.findPar(i)!=ds.findPar(hash1[crX-2][crY])){ ds.uz(i,hash1[crX-2][crY]); u.push_back(i); v.push_back(hash1[crX-2][crY]); } } if(hash1[crX][crY+2]){ if(ds.findPar(i)!=ds.findPar(hash1[crX][crY+2])){ ds.uz(i,hash1[crX][crY+2]); u.push_back(i); v.push_back(hash1[crX][crY+2]); } } if(hash1[crX][crY-2]){ if(ds.findPar(i)!=ds.findPar(hash1[crX][crY-2])){ ds.uz(i,hash1[crX][crY-2]); u.push_back(i); v.push_back(hash1[crX][crY-2]); } } } set<int> p; for(int i=0;i<n;i++){ p.insert(ds.findPar(i)); } if(p.size()!=1){ return 0; } map<ll,map<ll,ll>> oc; for(int i=0;i<n-1;i++){ int crX = x[u[i]]; int crY = y[u[i]]; int nxX = x[v[i]]; int nxY = y[v[i]]; if(crX == nxX){ ll bv = (crY + nxY)/2; if(oc[crX + 1][b]){ a.push_back(crX - 1); b.push_back(bv); oc[crX - 1][bv] = 1; }else{ a.push_back(crX + 1); b.push_back(bv); oc[crX + 1][bv] = 1; } }else{ ll av = (crX + nxX) / 2; if(oc[a][crY + 1]){ a.push_back(av); b.push_back(crY - 1); oc[av][crY - 1] = 1; }else{ a.push_back(av); b.push_back(crY + 1); oc[av][crY + 1] = 1; } } } // bool f=1; // for(ll i=0;i<n-1;i++){ // if((arr[i+1].first - arr[i].first) != 2){ // return 0; // } // u.push_back(arr[i+1].second); // v.push_back(arr[i].second); // a.push_back(1); // b.push_back((arr[i+1].first+arr[i].first)/2); // } build(u, v, a, b); return 1; }

Compilation message (stderr)

parks.cpp: In function 'int construct_roads(std::vector<int>, std::vector<int>)':
parks.cpp:95:27: error: no match for 'operator[]' (operand types are 'std::map<long long int, std::map<long long int, long long int> >::mapped_type' {aka 'std::map<long long int, long long int>'} and 'std::vector<int>')
   95 |             if(oc[crX + 1][b]){
      |                           ^
In file included from /usr/include/c++/10/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from parks.cpp:2:
/usr/include/c++/10/bits/stl_map.h:492:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = long long int; _Tp = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = long long int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = long long int]'
  492 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_map.h:492:34: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const key_type&' {aka 'const long long int&'}
  492 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_map.h:512:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = long long int; _Tp = long long int; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, long long int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = long long int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = long long int]'
  512 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_map.h:512:29: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::map<long long int, long long int>::key_type&&' {aka 'long long int&&'}
  512 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~
parks.cpp:106:18: error: no match for 'operator[]' (operand types are 'std::map<long long int, std::map<long long int, long long int> >' and 'std::vector<int>')
  106 |             if(oc[a][crY + 1]){
      |                  ^
In file included from /usr/include/c++/10/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from parks.cpp:2:
/usr/include/c++/10/bits/stl_map.h:492:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = long long int; _Tp = std::map<long long int, long long int>; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, std::map<long long int, long long int> > >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = std::map<long long int, long long int>; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = long long int]'
  492 |       operator[](const key_type& __k)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_map.h:492:34: note:   no known conversion for argument 1 from 'std::vector<int>' to 'const key_type&' {aka 'const long long int&'}
  492 |       operator[](const key_type& __k)
      |                  ~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_map.h:512:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](std::map<_Key, _Tp, _Compare, _Alloc>::key_type&&) [with _Key = long long int; _Tp = std::map<long long int, long long int>; _Compare = std::less<long long int>; _Alloc = std::allocator<std::pair<const long long int, std::map<long long int, long long int> > >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = std::map<long long int, long long int>; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = long long int]'
  512 |       operator[](key_type&& __k)
      |       ^~~~~~~~
/usr/include/c++/10/bits/stl_map.h:512:29: note:   no known conversion for argument 1 from 'std::vector<int>' to 'std::map<long long int, std::map<long long int, long long int> >::key_type&&' {aka 'long long int&&'}
  512 |       operator[](key_type&& __k)
      |                  ~~~~~~~~~~~^~~