1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| #include<bits/stdc++.h> using namespace std; namespace IO{ int c; unsigned int seed; unsigned int randnum(){seed^=seed<<13;seed^=seed>>17;seed^=seed<<5;return seed;} inline int read(int &x){scanf("%d",&x);return x;} inline void init_case(int &m,int &a,int &b,int &d,int p[]){scanf("%d%u%d%d%d%d",&m,&seed,&a,&b,&c,&d);for(int i=1;i<=m;i++){if(randnum()%c==0)p[i]=-1;else p[i]=randnum()%b;}} inline void update_ans(unsigned int &ans_sum,unsigned int cur_ans,int no){const static unsigned int mod=998244353;ans_sum^=(long long)no*(no+7)%mod*cur_ans%mod;} } void write(int x){if(x<0) putchar('-'),x=-x;if(x<10) putchar(x+'0');else{write(x/10);putchar(x%10+'0');}} unsigned int ans_sum; int T,m,a,b,d,ans,p[4000010],f[4000010],vis[4000010],num[4000010],h,t,g[4000010]; bool did[4000010],tag; queue<int> q; namespace Solve{ inline void Step1(int x){vis[x]=1;did[x]=1;while(vis[ans]&&ans<=b) ans++;} inline void Step2(int x){if(d==1){tag=1;return ;}did[x]=0;q.push(x);while(h<=t&&g[t]>x) t--;g[++t]=x;} inline void Step3(){if(dq.empty()){tag=1;return ;}did[q.front()]=1;q.pop();} } signed main(){ IO::read(T); while(T--){ IO::init_case(m,a,b,d,p); for(int i=0;i<=a;i++) vis[i]=1,did[i]=1; for(int i=a+1;i<=b;i++) vis[i]=0,did[i]=0; ans=a+1;h=1;t=0;tag=0;ans_sum=0; while(!q.empty()) q.pop(); for(int i=1;i<=m;i++){ tag=0; if(p[i]==-1) Solve::Step3(); else if(vis[p[i]]==0) Solve::Step1(p[i]); else if(did[p[i]]) Solve::Step2(p[i]); else Solve::Step3(); if(tag==1) continue ; while(h<=t&&did[g[h]]) h++; if(h>t) IO::update_ans(ans_sum,ans,i); else IO::update_ans(ans_sum,min(ans,g[h]),i); } write(ans_sum);putchar('\n'); } }
|