Submission #701840

#TimeUsernameProblemLanguageResultExecution timeMemory
701840Darren0724The Potion of Great Power (CEOI20_potion)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> using namespace std; int n; vector<int> h; struct cmp{ bool operator()(const int &a,const int &b){ return h[a]<h[b]; } }; vector<map<int,set<int,cmp>>> s; void init(int N, int D, int H[]) { n=N; h.resize(n); s.resize(n); for(int i=0;i<n;i++){ h[i]=H[i]; } set<int,cmp> a1; for(int i=0;i<n;i++){ s[i][0]=a1; } } void curseChanges(int U, int A[], int B[]) { for(int i=1;i<=U;i++){ int a=A[i-1]; int b=B[i-1]; set<int,cmp> a1=(--s[a].end())->second; set<int,cmp> b1=(--s[b].end())->second; bool flag=a1.find(b)==a1.end(); if(flag){ a1.insert(b); b1.insert(a); } else{ a1.erase(b); b1.erase(a); } s[a][i]=a1; s[b][i]=b1; } /*for(int i=0;i<n;i++){ for(auto j:s[i]){ cout<<i<<' '<<j.first<<':'; for(int k:j.second){ cout<<k<<' '; } cout<<endl; } }*/ } int question(int x, int y, int v) { set<int,cmp> s1; set<int,cmp> a=(--s[x].upper_bound(v))->second; set<int,cmp> b=(--s[y].upper_bound(v))->second; auto it=a.begin(); auto it1=b.begin(); int ans=1000000000; while(it!=a.end()&&it1!=b.end()){ ans=min(ans,abs(h[*it]-h[*it1])); if(h[*it]<h[*it1]){ it++; } else{ it1++; } } return ans; }

Compilation message (stderr)

In file included from /usr/include/c++/10/map:60,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:81,
                 from potion.cpp:1:
/usr/include/c++/10/bits/stl_tree.h: In instantiation of 'static const _Key& std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_S_key(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type) [with _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = cmp; _Alloc = std::allocator<int>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Const_Link_type = const std::_Rb_tree_node<int>*]':
/usr/include/c++/10/bits/stl_tree.h:1935:36:   required from 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_M_lower_bound(std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type, std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Base_ptr, const _Key&) [with _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = cmp; _Alloc = std::allocator<int>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator = std::_Rb_tree<int, int, std::_Identity<int>, cmp, std::allocator<int> >::iterator; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Link_type = std::_Rb_tree_node<int>*; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::_Base_ptr = std::_Rb_tree_node_base*]'
/usr/include/c++/10/bits/stl_tree.h:2553:36:   required from 'std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::find(const _Key&) [with _Key = int; _Val = int; _KeyOfValue = std::_Identity<int>; _Compare = cmp; _Alloc = std::allocator<int>; std::_Rb_tree<_Key, _Val, _KeyOfValue, _Compare, _Alloc>::iterator = std::_Rb_tree<int, int, std::_Identity<int>, cmp, std::allocator<int> >::iterator]'
/usr/include/c++/10/bits/stl_set.h:795:25:   required from 'std::set<_Key, _Compare, _Alloc>::iterator std::set<_Key, _Compare, _Alloc>::find(const key_type&) [with _Key = int; _Compare = cmp; _Alloc = std::allocator<int>; std::set<_Key, _Compare, _Alloc>::iterator = std::_Rb_tree<int, int, std::_Identity<int>, cmp, std::allocator<int> >::const_iterator; std::set<_Key, _Compare, _Alloc>::key_type = int]'
potion.cpp:30:28:   required from here
/usr/include/c++/10/bits/stl_tree.h:780:8: error: static assertion failed: comparison object must be invocable as const
  780 |        is_invocable_v<const _Compare&, const _Key&, const _Key&>,
      |        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~