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