Ascending Rating HDU
[题目](http://acm.hdu.edu.cn/showproblem.php?pid=6319)
大意就是让你维护从i到i+m-1的单调递增序列,O(n*m)
不过此题要倒序维护单调递减O(1)
然后对输入输出数据进行一系列奇奇怪怪的处理
#include<bits/stdc++.h> #define re return #define ll long long #define dec(i,l,r) for(int i=l;i>=r;--i) #define inc(i,l,r) for(int i=l;i<=r;++i) const int maxn=100000005; using namespace std; template<typename T>inline void rd(T&x) { char c;bool f=0; while((c=getchar())<'0'||c>'9')if(c=='-')f=1; x=c^48; while((c=getchar())>='0'&&c<='9')x=x*10+(c^48); if(f)x=-x; } ll T,n,m,k,p,Q,r,mod,hd,tail; ll a[maxn],sj[maxn]; int main() { freopen("in.txt","r",stdin); rd(T); while(T--) { rd(n),rd(m),rd(k),rd(p),rd(Q),rd(r),rd(mod); inc(i,1,k) rd(a[i]); inc(i,k+1,n) a[i]=(a[i-1]*p+Q*i+r)%mod; ll ans=0,cnt=0; hd=1;tail=0; dec(i,n,n-m+2) { while(hd<=tail&&a[sj[tail]]<=a[i])--tail; sj[++tail]=i; } dec(i,n-m+1,1) { while(hd<=tail&&sj[hd]>=i+m)++hd; while(hd<=tail&&a[sj[tail]]<=a[i])--tail; sj[++tail]=i; ans+=(i^a[sj[hd]]); cnt+=(i^(tail-hd+1)); } printf("%lld %lld\n",ans,cnt); } re 0; }