답안 #871089

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871089 2023-11-09T21:01:47 Z Ahmed57 Weirdtree (RMI21_weirdtree) C++17
21 / 100
211 ms 40008 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<=1000&&Q<=1000)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{
    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){
        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;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2396 KB Output is correct
2 Correct 5 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2396 KB Output is correct
2 Correct 5 ms 2396 KB Output is correct
3 Correct 36 ms 11104 KB Output is correct
4 Correct 36 ms 10832 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2392 KB Output is correct
2 Correct 3 ms 2648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 2392 KB Output is correct
2 Correct 3 ms 2648 KB Output is correct
3 Correct 211 ms 38764 KB Output is correct
4 Correct 198 ms 40008 KB Output is correct
5 Correct 186 ms 39856 KB Output is correct
6 Correct 197 ms 39804 KB Output is correct
7 Incorrect 14 ms 10320 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 14 ms 10320 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2396 KB Output is correct
2 Correct 5 ms 2396 KB Output is correct
3 Correct 36 ms 11104 KB Output is correct
4 Correct 36 ms 10832 KB Output is correct
5 Correct 7 ms 2392 KB Output is correct
6 Correct 3 ms 2648 KB Output is correct
7 Incorrect 14 ms 10320 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 2396 KB Output is correct
2 Correct 5 ms 2396 KB Output is correct
3 Correct 36 ms 11104 KB Output is correct
4 Correct 36 ms 10832 KB Output is correct
5 Correct 7 ms 2392 KB Output is correct
6 Correct 3 ms 2648 KB Output is correct
7 Correct 211 ms 38764 KB Output is correct
8 Correct 198 ms 40008 KB Output is correct
9 Correct 186 ms 39856 KB Output is correct
10 Correct 197 ms 39804 KB Output is correct
11 Incorrect 14 ms 10320 KB Output isn't correct
12 Halted 0 ms 0 KB -