题面:
https://www.lydsy.com/JudgeOnline/problem.php?id=3613
题解:
考虑前面的数越小答案越优秀,于是我们二分答案,判断时让前面的数达到所能达到的最小值,这样最优秀。。
代码:
#include<bits/stdc++.h> using namespace std; typedef long long ll;
const int maxn=;
int n;
ll g[maxn],p,c,d,a,b,l,r,ans; bool pan(ll x){
ll mx=-0x3f3f3f3f;
for(int i=;i<=n;i++){
if(g[i]-x>mx) mx=g[i]-x;
else if(g[i]+x<mx) return ;
}
return ;
} ll f(ll x){
return (a*x%p*x%p*x%p+b*x%p*x%p+c*x%p+d)%p;
} int main(){
scanf("%d%lld%lld%lld%lld%lld%lld",&n,&a,&b,&c,&d,&g[],&p);
for(int i=;i<=n;i++)
g[i]=(f(g[i-])+f(g[i-]))%p;
l=,r=1e9+;
while(l<=r){
ll mid=l+r>>;
if(pan(mid))
r=mid-,ans=mid;
else
l=mid+;
}
printf("%lld",ans);
return ;
}