fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. struct node {
  4. int d,c,x;
  5. }arr[350000];
  6. bool cmp(node a,node b){
  7. return a.d<b.d;
  8. }
  9. int n,m,t[350000],sum;
  10. int main(){
  11. cin>>n>>m;
  12. for(int i=1;i<=n;i++){
  13. cin>>arr[i].c>>arr[i].d>>arr[i].x;
  14. t[arr[i].c]++;
  15. }
  16. for(int i=1;i<=n;i++){
  17. if(t[i]>=1){
  18. sum++;
  19. }
  20. }
  21. sort(arr+1,arr+1+n,cmp);
  22. int l=1;
  23. for(int i=1;i<=m;i++){
  24. while(i>=arr[l].d && l<=n){
  25. if(t[arr[l].x]==0){
  26. sum++;
  27. }
  28. t[arr[l].x]++;
  29. if(t[arr[l].c]==1){
  30. sum--;
  31. }
  32. t[arr[l].c]--;
  33. l++;
  34. }
  35. cout<<sum;
  36. cout<<"\n";
  37. }
  38. return 0;
  39. }
Success #stdin #stdout 0s 5608KB
stdin
6 7
1 3 2
2 6 5
5 5 1
3 3 5
4 1 6
6 3 6
stdout
5
5
3
3
4
4
4