大致题意
给定一个生成数列的方式,要求维护一个栈,每次push和pop操作后都要输出栈内最大值。
思路
网络赛时候当场懵了。栈内元素顺序不能变,但是他只要求最大值就行,于是每次判断要push的元素,如果比栈顶元素大直接push,否则再push一遍栈顶元素,相当于变成一个前缀最大数列。
代码
#include<bits/stdc++.h>
using namespace std;
#define maxn 5000005
#define maxm 20006
#define ll long long int
#define INF 0x3f3f3f3f
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,r,l) for(int i=r;i>=l;i--)
#define mem(a) memset(a,0,sizeof(a))
#define sqr(x) (x*x)
#define inf (ll)2e18+1
ll read(){
ll x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
return f*x;
}
unsigned int T,n,m,p,q,sa,sb,sc;
unsigned int rng61(){
sa^=sa<<16;
sa^=sa>>5;
sa^=sa<<1;
ll t=sa;sa=sb;
sb=sc;
sc^=t^sa;
return sc;
}
ll st[maxn];
int top;
int main()
{
T=read();
int kase=0;
while(T--){
ll ans=0;
top=0;
n=read();p=read();q=read();m=read();sa=read();sb=read();sc=read();
inc(i,1,n){
if(rng61()%(p+q)<p){
ll tmp=rng61()%m+1;
if(st[top]>=tmp)tmp=st[top];
st[++top]=tmp;
ans^=1ll*i*tmp;
}
else {
if(top)top--;
if(top)ans^=1ll*i*st[top];
}
}
printf("Case #%d: %lld\n",++kase,ans);
}
return 0;
}