Submission #104862

#TimeUsernameProblemLanguageResultExecution timeMemory
104862win11905Ideal city (IOI12_city)C++11
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #define long long long #define all(x) (x).begin(), (x).end() #define pii pair<int, int> #define x first #define y second using namespace std; const int M = 1e9; const int N = 1e5+5; vector<set<int> > g; vector<int> vec, sz; int n, ans; pii dfs(int u, int p) { pii now(sz[u], 0); for(auto v : g[u]) if(v != p) { pii z = dfs(v, u); ans = (ans + 1ll * now.x * z.y + 1ll * z.x * now.y) % M; now.x = (now.x + z.x) % M, now.y = (now.y + z.y) % M; } return pii(now.x, (now.y + now.x) % M); } void solve() { g = vector<set<int> >(n+1), sz = vector<int>(n+1); sort(all(vec)); map<pii, int> Mp; for(int i = 1, p = 0; p != n; ++i) { do { int z = Mp[pii(vec[p].x-1, vec[p].y)]; if(z) g[z].emplace(i), g[i].emplace(z); Mp[vec[p++]] = i, sz[i]++; } while(p < n && vec[p-1].x == vec[p].x && vec[p-1].y + 1 == vec[p].y); } dfs(1, 0); } int DistanceSum(int n, int x[], int y[]) { ::n = n; for(int i = 0; i < n; ++i) vec.emplace_back(x[i], y[i]); solve(); for(auto &x : vec) swap(x.x, x.y); solve(); return ans; }

Compilation message (stderr)

city.cpp: In function 'void solve()':
city.cpp:5:11: error: request for member 'first' in 'vec.std::vector<int>::operator[](((std::vector<int>::size_type)p))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}'
 #define x first
           ^
city.cpp:32:35: note: in expansion of macro 'x'
             int z = Mp[pii(vec[p].x-1, vec[p].y)];
                                   ^
city.cpp:6:11: error: request for member 'second' in 'vec.std::vector<int>::operator[](((std::vector<int>::size_type)p))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}'
 #define y second
           ^
city.cpp:32:47: note: in expansion of macro 'y'
             int z = Mp[pii(vec[p].x-1, vec[p].y)];
                                               ^
city.cpp:34:15: error: no match for 'operator[]' (operand types are 'std::map<std::pair<int, int>, int>' and '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}')
             Mp[vec[p++]] = i, sz[i]++;
               ^
In file included from /usr/include/c++/7/map:61:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:81,
                 from city.cpp:1:
/usr/include/c++/7/bits/stl_map.h:484:7: note: candidate: std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type& std::map<_Key, _Tp, _Compare, _Alloc>::operator[](const key_type&) [with _Key = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::pair<int, int>]
       operator[](const key_type& __k)
       ^~~~~~~~
/usr/include/c++/7/bits/stl_map.h:484:7: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}' to 'const key_type& {aka const std::pair<int, int>&}'
/usr/include/c++/7/bits/stl_map.h:504: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 = std::pair<int, int>; _Tp = int; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<const std::pair<int, int>, int> >; std::map<_Key, _Tp, _Compare, _Alloc>::mapped_type = int; std::map<_Key, _Tp, _Compare, _Alloc>::key_type = std::pair<int, int>]
       operator[](key_type&& __k)
       ^~~~~~~~
/usr/include/c++/7/bits/stl_map.h:504:7: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}' to 'std::map<std::pair<int, int>, int>::key_type&& {aka std::pair<int, int>&&}'
city.cpp:5:11: error: request for member 'first' in 'vec.std::vector<int>::operator[](((std::vector<int>::size_type)(p - 1)))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}'
 #define x first
           ^
city.cpp:35:35: note: in expansion of macro 'x'
         } while(p < n && vec[p-1].x == vec[p].x && vec[p-1].y + 1 == vec[p].y); 
                                   ^
city.cpp:5:11: error: request for member 'first' in 'vec.std::vector<int>::operator[](((std::vector<int>::size_type)p))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}'
 #define x first
           ^
city.cpp:35:47: note: in expansion of macro 'x'
         } while(p < n && vec[p-1].x == vec[p].x && vec[p-1].y + 1 == vec[p].y); 
                                               ^
city.cpp:6:11: error: request for member 'second' in 'vec.std::vector<int>::operator[](((std::vector<int>::size_type)(p - 1)))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}'
 #define y second
           ^
city.cpp:35:61: note: in expansion of macro 'y'
         } while(p < n && vec[p-1].x == vec[p].x && vec[p-1].y + 1 == vec[p].y); 
                                                             ^
city.cpp:6:11: error: request for member 'second' in 'vec.std::vector<int>::operator[](((std::vector<int>::size_type)p))', which is of non-class type '__gnu_cxx::__alloc_traits<std::allocator<int> >::value_type {aka int}'
 #define y second
           ^
city.cpp:35:77: note: in expansion of macro 'y'
         } while(p < n && vec[p-1].x == vec[p].x && vec[p-1].y + 1 == vec[p].y); 
                                                                             ^
city.cpp: In function 'int DistanceSum(int, int*, int*)':
city.cpp:5:11: error: request for member 'first' in 'first', which is of non-class type 'int'
 #define x first
           ^
city.cpp:44:31: note: in expansion of macro 'x'
     for(auto &x : vec) swap(x.x, x.y);
                               ^
city.cpp:6:11: error: request for member 'second' in 'first', which is of non-class type 'int'
 #define y second
           ^
city.cpp:44:36: note: in expansion of macro 'y'
     for(auto &x : vec) swap(x.x, x.y);
                                    ^
In file included from /usr/include/x86_64-linux-gnu/c++/7/bits/c++allocator.h:33:0,
                 from /usr/include/c++/7/bits/allocator.h:46,
                 from /usr/include/c++/7/string:41,
                 from /usr/include/c++/7/bits/locale_classes.h:40,
                 from /usr/include/c++/7/bits/ios_base.h:41,
                 from /usr/include/c++/7/ios:42,
                 from /usr/include/c++/7/istream:38,
                 from /usr/include/c++/7/sstream:38,
                 from /usr/include/c++/7/complex:45,
                 from /usr/include/c++/7/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:52,
                 from city.cpp:1:
/usr/include/c++/7/ext/new_allocator.h: In instantiation of 'void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = int; _Args = {int&, int&}; _Tp = int]':
/usr/include/c++/7/bits/alloc_traits.h:475:4:   required from 'static void std::allocator_traits<std::allocator<_CharT> >::construct(std::allocator_traits<std::allocator<_CharT> >::allocator_type&, _Up*, _Args&& ...) [with _Up = int; _Args = {int&, int&}; _Tp = int; std::allocator_traits<std::allocator<_CharT> >::allocator_type = std::allocator<int>]'
/usr/include/c++/7/bits/vector.tcc:100:30:   required from 'void std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int&, int&}; _Tp = int; _Alloc = std::allocator<int>]'
city.cpp:42:59:   required from here
/usr/include/c++/7/ext/new_allocator.h:136:4: error: new initializer expression list treated as compound expression [-fpermissive]
  { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~