Submission #871076

# Submission time Handle Problem Language Result Execution time Memory
871076 2023-11-09T20:20:28 Z Ahmed57 Weirdtree (RMI21_weirdtree) C++17
13 / 100
85 ms 38552 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));
}
void initialise(int32_t N, int32_t Q,int32_t h[]){
    n = N;
    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){
    node res = query(1,1,n,l,r);
    update(1,1,n,res.id,-1,1);
}
void magic(int32_t i, int32_t x){
    update(1,1,n,i,x,0);
}
long long inspect(int32_t l, int32_t r){
    node res = query(1,1,n,l,r);
    return res.sum;
}
/*
signed main(){
    ios_base::sync_with_stdio(false);cin.tie(0);
    initialise(6,1,{0,1,2,3,1,2,3});
    cut(1,6,3);
    cout<<inspect(1,6)<<endl;
}*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 36 ms 9508 KB Output is correct
4 Correct 34 ms 9436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 85 ms 35252 KB Output is correct
2 Correct 76 ms 38552 KB Output is correct
3 Incorrect 13 ms 11136 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 36 ms 9508 KB Output is correct
4 Correct 34 ms 9436 KB Output is correct
5 Incorrect 1 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 36 ms 9508 KB Output is correct
4 Correct 34 ms 9436 KB Output is correct
5 Incorrect 1 ms 2396 KB Output isn't correct
6 Halted 0 ms 0 KB -