Submission #529170

#TimeUsernameProblemLanguageResultExecution timeMemory
529170AdamGSSterilizing Spray (JOI15_sterilizing)C++17
100 / 100
1398 ms9716 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e5+7;
ll tr[4*LIM], N=1;
set<int>S;
void upd(int v, ll x) {
  v+=N;
  tr[v]=x;
  v/=2;
  while(v) {
    tr[v]=tr[2*v]+tr[2*v+1];
    v/=2;
  }
}
ll cnt(int l, int r) {
  l+=N; r+=N;
  ll ans=tr[l];
  if(l!=r) ans+=tr[r];
  while(l/2!=r/2) {
    if(l%2==0) ans+=tr[l+1];
    if(r%2==1) ans+=tr[r-1];
    l/=2; r/=2;
  }
  return ans;
}

int main() {
  int n, q, k;
  cin >> n >> q >> k;
  while(N<n) N*=2;
  rep(i, n) {
    cin >> tr[N+i];
    if(tr[N+i]) S.insert(i);
  }
  S.insert(n);
  for(int i=N-1; i; --i) tr[i]=tr[2*i]+tr[2*i+1];
  while(q--) {
    int t, a, b;
    cin >> t >> a >> b;
    if(t==1) {
      --a;
      auto it=S.lower_bound(a);
      if((*it)==a) S.erase(a);
      upd(a, b);
      if(b) S.insert(a);
    } else if(t==2) {
      --a; --b;
      if(k>1) {
        while(a<=b) {
          auto it=S.lower_bound(a);
          a=*it;
          if(a>b) break;
          S.erase(a);
          upd(a, tr[N+a]/k);
          if(tr[N+a]) S.insert(a);
          ++a;
        }
      }
    } else {
      --a; --b;
      cout << cnt(a, b) << '\n';
    }
  }
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...