제출 #1355018

#제출 시각아이디문제언어결과실행 시간메모리
1355018iamhereforfunSterilizing Spray (JOI15_sterilizing)C++20
100 / 100
655 ms8892 KiB
// Starcraft 2 enjoyer //

#include <bits/stdc++.h>

// #pragma GCC target("avx2")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define LSOne(X) ((X) & -(X))
#define int long long

const int N = 1e5 + 5;
const int M = 2e6 + 5;
const long long K = (1LL << 60) - 1;
const int LG = 20;
const long long INF = 1e18 + 5;
const int C = 26;
const int B = 1000;
const int MOD = 1e9 + 9;

struct Fenwick
{
    vector<int> ft;
    int n;
    Fenwick(int len)
    {
        n = len;
        ft.assign(n + 1, 0);
    }
    void update(int pos, int val)
    {
        while (pos <= n)
        {
            ft[pos] += val;
            pos += LSOne(pos);
        }
    }
    int get(int pos)
    {
        int sum = 0;
        while (pos > 0)
        {
            sum += ft[pos];
            pos -= LSOne(pos);
        }
        return sum;
    }
    int get(int l, int r)
    {
        return get(r) - get(l - 1);
    }
};

int n, q, k, v[N];
set<pair<int, int>> st;

inline void solve()
{
    cin >> n >> q >> k;
    Fenwick ft(n);
    for (int x = 1; x <= n; x++)
    {
        cin >> v[x];
        st.insert({x, v[x]});
        ft.update(x, v[x]);
    }
    for (int x = 0; x < q; x++)
    {
        int t, a, b;
        cin >> t >> a >> b;
        if (t == 1)
        {
            if (v[a])
            {
                st.erase(st.lower_bound({a, 0}));
            }
            ft.update(a, -v[a]);
            v[a] = b;
            ft.update(a, v[a]);
            st.insert({a, v[a]});
        }
        else if (t == 2)
        {
            if (k == 1)
                continue;
            auto it = st.lower_bound({a, 0});
            while (it != st.end() && it->first <= b)
            {
                auto [i, j] = *it;
                ft.update(i, -j);
                // cout << i << " " << j << "\n";
                j /= k;
                ft.update(i, j);
                // cout << i << " " << j << "\n";
                v[i] = j;
                it++;
                st.erase(prev(it));
                if (j)
                {
                    st.insert({i, j});
                }
            }
        }
        else
        {
            cout << ft.get(a, b) << "\n";
        }
    }
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin >> t;
    for (int x = 1; x <= t; x++)
    {
        solve();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...