fork download
  1. for ii in range(int(input())):
  2. segs = {}
  3. N=int(input())
  4.  
  5. for k in range(N):
  6. X=input().split()
  7. L=int(X[0])
  8. R=int(X[1])
  9. V=X[2]
  10. fault=0
  11. if(V not in segs):
  12. segs[V]=[[[L,R]],1]
  13. else:
  14. flg1=0
  15. for i in range(0,len(segs[V][0])):
  16. if(segs[V][1]==3):
  17. fault=1
  18. break
  19. if(R<segs[V][0][i][0] or L>segs[V][0][i][1]):
  20. continue
  21. else:
  22. if(L<segs[V][0][i][0]):
  23. if(R>segs[V][0][i][1]):
  24. segs[V][0][i][0]=L
  25. segs[V][0][i][1]=R
  26. else:
  27. segs[V][0][i][0]=L
  28. else:
  29. if(R>segs[V][0][i][1]):
  30. segs[V][0][i][1]=R
  31. segs[V][1]+=1
  32. flg1=1
  33.  
  34. if(flg1!=1):
  35. segs[V][0].append([L,R])
  36. if(fault==1):
  37. break
  38. if(fault==1):
  39. print("NO")
  40. else:
  41. print("YES")
Success #stdin #stdout 0.02s 9404KB
stdin
2
4
5 7 2
4 6 1
1 5 2
6 8 1
4
1 2 1
1 2 1
1 2 1
1 2 1
stdout
YES
NO