Submission #871086

# Submission time Handle Problem Language Result Execution time Memory
871086 2023-11-09T20:59:41 Z Ahmed57 Weirdtree (RMI21_weirdtree) C++17
0 / 100
2000 ms 32224 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
long long arr[300001],n;
struct node{
    long long ma =0 , id = 0 , sum = 0;
}seg[1200001];
node combine(node a,node b){
    node res;
    res.sum = a.sum+b.sum;
    if(a.ma>=b.ma)res.ma = a.ma , res.id = a.id;
    else res.ma = b.ma , res.id = b.id;
    return res;
}
void build(int p,int l,int r){
    if(l==r){
        seg[p].ma = arr[l];
        seg[p].id = l;
        seg[p].sum = arr[l];
        return ;
    }
    int md = (l+r)/2;
    build(p*2,l,md);
    build(p*2+1,md+1,r);
    seg[p] =combine(seg[p*2],seg[p*2+1]);
}
void update(int p,int l,int r,int idx,int val,int op){
    if(l==r){
        if(op==0){
            seg[p].ma = val;
            seg[p].sum = val;
        }else{
            seg[p].ma = max(0ll,seg[p].ma+val);
            seg[p].sum = max(0ll,seg[p].sum+val);
        }
        return ;
    }
    int md = (l+r)/2;
    if(idx<=md)update(p*2,l,md,idx,val,op);
    else update(p*2+1,md+1,r,idx,val,op);
    seg[p] = combine(seg[p*2],seg[p*2+1]);
}
node query(int p,int l,int r,int lq,int rq){
    if(l>=lq&&r<=rq){
        return seg[p];
    }
    int md = (l+r)/2;
    if(rq<=md)return query(p*2,l,md,lq,rq);
    else if(lq>md)return query(p*2+1,md+1,r,lq,rq);
    else return combine(query(p*2,l,md,lq,rq),query(p*2+1,md+1,r,lq,rq));
}
bool ss = 0;
void initialise(int32_t N, int32_t Q,int32_t h[]){
    n = N;
    if(n<=2000)ss = 1;
    for(int i = 1;i<=n;i++){
        arr[i] = h[i];
    }
    build(1,1,n);
}
void cut(int32_t l, int32_t r, int32_t k){
    if(ss==0){
    node res = query(1,1,n,l,r);
    update(1,1,n,res.id,-1,1);
    }else{
    ss = 1;
    vector<int> v;
    for(int i = l;i<=r;i++){
        v.push_back(arr[i]);
    }
    sort(v.begin(),v.end());
    vector<int> xd;
    int all = 0;
    for(int i = v.size()-1;i>=0;i--){
        all+=v[i];
        xd.push_back(all);
    }
    reverse(xd.begin(),xd.end());
    int nah = 0;
    for(int i = v.size()-1;i>=0;i--){
        if(i&&v[i]==v[i-1])continue;
        int elem = v.size()-i;
        if(k-(xd[i]-(elem*v[i]))>=0){
            nah = i;
        }
    }
    int elem = v.size()-nah;
    long long num = v[nah]-((k-(xd[nah]-(elem*v[nah])))/elem);
    num = max(num,0ll);
    long long rem = k-(xd[nah]-(num*elem));
    for(int i = l;i<=r;i++){
        arr[i] = min(arr[i],num);
        if(arr[i]==num&&rem&&arr[i]!=0){
            arr[i]--;
            rem--;
        }
    }
    }
}
void magic(int32_t i, int32_t x){
    if(ss==0)update(1,1,n,i,x,0);
    else arr[i] = x;
}
long long inspect(int32_t l, int32_t r){
    if(ss==0){
        long long sum = 0;
    for(int i = l;i<=r;i++){
        sum+=arr[i];
    }
    return sum;
    }else{
    node res = query(1,1,n,l,r);
    return res.sum;
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 2652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2073 ms 32224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -