fork(1) download
  1. // iostream is too mainstream
  2. #include <cstdio>
  3. // bitch please
  4. #include <iostream>
  5. #include <algorithm>
  6. #include <cstdlib>
  7. #include <vector>
  8. #include <set>
  9. #include <map>
  10. #include <queue>
  11. #include <stack>
  12. #include <list>
  13. #include <cmath>
  14. #include <iomanip>
  15. #define dibs reserve
  16. #define OVER9000 1234567890
  17. #define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
  18. #define tisic 47
  19. #define soclose 1e-8
  20. #define chocolate win
  21. // so much chocolate
  22. #define patkan 9
  23. #define ff first
  24. #define ss second
  25. #define abs(x) ((x < 0)?-(x):x)
  26. #define uint unsigned int
  27. #define dbl long double
  28. using namespace std;
  29. // mylittledoge
  30.  
  31. struct fin {
  32. vector<int> T;
  33. fin(int N) {T.resize(N+1,N+1);}
  34.  
  35. int lastone(int x) {return x&(x^(x-1));}
  36.  
  37. void put(int pos, int val) {
  38. for(int i =pos+1; i < T.size(); i +=lastone(i)) T[i] =min(T[i],val);
  39. }
  40.  
  41. int get(int pos) {
  42. int ret =OVER9000;
  43. for(int i =pos+1; i > 0; i -=lastone(i)) ret =min(ret,T[i]);
  44. return ret;}
  45. };
  46.  
  47. int main() {
  48. cin.sync_with_stdio(0);
  49. cin.tie(0);
  50. int T;
  51. cin >> T;
  52. for(int t =0; t < T; t++) {
  53. int N;
  54. cin >> N;
  55. vector< pair<int,int> > V(N);
  56. for(int i =0; i < N; i++) {
  57. int a,b,c;
  58. cin >> a >> b >> c;
  59. V[a-1] =make_pair(b,c);}
  60. fin F(N+tisic);
  61. int ans =0;
  62. for(int i =0; i < N; i++) {
  63. if(F.get(V[i].ff) > V[i].ss) ans++;
  64. F.put(V[i].ff,V[i].ss);}
  65. cout << ans << "\n";}
  66. return 0;}
  67.  
  68. // look at my code
  69. // my code is amazing
Success #stdin #stdout 0s 3436KB
stdin
3
3
2 3 2
3 2 3
1 1 1
3
1 2 3
2 3 1
3 1 2
10
1 7 10
3 9 7
2 2 9
5 10 8
4 3 5
7 5 2
6 1 3
9 6 6
8 4 4
10 8 1
stdout
1
3
7