fork download
  1. def interesting_subarrays():
  2. import sys
  3. input = sys.stdin.read
  4.  
  5. # Reading all input data at once
  6. data = input().split()
  7.  
  8. # Index to traverse the input data
  9. idx = 0
  10.  
  11. # Reading number of test cases
  12. t = int(data[idx])
  13. idx += 1
  14.  
  15. results = []
  16.  
  17. for _ in range(t):
  18. # Reading n and q
  19. n = int(data[idx])
  20. q = int(data[idx + 1])
  21. idx += 2
  22.  
  23. # Reading array elements
  24. arr = list(map(int, data[idx:idx + n]))
  25. idx += n
  26.  
  27. # Build prefix XOR array
  28. prefix_xor = [0] * (n + 1)
  29. for i in range(n):
  30. prefix_xor[i + 1] = prefix_xor[i] ^ arr[i]
  31.  
  32. for _ in range(q):
  33. l = int(data[idx])
  34. r = int(data[idx + 1])
  35. idx += 2
  36.  
  37. # Check total XOR of the range
  38. total_xor = prefix_xor[r] ^ prefix_xor[l - 1]
  39.  
  40. if total_xor == 0:
  41. results.append("YES")
  42. else:
  43. found = False
  44. for m in range(l, r):
  45. if prefix_xor[m] == prefix_xor[r]:
  46. found = True
  47. break
  48. if found:
  49. results.append("YES")
  50. else:
  51. results.append("NO")
  52.  
  53. # Output all results
  54. for res in results:
  55. print(res)
  56.  
  57. # To run the function, call it directly.
  58. # Please make sure to provide input through stdin, as specified in the problem statement.
  59.  
Success #stdin #stdout 0.04s 9516KB
stdin
4
5 5
1 1 2 3 0
1 5
2 4
3 5
1 3
3 4
5 5
1 2 3 4 5
1 5
2 4
3 5
1 3
2 3
7 4
12 9 10 9 10 11 9
1 5
1 7
2 6
2 7
11 4
0 0 1 0 0 1 0 1 1 0 1
1 2
2 5
6 9
7 11
stdout
Standard output is empty