Submission #475461

# Submission time Handle Problem Language Result Execution time Memory
475461 2021-09-22T14:31:26 Z nicolaalexandra Sterilizing Spray (JOI15_sterilizing) C++14
0 / 100
397 ms 54972 KB
#include <bits/stdc++.h>
#define DIM 100010
#define INF 100000000000000LL
using namespace std;

struct segment_tree{
    long long v[50];
    int lazy;
} aint[DIM*4];

int n,k,q,i,j,x,y,tip,max_exp;
long long sol[50],v[DIM],p[50];

void update_nod (int nod){
    int fiu_st = nod<<1, fiu_dr = (nod<<1)|1;
    int t = 0;
    for (int i=0;i<=max_exp;i++){
        aint[nod].v[i] = aint[fiu_st].v[i] + aint[fiu_dr].v[i] + t;
        t = aint[nod].v[i] / k;
        aint[nod].v[i] %= k;
    }
}

void build (int nod, int st, int dr){

    if (st == dr){
        long long val = v[st];
        for (int i=max_exp;i>=0;i--){
            aint[nod].v[i] = val / p[i];
            val -= aint[nod].v[i] * p[i];
        }

        return;
    }
    int mid = (st+dr)>>1;
    build (nod<<1,st,mid);
    build ((nod<<1)|1,mid+1,dr);

    update_nod (nod);
}

void update_lazy (int nod, int st, int dr){
    if (!aint[nod].lazy)
        return;
    if (st != dr){
        int fiu_st = nod<<1, fiu_dr = (nod<<1)|1;
        int val = aint[nod].lazy;
        for (int i=0;i+val<=max_exp;i++){
            aint[fiu_st].v[i] = aint[fiu_st].v[i + val];
            aint[fiu_dr].v[i] = aint[fiu_dr].v[i + val];
        }

        aint[fiu_st].lazy += val;
        aint[fiu_dr].lazy += val;
    }
    aint[nod].lazy = 0;
}

void update_intv (int nod, int st, int dr, int x, int y){
    update_lazy (nod,st,dr);
    if (x <= st && dr <= y){

        for (int i=0;i<max_exp;i++)
            aint[nod].v[i] = aint[nod].v[i+1];

        aint[nod].lazy++;

        update_lazy (nod,st,dr);

        return;
    }
    int mid = (st+dr)>>1;
    if (x <= mid)
        update_intv (nod<<1,st,mid,x,y);
    if (y > mid)
        update_intv ((nod<<1)|1,mid+1,dr,x,y);

    update_lazy (nod<<1,st,mid);
    update_lazy ((nod<<1)|1,mid+1,dr);

    update_nod(nod);
}

void update (int nod, int st, int dr, int poz, int val){
    update_lazy (nod,st,dr);
    if (st == dr){

        for (int i=max_exp;i>=0;i--){
            aint[nod].v[i] = val / p[i];
            val -= aint[nod].v[i] * p[i];
        }

        return;
    }

    int mid = (st+dr)>>1;
    if (poz <= mid)
        update (nod<<1,st,mid,poz,val);
    else update ((nod<<1)|1,mid+1,dr,poz,val);

    update_lazy (nod<<1,st,mid);
    update_lazy ((nod<<1)|1,mid+1,dr);

    update_nod (nod);
}

void query (int nod, int st, int dr, int x, int y){
    update_lazy (nod,st,dr);
    if (x <= st && dr <= y){

        int t = 0;
        for (int i=0;i<=max_exp;i++){
            sol[i] += aint[nod].v[i] + t;
            t = sol[i] / k;
            sol[i] %= k;
        }

        return;
    }
    int mid = (st+dr)>>1;
    if (x <= mid)
        query (nod<<1,st,mid,x,y);
    if (y > mid)
        query ((nod<<1)|1,mid+1,dr,x,y);

}

int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>n>>q>>k;
    for (i=1;i<=n;i++)
        cin>>v[i];

    p[0] = 1;
    for (i=1;i<=50;i++){
        if (p[i-1] >  INF / k)
            break;

        p[i] = p[i-1] * k;
    }

    max_exp = i-1;


    build (1,1,n);

    for (;q--;){

        cin>>tip>>x>>y;
        if (tip == 1)
            update (1,1,n,x,y);
        else {
            if (tip == 2)
                update_intv (1,1,n,x,y);
            else {
                for (int i=0;i<=max_exp;i++)
                    sol[i] = 0;
                query (1,1,n,x,y);

                long long ans = 0;
                for (int i=0;i<=max_exp;i++)
                    ans += p[i] * sol[i];

                cout<<ans<<"\n";
            }
        }

    }


    return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 460 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 343 ms 54972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 183 ms 7356 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 397 ms 54780 KB Output isn't correct
2 Halted 0 ms 0 KB -