Submission #773015

#TimeUsernameProblemLanguageResultExecution timeMemory
773015dooweyPrize (CEOI22_prize)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define fi first #define se second #define mp make_pair #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); const int N = (int)1e6 + 10; const int LOG = 20; int n, k, q, t; struct ans{ int d1, d2, d3, d4; }; vector<pii> questions; vector<ans> answers; struct tree{ vector<int> T[N]; vector<int> Q[N]; int dep[N]; int idx; int root; void input(){ int p; for(int i = 1; i <= n; i ++ ){ cin >> p; if(p == -1){ root = i; } else{ T[p].push_back(i); } } } int up[LOG][N]; int tin[N]; int tout[N]; int tt = 0; void dfs(int u, int pa){ tt ++ ; tin[u] = tt; up[0][u]=pa; for(int lg = 1; lg < LOG; lg ++ ){ up[lg][u]=up[lg-1][up[lg-1][u]]; } for(auto x : T[u]){ dfs(x,u); } tout[u] = tt; } bool is_anc(int u, int v){ return tin[u] <= tin[v] && tout[u] >= tout[v]; } int lca(int u, int v){ if(is_anc(u, v)) return u; for(int lg = LOG - 1; lg >= 0 ;lg -- ){ if(!is_anc(up[lg][u], v)) u=up[lg][u]; } return up[0][u]; } set<pii> L[N]; void add_edge(int u, int v){ if(u != v){ Q[u].push_back(v); //Q[v].push_back(mp(u, w)); } } int R; void dfs_virtual(int node){ for(auto x : Q[node]){ L[node].insert(); } } vector<int> lis; vector<int> answ; void make_questions(vector<int> _li){ lis = _li; dfs(root, root); sort(lis.begin(), lis.end(), [&](int x, int y) {return tin[x] < tin[y];}); for(int i = 0 ; i + 1 < lis.size(); i ++ ){ answ.push_back(questions.size()); questions.push_back(mp(lis[i], lis[i+1])); } } void make_virtual(){ vector<int> wh; for(auto x : lis){ wh.push_back(x); } int cur; for(int i = 0 ; i + 1 < lis.size(); i ++ ){ cur = lca(lis[i], lis[i + 1]); wh.push_back(cur); } sort(wh.begin(), wh.end(), [&](int x, int y) {return tin[x] < tin[y];}); vector<int> stek; for(auto x : wh){ while(!stek.empty() && is_anc(x, stek.back())) stek.pop_back(); if(!stek.empty()) add_edge(stek.back(), x, 0); stek.push_back(x); } dfs_virtual(big); } int get_dist(int i, int j){ int lc = lca(i, j); return dep[i] + dep[j] - 2 * dep[lc]; } }; tree A, B; int main(){ //fastIO; cin >> n >> k >> q >> t; vector<int> y; for(int i = 1; i <= k ; i ++ ){ y.push_back(i); } A.input(); B.input(); A.idx = 0; B.idx = 1; A.make_questions(y); B.make_questions(y); for(auto x : y){ cout << x << " "; } cout << "\n"; fflush(stdout); for(auto x : questions){ cout << "? " << x.fi << " " << x.se << "\n"; } cout << "!\n"; fflush(stdout); answers.resize(questions.size()); for(int i = 0 ; i < questions.size(); i ++ ){ cin >> answers[i].d1 >> answers[i].d2 >> answers[i].d3 >> answers[i].d4; } A.make_virtual(); B.make_virtual(); int l, r; vector<pii> qq; for(int iq = 1; iq <= t; iq ++ ){ cin >> l >> r; qq.push_back(mp(l, r)); } for(auto v : qq){ cout << A.get_dist(v.fi,v.se) << " " << B.get_dist(v.fi,v.se) << "\n"; } fflush(stdout); return 0; }

Compilation message (stderr)

