Submission #349745

# Submission time Handle Problem Language Result Execution time Memory
349745 2021-01-18T09:51:13 Z Bill_00 The Potion of Great Power (CEOI20_potion) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define N 200000
#define M 100000
#define pb push_back
#define ff first
#define ss second
using namespace std;
int h[M],n;
vector<vector<int>>v[M];
int cnt[N];
int q[M][2];
vector<pair<int,bool> >day[N];
void init(int nn,int d, int H[]){
	n=nn;
	for(int i=0;i<n;i++) h[i]=H[i];
}

void curseChanges(int u, int A[], int B[]){
	for(int i=1;i<=u;i++){
		cnt[A[i-1]]++;
		cnt[B[i-1]]++;
	}
	for(int i=0;i<n;i++){
		v[i].resize(cnt[i]);
		cnt[i]=0;
	}
	for(int i=1;i<=u;i++){
		q[i][0]=cnt[A[i-1]];
		q[i][1]=cnt[B[i-1]];
		cnt[A[i-1]]++;
		cnt[B[i-1]]++;
	}
	for(int i=0;i<n;i++) cnt[i]=0;
	for(int i=1;i<=u;i++){
		int a=A[i-1],b=B[i-1];
		day[a].pb({i,0});
		day[b].pb({i,1});
		if(cnt[a]==0){
			v[a][cnt[a]].pb(b);
		}
		else{
			bool flag=0;
			for(int j:v[a][cnt[a]-1]){
				if(j==b){
					flag=1;
					continue;
				}
				v[a][cnt[a]].pb(j);
			}
			if(flag==0) v[a][cnt[a]].pb(b);
		}
		if(cnt[b]==0){
			v[b][cnt[b]].pb(a);
		}
		else{
			bool flag=0;
			for(int j:v[b][cnt[b]-1]){
				if(j==a){
					flag=1;
					continue;
				}
				v[b][cnt[b]].pb(j);
			}
			if(flag==0) v[b][cnt[b]].pb(a);
		}
		cnt[a]++;
		cnt[b]++;
	}
}

int question(int x, int y, int z) {
	int ans=1e9;
	int id=upper_bound(day[x].begin(),day[x].end(),z)-day[x].begin();
	--id;
	int e=day[x].size()-1;
	if(id<0 || id>e){
		return ans;
	}
	int a=q[day[x][id].ff][day[x][id].ss];
	id=upper_bound(day[y].begin(),day[y].end(),z)-day[y].begin();
	--id;
	e=day[y].size()-1;
	if(id<0 || id>e){
		return ans;
	}
	int b=q[day[y][id].ff][day[y][id].ss];

	// cout << a << ' ' << b << '\n';
	if(v[x][a].size()==0 || v[y][b].size()==0){
		return ans;
	}
	vector<int>xx,yy;
	for(int V:v[y][b]){
		yy.pb(h[V]);
	}
	sort(yy.begin(),yy.end());
	for(int U:v[x][a]){
		int id=lower_bound(yy.begin(),yy.end(),h[U])-yy.begin();
		ans=min(ans,abs(h[U]-yy[max(0,id-1)]));
		int r=yy.size()-1;
		ans=min(ans,abs(yy[min(id,r)]-h[U]));
	}
	return ans;
}

Compilation message

