fork(4) download
  1. T = int(input())
  2. for t in range(T):
  3. N = int(input())
  4. A = list(map(int, input().split()))
  5.  
  6. Acopy = A[:]
  7. Acopy.sort()
  8. k = 1
  9. replacement = {}
  10. for x in Acopy:
  11. if x not in replacement:
  12. replacement[x] = k
  13. k += 1
  14.  
  15. A = [replacement[Ai] for Ai in A]
  16.  
  17. last = [-1]*100005
  18. for i in range(len(A)-1, -1, -1):
  19. if last[A[i]]==-1:
  20. last[A[i]] = i
  21.  
  22. pre = [-1]*100005
  23. pre[0] = last[0]
  24. for i in range(1, len(last)):
  25. pre[i] = max(pre[i-1], last[i])
  26.  
  27. best = 0
  28. for i in range(N):
  29. subarray_size = pre[A[i]] - i + 1
  30. best = max(best, subarray_size)
  31.  
  32. print(best)
Success #stdin #stdout 0.14s 27712KB
stdin
4
5
5 4 3 2 1
5
4 4 4 4 4
4
1 2 3 4
5
1 3 5 2 4
stdout
5
5
1
3