fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5.  
  6. int n,q;
  7. cin>>n>>q;
  8.  
  9. vector<int> numbers(n);
  10.  
  11. for(auto& number: numbers){
  12. cin>>number;
  13. }
  14.  
  15. vector<pair<int,int>> queries(q);
  16.  
  17. for(auto& query: queries){
  18. cin>>query.first>>query.second;
  19. }
  20.  
  21.  
  22. vector<int> updates(n+1,0);
  23.  
  24.  
  25. for(auto& query: queries){
  26. updates[query.first]++;
  27. updates[query.second+1]--;
  28. }
  29.  
  30. for(int i=0; i<n; i++){
  31. updates[i+1] = updates[i+1] + updates[i];
  32.  
  33. numbers[i] += updates[i];
  34. cout<<numbers[i]<<" ";
  35. }
  36.  
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5320KB
stdin
10 2
0 0 0 0 0 0 0 0 0 0
3 5
4 8
stdout
0 0 0 1 2 2 1 1 1 0