In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_less_iter::operator()(_Value&, _Iterator) const [with _Value = const int; _Iterator = __gnu_cxx::__normal_iterator<std::pair<int, bool>*, std::vector<std::pair<int, bool> > >]':
/usr/include/c++/9/bits/stl_algo.h:2051:14:   required from '_ForwardIterator std::__upper_bound(_ForwardIterator, _ForwardIterator, const _Tp&, _Compare) [with _ForwardIterator = __gnu_cxx::__normal_iterator<std::pair<int, bool>*, std::vector<std::pair<int, bool> > >; _Tp = int; _Compare = __gnu_cxx::__ops::_Val_less_iter]'
/usr/include/c++/9/bits/stl_algo.h:2085:32:   required from '_FIter std::upper_bound(_FIter, _FIter, const _Tp&) [with _FIter = __gnu_cxx::__normal_iterator<std::pair<int, bool>*, std::vector<std::pair<int, bool> > >; _Tp = int]'
potion.cpp:73:50:   required from here
/usr/include/c++/9/bits/predefined_ops.h:90:22: error: no match for 'operator<' (operand types are 'const int' and 'std::pair<int, bool>')
   90 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:915:5: note: candidate: 'template<class _IteratorL, class _IteratorR, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_IteratorL, _Container>&, const __gnu_cxx::__normal_iterator<_IteratorR, _Container>&)'
  915 |     operator<(const __normal_iterator<_IteratorL, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:915:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:90:22: note:   mismatched types 'const __gnu_cxx::__normal_iterator<_IteratorL, _Container>' and 'const int'
   90 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:922:5: note: candidate: 'template<class _Iterator, class _Container> bool __gnu_cxx::operator<(const __gnu_cxx::__normal_iterator<_Iterator, _Container>&, const __gnu_cxx::__normal_iterator<_Iterator, _Container>&)'
  922 |     operator<(const __normal_iterator<_Iterator, _Container>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:922:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:90:22: note:   mismatched types 'const __gnu_cxx::__normal_iterator<_Iterator, _Container>' and 'const int'
   90 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:110,
                 from potion.cpp:1:
/usr/include/c++/9/bits/regex.h:1048:5: note: candidate: 'template<class _BiIter> bool std::__cxx11::operator<(const std::__cxx11::sub_match<_BiIter>&, const std::__cxx11::sub_match<_BiIter>&)'
 1048 |     operator<(const sub_match<_BiIter>& __lhs, const sub_match<_BiIter>& __rhs)
      |     ^~~~~~~~
/usr/include/c++/9/bits/regex.h:1048:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:90:22: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'const int'
   90 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:110,
                 from potion.cpp:1:
/usr/include/c++/9/bits/regex.h:1124:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator<(std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&, const std::__cxx11::sub_match<_BiIter>&)'
 1124 |     operator<(const __sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/regex.h:1124:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:90:22: note:   mismatched types 'std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>' and 'const int'
   90 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:110,
                 from potion.cpp:1:
/usr/include/c++/9/bits/regex.h:1198:5: note: candidate: 'template<class _Bi_iter, class _Ch_traits, class _Ch_alloc> bool std::__cxx11::operator<(const std::__cxx11::sub_match<_BiIter>&, std::__cxx11::__sub_match_string<_Bi_iter, _Ch_traits, _Ch_alloc>&)'
 1198 |     operator<(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/regex.h:1198:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:90:22: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'const int'
   90 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:110,
                 from potion.cpp:1:
/usr/include/c++/9/bits/regex.h:1272:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator<(const typename std::iterator_traits<_Iter>::value_type*, const std::__cxx11::sub_match<_BiIter>&)'
 1272 |     operator<(typename iterator_traits<_Bi_iter>::value_type const* __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/regex.h:1272:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:90:22: note:   'std::pair<int, bool>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   90 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:110,
                 from potion.cpp:1:
/usr/include/c++/9/bits/regex.h:1346:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator<(const std::__cxx11::sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type*)'
 1346 |     operator<(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/regex.h:1346:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:90:22: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'const int'
   90 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:110,
                 from potion.cpp:1:
/usr/include/c++/9/bits/regex.h:1421:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator<(const typename std::iterator_traits<_Iter>::value_type&, const std::__cxx11::sub_match<_BiIter>&)'
 1421 |     operator<(typename iterator_traits<_Bi_iter>::value_type const& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/regex.h:1421:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:90:22: note:   'std::pair<int, bool>' is not derived from 'const std::__cxx11::sub_match<_BiIter>'
   90 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:110,
                 from potion.cpp:1:
/usr/include/c++/9/bits/regex.h:1499:5: note: candidate: 'template<class _Bi_iter> bool std::__cxx11::operator<(const std::__cxx11::sub_match<_BiIter>&, const typename std::iterator_traits<_Iter>::value_type&)'
 1499 |     operator<(const sub_match<_Bi_iter>& __lhs,
      |     ^~~~~~~~
/usr/include/c++/9/bits/regex.h:1499:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:90:22: note:   mismatched types 'const std::__cxx11::sub_match<_BiIter>' and 'const int'
   90 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:64,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/stl_pair.h:454:5: note: candidate: 'template<class _T1, class _T2> constexpr bool std::operator<(const std::pair<_T1, _T2>&, const std::pair<_T1, _T2>&)'
  454 |     operator<(const pair<_T1, _T2>& __x, const pair<_T1, _T2>& __y)
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_pair.h:454:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:90:22: note:   mismatched types 'const std::pair<_T1, _T2>' and 'const int'
   90 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:331:5: note: candidate: 'template<class _Iterator> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_Iterator>&)'
  331 |     operator<(const reverse_iterator<_Iterator>& __x,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:331:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:90:22: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'const int'
   90 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/stl_iterator.h:369:5: note: candidate: 'template<class _IteratorL, class _IteratorR> bool std::operator<(const std::reverse_iterator<_Iterator>&, const std::reverse_iterator<_IteratorR>&)'
  369 |     operator<(const reverse_iterator<_IteratorL>& __x,
      |     ^~~~~~~~
/usr/include/c++/9/bits/stl_iterator.h:369:5: note:   template argument deduction/substitution failed:
In file included from /usr/include/c++/9/bits/stl_algobase.h:71,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from potion.cpp:1:
/usr/include/c++/9/bits/predefined_ops.h:90:22: note:   mismatched types 'const std::reverse_iterator<_Iterator>' and 'const int'
   90 |       { return __val < *__it; }
      |                ~~~~~~^~~~~~~
In file included from /usr/include/c++/9/bits/stl_algobase.h:67,
                 from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_6