제출 #1331649

#제출 시각아이디문제언어결과실행 시간메모리
133164912345678Sterilizing Spray (JOI15_sterilizing)C++17
100 / 100
113 ms8716 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long

const int nx=1e5+5;

ll n, q, k, a[nx], t, l ,r, x, y;
map<ll, ll> mp;

struct fenwick
{
    ll f[nx];
    void add(int i, ll x) {while (i<=n) f[i]+=x, i+=(i&-i);}
    ll query(int i)
    {
        ll res=0;
        while (i) res+=f[i], i-=(i&-i);
        return res;
    }
} f;

int main()
{
    cin.tie(NULL)->sync_with_stdio(false);
    cin>>n>>q>>k;
    for (int i=1; i<=n; i++) cin>>a[i], mp[i]=a[i], f.add(i, a[i]);
    while (q--)
    {
        cin>>t>>l>>r;
        if (t==1)
        {
            f.add(l, r-a[l]);
            mp[l]=a[l]=r;
        }
        if (t==2)
        {
            if (k==1) continue;
            for (auto itr=mp.lower_bound(l); itr!=mp.end()&&itr->first<=r; )
            {
                if (itr->second<k) f.add(itr->first, -a[itr->first]), a[itr->first]=0, itr=mp.erase(itr);
                else f.add(itr->first, -itr->second+(itr->second/k)), a[itr->first]=itr->second=itr->second/k, itr++;
            }
        }
        if (t==3) cout<<f.query(r)-f.query(l-1)<<'\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...