fork download
  1. #include<iostream>
  2. #include<vector>
  3. #include<algorithm>
  4. #include<cmath>
  5.  
  6. using namespace std;
  7.  
  8. int main(){
  9. int n, q;
  10. cin >> n >> q;
  11. vector<int> v(n+1, 0);
  12. vector<int> a(n+1, 0);
  13. for(int i = 1; i <= n; i++){
  14. cin >> a[i];
  15. int k = i;
  16. while(k <= n){
  17. v[k] += a[i];
  18. k += k & -k;
  19. }
  20. }
  21.  
  22. while(q--){
  23. int type;
  24. cin >> type;
  25. cout << 10 - q << ":";
  26. if(type == 1){
  27. int k, u;
  28. cin >> k >> u;
  29. u -= a[k];
  30. while(k <= n){
  31. v[k] += u;
  32. k += k & -k;
  33. }
  34. cout<<endl;
  35. }
  36.  
  37. else if(type == 2){
  38. int a, b;
  39. cin >> a >> b;
  40. a--;
  41. for(int i = 1; i <= n; i++){
  42. cout << v[i] << " ";
  43. }
  44. int sa = 0, sb = 0;
  45. while (a > 0){
  46. sa += v[a];
  47. a -= a & -a;
  48. }
  49. while (b > 0){
  50. sb += v[b];
  51. b -= b & -b;
  52. }
  53. cout<< sb << sa << endl;
  54. }
  55. }
  56. }
  57.  
Success #stdin #stdout 0s 5280KB
stdin
8 10
10 9 6 10 10 3 6 7
1 1 6
1 2 5
1 3 7
1 4 4
1 5 6
1 6 2
1 7 7
1 8 7
2 1 1
2 1 2
stdout
1:
2:
3:
4:
5:
6:
7:
8:
9:6 11 7 22 6 8 7 44 60
10:6 11 7 22 6 8 7 44 110