Submission #695401

#TimeUsernameProblemLanguageResultExecution timeMemory
695401tamthegodSterilizing Spray (JOI15_sterilizing)C++17
100 / 100
350 ms8140 KiB
// Make the best become better
// No room for laziness
#include<bits/stdc++.h>

#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, q, k;
int a[maxN];
struct TNode
{
    int sum, _max;
    TNode operator + (const TNode& other) const
    {
        TNode tmp;
        tmp.sum = sum + other.sum;
        tmp._max = max(_max, other._max);
        return tmp;
    }
} st[4 * maxN];
void build(int id, int l, int r)
{
    if(l == r)
    {
        st[id] = {a[l], a[l]};
        return;
    }
    int mid = (l + r) / 2;
    build(id * 2, l, mid);
    build(id * 2 + 1, mid + 1, r);
    st[id] = st[id * 2] + st[id * 2 + 1];
}
void update(int id, int l, int r, int u, int v)
{
    if(l > v || r < u || !st[id]._max) return;
    if(l == r)
    {
        st[id].sum /= k;
        st[id]._max /= k;
        return;
    }
    int mid = (l + r) / 2;
    update(id * 2, l, mid, u, v);
    update(id * 2 + 1, mid + 1, r, u, v);
    st[id] = st[id * 2] + st[id * 2 + 1];
}
void update1(int id, int l, int r, int pos, int val)
{
    if(l == r)
    {
        st[id] = {val, val};
        return;
    }
    int mid = (l + r) / 2;
    if(pos <= mid) update1(id * 2, l, mid, pos, val);
    else update1(id * 2 + 1, mid + 1, r, pos, val);
    st[id] = st[id * 2] + st[id * 2 + 1];
}
int get(int id, int l, int r, int u, int v)
{
    if(l > v || r < u) return 0;
    if(l >= u && r <= v) return st[id].sum;
    int mid = (l + r) / 2;
    return get(id * 2, l, mid, u, v) + get(id * 2 + 1, mid + 1, r, u, v);
}
void ReadInput()
{
    cin >> n >> q >> k;
    for(int i=1; i<=n; i++)
        cin >> a[i];
}
void Solve()
{
    build(1, 1, n);
    while(q--)
    {
        int type;
        cin >> type;
        if(type == 1)
        {
            int a, b;
            cin >> a >> b;
            update1(1, 1, n, a, b);
        }
        else if(type == 2)
        {
            int l, r;
            cin >> l >> r;
            if(k > 1) update(1, 1, n, l, r);
        }
        else
        {
            int l, r;
            cin >> l >> r;
            cout << get(1, 1, n, l, r) << '\n';
        }
    }
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...