[HEOI2014]南园满地堆轻絮
题解:
答案就是差距最大的逆序对的一半,因为两个数都减小一半就可以了。
时间复杂度O(n)
/*Keep on going Never give up*/ //#pragma GCC optimize(3,"Ofast","inline") #include <iostream> #include <cstdio> #include <stdlib.h> #include <cstring> #include <cmath> #include <math.h> #include <string> #include<string.h> #include <list> #include <set> #include <unordered_map> #include <queue> #include <stack> #include <algorithm> #include <stdlib.h> #include <vector> #include <cctype> #include<iomanip> #define int long long #define endl '\n' using namespace std; const int maxn = 1e6+10; const int MaxN = 0x3f3f3f3f; const int MinN = 0xc0c0c00c; typedef long long ll; const ll mod= 199999; using namespace std; int n,a,b,c,d; int arr[5000001]; int mmd,ans; int F(int x){ return ((((((a*x)%mmd*x)%mmd*x)%mmd+(b*x%mmd)*x%mmd)%mmd+(c*x)%mmd)%mmd+d)%mmd; } signed main(){ cin>>n>>a>>b>>c>>d>>arr[1]>>mmd; int imax=arr[1]; for(int i=2;i<=n;i++){ arr[i]=(F(arr[i-1])+F(arr[i-2]))%mmd; ans=max(ans,imax-arr[i]); imax=max(imax,arr[i]); } cout<<(ans+1)/2<<endl; return 0; }
题解 文章被收录于专栏
主要写一些题目的题解