Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<string.h>
- typedef unsigned long long int ll;
- ll a[1000000];
- char s[1000000];
- ll mul(ll a1,ll b1,ll c1)
- {
- ll pro=0;
- b1=b1%c1;
- while(a1)
- {
- if(a1&1)
- {
- pro=pro+=b1;
- if(pro>c1) pro=pro-c1;
- }
- a1>>=1;
- b1<<=1;
- if(b1>c1)
- b1=b1-c1;
- }
- return pro;
- }
- #define getcx getchar_unlocked
- inline void fscan(ll *a )
- {
- ll n=0; int ch = getcx(); int sign = 1;
- while(ch < '0' || ch > '9')
- {
- if(ch == '-') sign=-1; ch = getcx();
- }
- while(ch >= '0' && ch <= '9')
- {
- n = (n << 3) + (n << 1) + ch - '0', ch = getcx();
- }
- *a = n * sign;
- }
- int main()
- {
- ll i,j,k,l,m,n,t,x,y,z,temp1,temp2;
- fscan(&t);
- while(t--)
- {
- fscan(&n);
- for(i=0;i<n;i++)
- fscan(&a[i]);
- fscan(&x);
- fscan(&y);
- fscan(&z);
- scanf("%s",s);
- l=strlen(s);
- ll end=n-1,count=n,min=0,max=n-1,revcount=0;
- i=0;
- for(count=0;count<n;count++)
- {
- if(s[count]=='A')
- {
- for(j=min;j<=max;j++)
- {
- a[j]=(a[j]+x)%z;
- }
- printf("%lld ",a[i]);
- if(((revcount&1))==1) i--;
- else i++;
- }
- else if(s[count]=='M')
- {
- for(j=min;j<=max;j++)
- {
- a[j]=mul(a[j],y,z);
- }
- printf("%lld ",a[i]);
- if(((revcount&1))==1) i--;
- else i++;
- }
- else
- {
- printf("%lld ",a[end]%z);
- if(end>=i)
- temp1=end-1;
- else
- temp1=end+1;
- temp2=temp1;
- temp1=i;
- i=temp2;
- end=temp1;
- revcount++;
- if(end>i)
- {
- min=i;max=end;
- }
- else
- {
- min=end;max=i;
- }
- }
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment