fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3. #define fi first
  4. #define se second
  5. #define pb push_back
  6. #define pf push_front
  7. #define ii pair<ll, ll>
  8. #define int long long
  9. using namespace std;
  10.  
  11. const ll N = 2e5+7;
  12. const ll inf = 1e18;
  13. const ll mod = 1e9+7;
  14.  
  15. int n,q;
  16. int a[N];
  17.  
  18. int tree[200007];
  19. int sie=200007;
  20.  
  21. void update(int id,int v){
  22. while(id<sie){
  23. tree[id]=((tree[id]+v)+mod)%mod;
  24. id+=id&-id;
  25. }
  26. }
  27.  
  28. int get(int id){
  29. int sum=0;
  30. while(id>0){
  31. sum=(sum+tree[id]+mod)%mod;
  32. id-=id&-id;
  33. }
  34. return sum;
  35. }
  36.  
  37.  
  38.  
  39. void solve() {
  40.  
  41. cin >> n >> q;
  42. for(int i=1;i<=n;i++){
  43. cin >> a[i];
  44. update(i,a[i]);
  45. }
  46. while(q--){
  47. int o,b,c;
  48. cin >> o >> b >> c;
  49. if(o==1){
  50. update(b,c-a[b]);
  51. }
  52. else{
  53. cout << get(c)-get(b-1) << '\n';
  54. }
  55. }
  56. }
  57. main(){
  58. ios_base::sync_with_stdio(false); cin.tie(NULL);
  59. // int t; cin >> t;
  60. // while(t--)
  61. solve();
  62. }
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty