【BZOJ 3613】 [Heoi2014]南園滿地堆輕絮,bzojheoi2014
3613: [Heoi2014]南園滿地堆輕絮
Time Limit: 50 Sec Memory Limit: 256 MB
Submit: 167 Solved: 109
[Submit][Status][Discuss]
Description
小 Z 是 ZRP(Zombies’ Republic of Poetry,殭屍詩歌共和國)的一名詩歌愛好者,最近 他研究起了詩詞音律的問題。
在過去,詩詞是需要編成曲子唱出來的,比如下面這首《菩薩蠻》,唱出來的話其對應 的音符就是這樣的:
南 園 滿 地 堆 輕 絮, 愁 聞 一 霎 清 明 雨
1 1 5 5 6 6 5 4 4 3 3 2 2 1
因而可以發現,“1 1 5 5 6 6 5 4 4 3 3 2 2 1”這串音符就成為了研究音律的關鍵。
小 Z 翻閱了眾多史料發現,過去的一首曲子的音調是不下降的
小 Z 想要知道對於一首給定的曲子,如何通過提高音調或者降低音調,將它的音調修改 的不下降,
而且使得修改幅度最大的那個音符的修改幅度盡量小。
即如果把一個包含 n 個音 符的曲子看做是一個正整數數列 A[1]…A[n],
那麼 目標是求另一個正整數數列 B[1]…B[n], 使得對於任意的 1≤i
#include <iostream>#include <cstring>#include <cstdio>#include <algorithm>#include <cmath>#include <cstdlib>#define LL long longusing namespace std;int n,a[5000005],mod;LL sa,sb,sc,sd;int F(LL x){ return (x*x%mod*x%mod*sa%mod+sb*x%mod*x%mod+sc*x%mod+sd)%mod;}int ok(int x){ int pre=a[1]-x; for (int i=2;i<=n;i++) { if (a[i]+x>=pre) { if (pre<a[i]-x) pre=a[i]-x; } else return 0; } return 1;}int main(){ cin>>n>>sa>>sb>>sc>>sd>>a[1]>>mod; a[0]=0; for (int i=2;i<=n;i++) a[i]=(int)((F(a[i-1])+F(a[i-2]))%mod+mod)%mod; int ans,l=0,r=mod+5; while(l<=r) { int m=(l+r)>>1; if (ok(m)) ans=m,r=m-1; else l=m+1; } cout<<ans<<endl; return 0;}