首页 技术 正文
技术 2022年11月15日
0 收藏 808 点赞 2,939 浏览 815 个字

分析:

构造数据时间有些长,可以用秦九韶优化一下。

二分答案+贪心,即:另每一个b[i]尽可能的小的同时满足题意,在枚举过程中,判断是否存在一个b[i-1]>a[i]+x

如果存在,那么向右找

如果不存在,向左找

附上代码:

#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <queue>
//#include <ctime>
using namespace std;
#define N 5000005
#define ll long long
int a[N],f[N],b[N],n,Sa,Sb,Sc,Sd,mod;
int F(int x)
{
if(f[x]) return f[x];
return f[x]=((1ll*Sa*a[x]%mod+Sb)*a[x]*a[x]%mod+(1ll*Sc*a[x]%mod+Sd)%mod)%mod;
}
int check(int x)
{
b[0]=-1<<30;
for(int i=1;i<=n;i++)
{
if(a[i]>b[i-1]+x)
{
b[i]=a[i]-x;
}else
{
if(a[i]+x<b[i-1])return 0;
b[i]=b[i-1];
}
}
return 1;
}
int main()
{
a[0]=0;
scanf("%d%d%d%d%d%d%d",&n,&Sa,&Sb,&Sc,&Sd,&a[1],&mod);
for(int i=2;i<=n;i++)a[i]=(F(i-1)+F(i-2))%mod;
int l=0,r=1<<30;
while(l<r)
{
int m=(l+r)>>1;
if(check(m)) r=m;
else l=m+1;
}
printf("%d\n",l);
return 0;
}

  卡了一下常数(loj上需要卡一下常数,bzoj和洛谷不用,开O2跑的飞快)

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,084
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,559
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,408
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,181
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,818
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,901