fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Solution {
  6. public static void main(String [] args){
  7. Scanner sc = new Scanner(System.in);
  8. long t = sc.nextLong();
  9.  
  10. while (t-- > 0) {
  11. long m = sc.nextLong();
  12. int n = sc.nextInt();
  13.  
  14. boolean[] isInGroup1 = new boolean[n + 1];
  15. boolean[] isInGroup2 = new boolean[n + 1];
  16.  
  17. long totalSum1 = 0, totalCount1 = 0;
  18. long totalSum2 = 0, totalCount2 = 0;
  19.  
  20. for (int i = 1; i <= n; i++) {
  21. int b = sc.nextInt();
  22. if (b == 1 || b == 3) {
  23. isInGroup1[i] = true;
  24. totalCount1++;
  25. totalSum1 += i;
  26. }
  27. if (b == 2 || b == 3) {
  28. isInGroup2[i] = true;
  29. totalCount2++;
  30. totalSum2 += i;
  31. }
  32. }
  33.  
  34. long countLeft1 = 0, countRight1 = totalCount1;
  35. long countLeft2 = 0, countRight2 = totalCount2;
  36.  
  37. long r1 = totalSum1 - totalCount1;
  38. long r2 = totalSum2 - totalCount2;
  39.  
  40. System.out.print(Math.abs(r1 - r2));
  41.  
  42. for (int i = 2; i <= n; i++) {
  43. if (isInGroup1[i - 1]) {
  44. countLeft1++;
  45. countRight1--;
  46. }
  47. if (isInGroup2[i - 1]) {
  48. countLeft2++;
  49. countRight2--;
  50. }
  51.  
  52. r1 = r1 + countLeft1 - countRight1;
  53. r2 = r2 + countLeft2 - countRight2;
  54. System.out.print(" " + Math.abs(r1 - r2));
  55. }
  56. System.out.println();
  57. }
  58. sc.close();
  59. }
  60. }
  61.  
Success #stdin #stdout 0.22s 59020KB
stdin
2
1 5
2 1 3 0 1
1 8
1 1 3 0 2 0 3 3
stdout
5 2 1 0 1
3 2 1 4 7 8 9 10