Submission #1101299

# Submission time Handle Problem Language Result Execution time Memory
1101299 2024-10-16T03:57:54 Z tsengang Sterilizing Spray (JOI15_sterilizing) C++14
100 / 100
872 ms 11908 KB
#include <bits/stdc++.h>
#define ll long long
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using namespace std;
ll n,q,k;
struct segtree{
    int n;
    vector<ll>d;
    segtree(ll n){
        d.resize(4*n);
        build(1,1,n);
    }
    void build(ll v,ll l,ll r){
        if(l==r){
            d[v]=0;
            return;
        }
        ll m=(l+r)/2;
        build(v*2,l,m);
        build(v*2+1,m+1,r);
        d[v]=d[v*2]+d[v*2+1];
    }
    ll query(ll v,ll l,ll r,ll L,ll R){
        if(L>R||l>R||L>r) return 0;
        if(L<=l&&r<=R){
            return d[v];
        }
        ll m=(l+r)/2;
        return query(v*2,l,m,L,R)+query(v*2+1,m+1,r,L,R);
    }
    void update(ll v,ll l,ll r,ll pos,ll val){
        if(pos<l||r<pos) return;
        if(l==r){
            d[v]=val;
            return;
        }
        ll m=(l+r)/2;
        update(v*2,l,m,pos,val);
        update(v*2+1,m+1,r,pos,val);
        d[v]=d[v*2]+d[v*2+1];
    }
    void updater(ll node, ll L, ll R, ll l, ll r, ll val){
    if (L > R || L > r || R < l)
        return;
    if (L == R){
        d[node] /= val;
        return;
    }
    ll mid = (L + R) / 2;
    updater(node*2, L, mid, l, r, val);
    updater(node*2 + 1, mid + 1, R, l, r, val);
    d[node] = d[node*2] + d[node*2+1];
    }
    void update2(ll v,ll l,ll r,ll pos){
        if(pos<l||r<pos) return;
        if(l==r){
            d[v]/=k;
            return;
        }
        ll m=(l+r)>>1;
        update2(v*2,l,m,pos);
        update2(v*2+1,m+1,r,pos);
        d[v]=d[v*2]+d[v*2+1];
    }
};
int main() {
    cin >> n >> q >> k;
    ll a[n+2];
    segtree gang(n);
    set<ll>st;
    for(ll i = 1; i <= n; i++){
        cin >> a[i];
        gang.update(1,1,n,i,a[i]);
        if(a[i] > 0) st.insert(i);
    }
    while(q--){
        ll s,x,y;
        cin >> s >> x >> y;
        if(s == 1){
            gang.update(1,1,n,x,y);
            if(y > 0)st.insert(x);
        }
        if(s == 2){
            if(k == 1) continue;
            ll cur = x,i;
            while(!st.empty()){
                auto pos = st.lower_bound(cur);
                if(st.end() == pos || *pos > y)break;
                ll i = *pos;
                gang.update2(1,1,n,i);
                if(gang.query(1,1,n,i,i) == 0){
                    st.erase(i);
                }
                cur = *pos+1;
            }
        }
        if(s == 3){
            cout << gang.query(1,1,n,x,y) << '\n';
        }
    }
}

Compilation message

sterilizing.cpp: In function 'int main()':
sterilizing.cpp:88:24: warning: unused variable 'i' [-Wunused-variable]
   88 |             ll cur = x,i;
      |                        ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 336 KB Output is correct
2 Correct 2 ms 336 KB Output is correct
3 Correct 4 ms 764 KB Output is correct
4 Correct 11 ms 608 KB Output is correct
5 Correct 13 ms 592 KB Output is correct
6 Correct 10 ms 592 KB Output is correct
7 Correct 12 ms 768 KB Output is correct
8 Correct 14 ms 592 KB Output is correct
9 Correct 14 ms 764 KB Output is correct
10 Correct 11 ms 592 KB Output is correct
11 Correct 11 ms 764 KB Output is correct
12 Correct 12 ms 692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 6984 KB Output is correct
2 Correct 117 ms 5192 KB Output is correct
3 Correct 113 ms 9032 KB Output is correct
4 Correct 171 ms 11296 KB Output is correct
5 Correct 165 ms 11848 KB Output is correct
6 Correct 170 ms 11860 KB Output is correct
7 Correct 171 ms 11848 KB Output is correct
8 Correct 185 ms 11908 KB Output is correct
9 Correct 171 ms 11592 KB Output is correct
10 Correct 165 ms 11676 KB Output is correct
11 Correct 163 ms 11592 KB Output is correct
12 Correct 177 ms 11592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 1300 KB Output is correct
2 Correct 34 ms 3408 KB Output is correct
3 Correct 45 ms 3620 KB Output is correct
4 Correct 111 ms 3144 KB Output is correct
5 Correct 158 ms 8008 KB Output is correct
6 Correct 144 ms 8008 KB Output is correct
7 Correct 136 ms 8520 KB Output is correct
8 Correct 154 ms 7940 KB Output is correct
9 Correct 151 ms 7924 KB Output is correct
10 Correct 135 ms 8012 KB Output is correct
11 Correct 139 ms 7912 KB Output is correct
12 Correct 149 ms 8016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 243 ms 6500 KB Output is correct
2 Correct 235 ms 6728 KB Output is correct
3 Correct 362 ms 5432 KB Output is correct
4 Correct 270 ms 4972 KB Output is correct
5 Correct 400 ms 11544 KB Output is correct
6 Correct 492 ms 11760 KB Output is correct
7 Correct 402 ms 11592 KB Output is correct
8 Correct 647 ms 11668 KB Output is correct
9 Correct 516 ms 11716 KB Output is correct
10 Correct 597 ms 11596 KB Output is correct
11 Correct 423 ms 11464 KB Output is correct
12 Correct 872 ms 11436 KB Output is correct