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,j=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. }
  56.  
  57.  
  58. public static void main (String[] args) throws java.lang.Exception
  59. {
  60. // your code goes here
  61. //BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  62. Scanner in = new Scanner(System.in);
  63. //int test = Integer.parseInt(br.readLine());
  64. int test = in.nextInt();
  65. while(test-->0)
  66. {
  67. //int num = Integer.parseInt(br.readLine());
  68. int num = in.nextInt();
  69. long list[] = new long[num+1];
  70. int i,j;
  71. for(i=0;i<num;i++)
  72. {
  73. list[i]= in.nextLong();
  74. }
  75. long a = in.nextLong();
  76. long b= in.nextLong();
  77. long c=in.nextLong();
  78. String s= in.next();
  79. for(i=0;i<num;i++)
  80. {
  81. if(s.charAt(i)=='R')
  82. reverse(list,c,i,num);
  83. else if(s.charAt(i)=='A')
  84. add(list,a,c,i,num);
  85. else if(s.charAt(i)=='M')
  86. multiply(list,b,c,i,num);
  87. }
  88. for(i=0;i<num;i++)
  89. {
  90. System.out.print((list[i]%c) + " ");
  91. }
  92. System.out.println("");
  93. }
  94.  
  95. }
  96. }
Success #stdin #stdout 0.1s 380672KB
stdin
3 
2 
1000000000000000000 1000000000000000000 
2 1000000000000000000 99999999999999999 
MM 
4 
1 2 3 4 
2 3 17 
AMAM 
10 
1 2 3 4 5 6 7 8 9 10 
2 5 3 
MMRRRRRRRR 
stdout
100 1000 
3 12 0 9 
2 2 1 0 0 1 2 2 1 0