1. 程式人生 > >bzoj3613 [Heoi2014]南園滿地堆輕絮

bzoj3613 [Heoi2014]南園滿地堆輕絮

def open .com c++ div closed bzoj3613 題解 namespace

傳送門:http://www.lydsy.com/JudgeOnline/problem.php?id=3613

【題解】

其實挺顯然。。就是最大逆序對差/2

技術分享
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned 
long long ull; const int M = 5e6 + 10; # define RG register # define ST static int n, SA, SB, SC, SD; int a[M], mod; inline int F(int x) { ll ret = 1ll * SA * x % mod * x % mod * x % mod + 1ll * SB * x % mod * x % mod + 1ll * SC * x % mod + SD; return int(ret % mod); } int main() { cin
>> n >> SA >> SB >> SC >> SD >> a[1] >> mod; for (int i=2; i<=n; ++i) { a[i] = F(a[i-1]) + F(a[i-2]); if(a[i] >= mod) a[i] -= mod; } int mx = -1, ans = 0; for (int i=1; i<=n; ++i) { if(mx >= a[i]) ans = max(ans, (mx-a[i]+1
)>>1); mx = max(mx, a[i]); } cout << ans << endl; return 0; }
View Code

bzoj3613 [Heoi2014]南園滿地堆輕絮