fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. /* Name of the class has to be "Main" only if the class is public. */
  6. class Ideone
  7. {
  8. public static void add(long list[],long a,long c,int s,int num)
  9. {
  10. for(int i=s;i<num;i++)
  11. {
  12. list[i] = (list[i]%c + a%c)%c;
  13. }
  14. }
  15.  
  16. public static long mulmod(long val,long b,long c)
  17. {
  18. long temp = b;
  19. if(val<=10000000000L && b<=1000000000L)
  20. {
  21. long ret = ((val%c)*(temp%c))%c;
  22. return ret;
  23. }
  24.  
  25. long ret = 0L;
  26. val=val%c;
  27. while(temp > 0L){
  28. if(temp%2!=0) {
  29. ret =(ret+val)%c;
  30. }
  31. val = (val<<1L)%c;
  32. temp>>=1L;
  33. }
  34. return (ret%c);
  35. }
  36.  
  37. public static void multiply(long list[],long b,long c,int s, int num)
  38. {
  39. for(int i=s;i<num;i++)
  40. {
  41. list[i]=mulmod(list[i],b,c);
  42. }
  43. }
  44.  
  45. public static void reverse(long list[],long c,int s,int num)
  46. { int to=num-1;
  47. /* while(s<j)
  48.   {
  49.   long temp = list[s]%c;
  50.   list[s]=list[j]%c;
  51.   list[j]=temp;
  52.   s++;
  53.   j--;
  54.   }*/
  55. for(int j=s;j<to;j++,to--){
  56. list[j]^=list[to]^=list[j]^=list[to];
  57. }
  58. }
  59.  
  60.  
  61. public static void main (String[] args) throws java.lang.Exception
  62. {
  63. // your code goes here
  64. //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  65. Scanner in = new Scanner(System.in);
  66. //int test = Integer.parseInt(br.readLine());
  67. int test = in.nextInt();
  68. while(test-->0)
  69. {
  70. //int num = Integer.parseInt(br.readLine());
  71. int num = in.nextInt();
  72. long list[] = new long[num+1];
  73. int i,j;
  74. for(i=0;i<num;i++)
  75. {
  76. list[i]= in.nextLong();
  77. }
  78. long a = in.nextLong();
  79. long b= in.nextLong();
  80. long c=in.nextLong();
  81. String s= in.next();
  82. for(i=0;i<num;i++)
  83. {
  84. if(s.charAt(i)=='R')
  85. reverse(list,c,i,num);
  86. else if(s.charAt(i)=='A')
  87. add(list,a,c,i,num);
  88. else if(s.charAt(i)=='M')
  89. multiply(list,b,c,i,num);
  90. }
  91. for(i=0;i<num;i++)
  92. {
  93. System.out.print((list[i]%c) + " ");
  94. }
  95. System.out.println("");
  96. }
  97.  
  98. }
  99. }
Success #stdin #stdout 0.09s 380672KB
stdin
2
3
1 1 1
2 3 1000
ARM
4
1 2 3 4
0 1 1000
AMAM
stdout
3 0 9 
1 2 3 4