#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
struct node
{
ll idx,w;
bool operator <(const node &a)const
{
if(w==a.w)
return idx>a.idx;
return w<a.w;
}
node (int idx,int w)
{
this->idx=idx;
this->w=w;
}
node()
{
}
}st[10000005];
ll tail,tot;
ll T,n,m,k,p,q,r,mod;
ll maxr,ct;
ll a[10000005];
ll scan()
{
ll res=0,flag=0;
char ch;
if((ch=getchar())=='-') flag=1;
else if((ch)>='0'&&ch<='9')
res=ch-'0';
while((ch=getchar())>='0'&&ch<='9')
{
res=res*10+(ch-'0');
}
return flag?-res:res;
}
void Out(ll a)
{
if(a<0)
{
putchar('-');
a=-a;
}
if(a>=10)
{
Out(a/10);
}
putchar(a%10+'0');
}
int main()
{
T=scan();
while(T--)
{
n=scan();m=scan();k=scan();p=scan();q=scan();r=scan();mod=scan();
for(int i=1;i<=k;i++) a[i]=scan();
for(int i=k+1;i<=n;i++)
a[i]=(p*a[i-1]+q*i+r)%mod;
maxr=0,ct=0;
ll A=0,B=0;
if(m==1)
{
for(int i=1;i<=n;i++)
{
A+=a[i]^i;
B+=1^i;
}
printf("%lld %lld\n",A,B);
continue;
}
A=B=0;
tot=0;
tail=1;
st[++tot].w=a[n];
st[tot].idx=n;
for(int i=n-1;i>=1;i--)
{
while(a[i]>=st[tot].w&&tot>=tail) tot--;
st[++tot].w=a[i];
st[tot].idx=i;
if(st[tail].idx>i+m-1) tail++;
if(i<=n-m+1)
{
//printf("tail %d %d\n",st[tail].idx,i+m-1);
ct=tot-tail+1;
maxr=st[tail].w;
//printf("tot %d tail %d\n",tot,tail);
//printf("%d %d\n",maxr,ct);
//printf("%d %d\n\n",maxr^i,ct^i);
A+=(i)^maxr;
B+=(i)^ct;
}
}
printf("%lld %lld\n",A,B);
}
return 0;
}
hdu6319 单调栈
最新推荐文章于 2019-07-30 21:46:54 发布