Submission #167904

# Submission time Handle Problem Language Result Execution time Memory
167904 2019-12-10T18:24:19 Z muhi1112 Pismo (COCI18_pismo) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define f1 first
#define s2 second
#define pb push_back
#define mp make_pair
#define ll long long
#define fri(a) freopen(a,"r",stdin);
#define fro(a) freopen(a,"w",stdout);
const int N=1e5+5;
const int INF=1e9+7;

int n,dizi[N],lok[N],maxst[N][25],tleft[N],tright[N],ans=INF;
stack<int>st1;

void loki(){
	for(int i=2;i<N;i++){
		lok[i]=lok[i/2]+1;
	}
	return;
}
void build(){
	for(int j=1;j<25;j++){
		for(int i=0;i+(1<<j)<N;i++){
			maxst[i][j]=max(maxst[i][j-1],maxst[i+(1<<(j-1))][j-1]);
		}
	}
	return;
}
ll qmax(int l,int r){
	int j=lok[(r-l+1)];
	return max(maxst[l][j],maxst[r-(1<<j)+1][j]);
}
void prepro1(){
	for(int i=0;i<=n;i++){
		while(!st1.empty() && dizi[i]<=dizi[st1.top()]){
			st1.pop();
		}
		tleft[i]=st1.top()+1;
		st1.push(i);
	}
	while(!st1.empty()){
		st1.pop();
	}
	return;
	//cout<<endl;

}
void prepro2(){
	for(int i=n+1;i>0;i--){
		while(!st1.empty() && dizi[i]<=dizi[st1.top()]){
			st1.pop();
		}
		tright[i]=st1.top()-1;
		st1.push(i);
	}
	return;
}
ll solve(){
	for(int i=1;i<=n;i++){
		//cout<<tright[i]<<" "<<tleft[i]<<" "<<qmax(tright[i],tleft[i])<<endl;
		ans=min(ans,tright[i]-tleft[i]>0?qmax(tleft[i],tright[i])-dizi[i]:INF);
	}
	return ans;
}
int main(){
	//fri("in.txt");
	//fro("out.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin>>n;
	memset(dizi,-1,sizeof(dizi));
	for(int i=1;i<=n;i++){
		cin>>dizi[i];
		maxst[i][0]=dizi[i];
	}
	loki();
	build();
	//cout<<qmax(2,2);
	prepro1();
	prepro2();
	//cout<<tleft[5]<<" "<<tright[5]<<endl;
	cout<<solve()<<endl;

return 0;
}

Compilation message

pismo.cpp: In function 'long long int solve()':
pismo.cpp:64:72: error: no matching function for call to 'min(int&, long long int)'
   ans=min(ans,tright[i]-tleft[i]>0?qmax(tleft[i],tright[i])-dizi[i]:INF);
                                                                        ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from pismo.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:195:5: note: candidate: template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)
     min(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:195:5: note:   template argument deduction/substitution failed:
pismo.cpp:64:72: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   ans=min(ans,tright[i]-tleft[i]>0?qmax(tleft[i],tright[i])-dizi[i]:INF);
                                                                        ^
In file included from /usr/include/c++/7/bits/specfun.h:45:0,
                 from /usr/include/c++/7/cmath:1914,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:41,
                 from pismo.cpp:1:
/usr/include/c++/7/bits/stl_algobase.h:243:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)
     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:243:5: note:   template argument deduction/substitution failed:
pismo.cpp:64:72: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   ans=min(ans,tright[i]-tleft[i]>0?qmax(tleft[i],tright[i])-dizi[i]:INF);
                                                                        ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from pismo.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3450:5: note: candidate: template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)
     min(initializer_list<_Tp> __l)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
pismo.cpp:64:72: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   ans=min(ans,tright[i]-tleft[i]>0?qmax(tleft[i],tright[i])-dizi[i]:INF);
                                                                        ^
In file included from /usr/include/c++/7/algorithm:62:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from pismo.cpp:1:
/usr/include/c++/7/bits/stl_algo.h:3456:5: note: candidate: template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)
     min(initializer_list<_Tp> __l, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
pismo.cpp:64:72: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   ans=min(ans,tright[i]-tleft[i]>0?qmax(tleft[i],tright[i])-dizi[i]:INF);
                                                                        ^