A 小甜甜
1 #include <iostream> 2 #include <cstdio> 3 #include <algorithm> 4 #include <cmath> 5 #include <vector> 6 #include <queue> 7 #include <set> 8 #include <map> 9 #include <string> 10 #include <string.h> 11 #include <stdlib.h> 12 #include <time.h> 13 #include <climits> 14 15 using namespace std; 16 17 const int maxN=5e6+7; 18 19 unsigned int sta[maxN]; 20 int to[maxN]; 21 int top=0; 22 23 int n,p,q,m; 24 unsigned int SA,SB,SC; 25 long long ans=0; 26 27 unsigned int rng61(){ 28 SA^=SA<<16; 29 SA^=SA>>5; 30 SA^=SA<<1; 31 unsigned int t=SA; 32 SA=SB; 33 SB=SC; 34 SC^=t^SA; 35 return SC; 36 } 37 38 void PUSH(unsigned int x,int i){ 39 //cerr<<"PUSH"<<x<<endl; 40 top++; 41 sta[top]=x; 42 43 if (x>sta[to[top-1]]) to[top]=top; 44 else to[top]=to[top-1]; 45 46 ans=ans^(1LL*sta[to[top]]*i); 47 } 48 49 void POP(int i){ 50 //cerr<<"POP"<<endl; 51 if (top==0) return; 52 top--; 53 if (top==0) return; 54 55 ans=ans^(1LL*sta[to[top]]*i); 56 } 57 58 void gen(){ 59 scanf("%d%d%d%d%u%u%u",&n,&p,&q,&m,&SA,&SB,&SC); 60 ans=top=0; 61 62 for (int i=1;i<=n;i++) { 63 if (rng61()%(p+q)<p) PUSH(rng61()%m+1,i); 64 else POP(i); 65 } 66 67 printf("%lld\n",ans); 68 } 69 70 71 int main(){ 72 int T; 73 scanf("%d",&T); 74 int kcase=0; 75 while (T--){ 76 printf("Case #%d: ",++kcase); 77 gen(); 78 } 79 return 0; 80 }