首页 > 其他分享 >Luogu P4105 [HEOI2014]南园满地堆轻絮

Luogu P4105 [HEOI2014]南园满地堆轻絮

时间:2022-10-25 14:00:49浏览次数:61  
标签:maxx P4105 int Luogu 南园 long include check mod


题目链接:​​传送门​

明显的二分
简单的check
我的没有long long会炸掉50分

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <complex>
#include <algorithm>
#include <climits>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <iomanip>
#define
#define

using namespace std;
typedef long long ll;
int n, sa, sb, sc, sd, a[A], mod;
ll F(ll x) {
return ((sa * x % mod * x % mod * x % mod + sb * x % mod * x % mod) % mod + (sc * x % mod + sd) % mod) % mod;
}
bool check(int x, int maxx = 1) {
for (int i = 1; i <= n; i++) {
maxx = max(maxx, a[i] - x);
if (maxx > a[i] + x) return false;
}
return true;
}

int main(int argc, char const *argv[]) {
cin >> n >> sa >> sb >> sc >> sd >> a[1] >> mod; a[0] = 0;
for (int i = 2; i <= n; i++) a[i] = (F(a[i - 1]) + F(a[i - 2])) % mod;
int l = 1, r = mod;
while (l <= r) {
int m = (l + r) >> 1;
if (check(m)) r = m - 1;
else l = m + 1;
}
cout << l << endl;
}


标签:maxx,P4105,int,Luogu,南园,long,include,check,mod
From: https://blog.51cto.com/lyle/5794681

相关文章

  • Luogu P3313 [SDOI2014]旅行
    题目链接:​​传送门​​动态开点+树剖的模板吧。都很熟的话就挺好写的特别注意在dfs序上修改#include<iostream>#include<cstdio>#include<cstring>#include<cstdli......
  • Luogu P2412 查单词
    题目链接:​​传送门​​做完这个题感觉我是个沙雕在越做越麻烦的道路上一去不复返我真傻,真的(会有大量冗余变量)#include<iostream>#include<cstdio>#include<cstring>......
  • 【luogu ARC106E】Medals(二分)(高维前缀和)
    Medals题目链接:luoguARC106E题目大意有n个第i个人的出现规律是对于所有2aik+1~2ai(k+1)的区间,2aik+1~2aik+ai会出现,另一部分则会不见。每个时间点你可以选择一......
  • 【luogu AGC035E】Develop(分类讨论)(DP)
    Develop题目链接:luoguAGC035E题目大意一开始有-1e18~1e18的所有整数,然后你每次操作可以在1~N中选一个还在的数x,擦掉他,然后查看x-2,x+K,如果没有就把数加上。然后......
  • luogu P8275 [USACO22OPEN] 262144 Revisited P
    题面传送门这里有个sb写这道题写了一下午。首先来考虑一段子段上的答案,显然答案有一个区间,设最大值为\(E\),则最小值一定在\([E,E+\logn]\)之间。我们考虑按照最大值分......
  • luogu P8585 球状精灵的传说 题解
    题目大意给定\(n\)个精灵的三维幅度\(\{r_{1,i},r_{2,i},r_{3,i}\}\),任意两个精灵若在三个幅度中有两个相同(这里可以乱序)则可以将剩下的一位相加组合起来。组合过的精......
  • Luogu P8348
    构造题。……这玩意儿怎么构造。不过只用判断Yes/No。考虑找一个方法唯一的表示一对数能表示的拓展出的序列包含的所有“一对数”。容易想到一直减到最小,用最终结果......
  • [luogu6575]Friends
    记$s=p+q$,当存在一个点度数$\ges$时,显然无解记$d_{S,T}=\sum_{x\inS,y\inT}[(x,y)\inE]$,称$S\subseteqV$合法当且仅当$|S|\lep$且$d(S,V\backslashS)\leq$结论:若......
  • Luogu P2656采蘑菇(Tarjan + spfa)
    采蘑菇题目描述小胖和ZYR要去ESQMS森林采蘑菇。ESQMS森林间有\(N\)个小树丛,\(M\)条小径,每条小径都是单向的,连接两个小树丛,上面都有一定数量的蘑菇。小胖和ZYR......
  • 【luogu AGC034F】RNG and XOR(FWT)
    RNGandXOR题目链接:luoguAGC034F题目大意给你一个长度为2^n的数组A。一开始有一个\(0\)数,然后每次你随机给它异或上0~2^n-1中的数,随机到\(i\)的概率跟Ai+1......