Main.cpp: In member function 'void tree::dfs_virtual(int)':
Main.cpp:85:28: error: no matching function for call to 'std::set<std::pair<int, int> >::insert()'
   85 |             L[node].insert();
      |                            ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_set.h:509:7: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(const value_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
  509 |       insert(const value_type& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_set.h:509:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/10/bits/stl_set.h:518:7: note: candidate: 'std::pair<typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator, bool> std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; typename std::_Rb_tree<_Key, _Key, std::_Identity<_Tp>, _Compare, typename __gnu_cxx::__alloc_traits<_Alloc>::rebind<_Key>::other>::const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
  518 |       insert(value_type&& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_set.h:518:7: note:   candidate expects 1 argument, 0 provided
/usr/include/c++/10/bits/stl_set.h:546:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, const value_type&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
  546 |       insert(const_iterator __position, const value_type& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_set.h:546:7: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/10/bits/stl_set.h:551:7: note: candidate: 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::insert(std::set<_Key, _Compare, _Alloc>::const_iterator, std::set<_Key, _Compare, _Alloc>::value_type&&) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::const_iterator = std::_Rb_tree<std::pair<int, int>, std::pair<int, int>, std::_Identity<std::pair<int, int> >, std::less<std::pair<int, int> >, std::allocator<std::pair<int, int> > >::const_iterator; std::set<_Key, _Compare, _Alloc>::value_type = std::pair<int, int>]'
  551 |       insert(const_iterator __position, value_type&& __x)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_set.h:551:7: note:   candidate expects 2 arguments, 0 provided
/usr/include/c++/10/bits/stl_set.h:566:2: note: candidate: 'template<class _InputIterator> void std::set<_Key, _Compare, _Alloc>::insert(_InputIterator, _InputIterator) [with _InputIterator = _InputIterator; _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]'
  566 |  insert(_InputIterator __first, _InputIterator __last)
      |  ^~~~~~
/usr/include/c++/10/bits/stl_set.h:566:2: note:   template argument deduction/substitution failed:
Main.cpp:85:28: note:   candidate expects 2 arguments, 0 provided
   85 |             L[node].insert();
      |                            ^
In file included from /usr/include/c++/10/set:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:87,
                 from Main.cpp:1:
/usr/include/c++/10/bits/stl_set.h:578:7: note: candidate: 'void std::set<_Key, _Compare, _Alloc>::insert(std::initializer_list<_Tp>) [with _Key = std::pair<int, int>; _Compare = std::less<std::pair<int, int> >; _Alloc = std::allocator<std::pair<int, int> >]'
  578 |       insert(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/10/bits/stl_set.h:578:7: note:   candidate expects 1 argument, 0 provided
Main.cpp:84:18: warning: unused variable 'x' [-Wunused-variable]
   84 |         for(auto x : Q[node]){
      |                  ^
Main.cpp: In member function 'void tree::make_questions(std::vector<int>)':
Main.cpp:94:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   94 |         for(int i = 0 ; i + 1 < lis.size(); i ++ ){
      |                         ~~~~~~^~~~~~~~~~~~
Main.cpp: In member function 'void tree::make_virtual()':
Main.cpp:106:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         for(int i = 0 ; i + 1 < lis.size(); i ++ ){
      |                         ~~~~~~^~~~~~~~~~~~
Main.cpp:115:57: error: no matching function for call to 'tree::add_edge(__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type&, int&, int)'
  115 |             if(!stek.empty()) add_edge(stek.back(), x, 0);
      |                                                         ^
Main.cpp:76:10: note: candidate: 'void tree::add_edge(int, int)'
   76 |     void add_edge(int u, int v){
      |          ^~~~~~~~
Main.cpp:76:10: note:   candidate expects 2 arguments, 3 provided
Main.cpp:119:21: error: 'big' was not declared in this scope
  119 |         dfs_virtual(big);
      |                     ^~~
Main.cpp: In function 'int main()':
Main.cpp:154:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  154 |     for(int i = 0 ; i < questions.size(); i ++ ){
      |                     ~~^~~~~~~~~~~~~~~~~~