Submission #1290957

#TimeUsernameProblemLanguageResultExecution timeMemory
1290957icebearSterilizing Spray (JOI15_sterilizing)C++20
100 / 100
120 ms6772 KiB
// ~~ icebear ~~
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;

template<class T>
    bool minimize(T &a, const T &b) {
        if (a > b) return a = b, true;
        return false;
    }

template<class T>
    bool maximize(T &a, const T &b) {
        if (a < b) return a = b, true;
        return false;
    }

#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebear"
/*END OF TEMPLATE. ICEBEAR AND THE CAT WILL WIN VOI26 */

const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll INF = 1e18 + 27092008;
const int N = 2e5 + 5;
int n, q, k, a[N];
set<int> pos;
ll ft[N];

void update(int x, int val) {
    for(; x <= n; x += x & -x) ft[x] += val;
}

ll get(int x) {
    ll ans = 0;
    for(; x; x -= x & -x) ans += ft[x];
    return ans;
}

void init(void) {
    cin >> n >> q >> k;
    FOR(i, 1, n) cin >> a[i];
}

void process(void) {
    FOR(i, 1, n) if (a[i] > 0)
        pos.insert(i), update(i, a[i]);
    while(q--) {
        int t; cin >> t;
        if (t == 1) {
            int x, b; cin >> x >> b;
            update(x, b - a[x]);
            if (a[x] > 0) pos.erase(x);
            a[x] = b;
            if (a[x] > 0) pos.insert(x);
        } else if (t == 2) {
            vector<int> tmp;
            int l, r; cin >> l >> r;
            if (k == 1) continue;
            auto it = pos.lower_bound(l);
            while(it != pos.end()) {
                if (*it > r) break;
                update(*it, a[*it] / k - a[*it]);
                a[*it] /= k;
                if (a[*it] == 0) tmp.pb(*it);
                it++;
            }
            for(int x : tmp) pos.erase(x);
        } else {
            int l, r; cin >> l >> r;
            cout << get(r) - get(l - 1) << '\n';
        }
    }
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if (fopen(task".inp", "r")) {
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    int tc = 1;
//    cin >> tc;
    while(tc--) {
        init();
        process();
    }
    return 0;
}

Compilation message (stderr)

sterilizing.cpp: In function 'int main()':
sterilizing.cpp:93:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:94:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...