fork download
  1. #include <iostream>
  2. #include<bits/stdc++.h>
  3. #define fo(i,start,end) for(int i=start;i<end;i++)
  4. using namespace std;
  5.  
  6. int main() {
  7. // your code goes here
  8. int n;
  9. cin>>n;
  10. vector<int>arr(n+1,0);
  11. int q;
  12. cin>>q;
  13. while(q--){
  14. int l,r;
  15. cin>>l>>r;
  16. arr[l] += 1;
  17. arr[r+1] += -1;
  18. }
  19. vector<int>prefix(n+1,0);
  20. fo(i,1,n){
  21. prefix[i] += prefix[i-1]+arr[i];
  22. }
  23. fo(i,1,n){
  24. cout<<prefix[i]<<" ";
  25. }
  26. cout<<endl;
  27.  
  28. return 0;
  29. }
Success #stdin #stdout 0s 5320KB
stdin
10
2
3 5 
4 7
stdout
0 0 1 2 2 1 1 0 0