Submission #484473

# Submission time Handle Problem Language Result Execution time Memory
484473 2021-11-03T16:09:51 Z Mahdi Sterilizing Spray (JOI15_sterilizing) C++17
5 / 100
44 ms 3660 KB
#include<bits/stdc++.h>
#pragma GCC optimize ("Ofast")
using namespace std;
#define all(v) v.begin(), v.end()
#define pii pair<int, int>
#define F first
#define S second
typedef long long ll;
const int N=1e5+5;
int n, q, k, sz, c[N], mx[N];
ll sg[N];

void st(int x){
    x+=sz-1;
    sg[x]=c[x-sz+1];
    while(x){
        --x;
        x/=2;
        mx[x]=(c[mx[2*x+1]]<c[mx[2*x+2]]? mx[2*x+2] : mx[2*x+1]);
        sg[x]=sg[2*x+1]+sg[2*x+2];
    }
}

ll sum(int x, int lx, int rx, int l, int r){
    if(lx>=r || rx<=l)
        return 0;
    if(lx>=l && rx<=r)
        return sg[x];
    int m=(lx+rx)/2;
    return sum(2*x+1, lx, m, l, r)+sum(2*x+2, m, rx, l, r);
}

int seg(int x, int lx, int rx, int l, int r){
    if(lx>=r || rx<=l)
        return n;
    if(lx>=l && rx<=r)
        return mx[x];
    int m=(lx+rx)/2;
    int L=seg(2*x+1, lx, m, l, r), R=seg(2*x+2, m, rx, l, r);
    return (c[L]<c[R] ? R : L);
}

void opr(int l, int r){
    if(k==1)
        return;
    vector<pii>v;
    int z=seg(0, 0, sz, l, r);
    while(c[z]){
        v.push_back({z, c[z]/k});
        c[z]=0;
        st(z);
        z=seg(0, 0, sz, l, r);
    }
    for(auto u:v){
        c[u.F]=u.S;
        st(u.F);
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin>>n>>q>>k;
    for(int i=0;i<n;++i){
        cin>>c[i];
    }
    sz=1;
    while(sz<n)
        sz<<=1;
    iota(mx+sz-1, mx+sz+n-1, 0);
    for(int i=sz-1;i<sz+n-1;++i)
        sg[i]=c[i-sz+1];
    for(int i=sz-2;i>=0;--i){
        sg[i]=sg[2*i+1]+sg[2*i+2];
        mx[i]=(c[mx[2*i+1]]<c[mx[2*i+2]] ? mx[2*i+2] : mx[2*i+1]);
    }
    int s, t, u;
    while(q--){
        cin>>s>>t>>u;
        if(s==1){
            c[--t]=u;
            st(t);
        }
        else if(s==2)
            opr(--t, u);
        else
            cout<<sum(0, 0, sz, --t, u)<<'\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 5 ms 332 KB Output is correct
4 Correct 16 ms 456 KB Output is correct
5 Correct 17 ms 548 KB Output is correct
6 Correct 10 ms 460 KB Output is correct
7 Correct 15 ms 548 KB Output is correct
8 Correct 15 ms 544 KB Output is correct
9 Correct 20 ms 548 KB Output is correct
10 Correct 14 ms 460 KB Output is correct
11 Correct 13 ms 460 KB Output is correct
12 Correct 17 ms 520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 3532 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 20 ms 920 KB Output is correct
2 Incorrect 44 ms 1992 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 7 ms 3660 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -