Submission #954518

# Submission time Handle Problem Language Result Execution time Memory
954518 2024-03-28T05:44:50 Z ezzzay Growing Trees (BOI11_grow) C++14
100 / 100
216 ms 5872 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
#define pb push_back
const int N=2e5+5;
int bit[N];
int arr[N];
int n,q;
vector<int>ans;
void update(int idx, int val){
    if(idx==0)return;
    while(idx<N){
        bit[idx]+=val;
        idx+= idx & -idx;
    }
}
int find(int idx){
    if(idx==0)return 0;
    int s=0;
    while(idx>0){
        s+=bit[idx];
        idx-= idx & -idx;
    }
    return s;
}
int findpos(int h){
    int lo=1;
    int hi=n+1;
    while(hi>=lo){
        int mid=(hi+lo)/2;
        if(find(mid)+arr[mid]<h){
            lo=mid+1;
        }
        else{
            hi=mid-1;
        }
    }
    return lo;
}
signed main(){
    vector<int>v;
    cin>>n>>q;
    
    for(int i=1;i<=n;i++){
        int a;
        cin>>a;
        v.pb(a);
    }
    sort(v.begin(),v.end());
    for(int i=1;i<=n;i++){
        arr[i]=v[i-1];
    }
    arr[n+1]=2e9;
    cout<<endl;
    while(q--){
        char c;
        cin>>c;
        if(c=='F'){
            int x,h;
            cin>>x>>h;
            int lo=findpos(h);
            if(n-lo+1<=x){
                update(lo,1);

                continue;
            }
            
            int r= lo+x-1;
            int p=find(r)+arr[r];
            
            int z=findpos(p);
            
            update(lo,1);
            update(z,-1);
            
            int cnt=r-z+1;
            
            int y=findpos(p+1)-1;
            
            int t=max(1LL,y-cnt+1);
            update(t,1);
            update(y+1,-1);
           
        }
        else{
            int l,r ;
            cin>>l>>r;
            int y=findpos(r+1);
            int x=findpos(l);
            ans.pb(y-x);
        }
    }
    for(auto a:ans)cout<<a<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 129 ms 4320 KB Output is correct
2 Correct 158 ms 5716 KB Output is correct
3 Correct 68 ms 5060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 348 KB Output is correct
2 Correct 6 ms 452 KB Output is correct
3 Correct 9 ms 604 KB Output is correct
4 Correct 4 ms 604 KB Output is correct
5 Correct 130 ms 2568 KB Output is correct
6 Correct 168 ms 2844 KB Output is correct
7 Correct 7 ms 604 KB Output is correct
8 Correct 118 ms 2356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 1872 KB Output is correct
2 Correct 155 ms 2880 KB Output is correct
3 Correct 2 ms 604 KB Output is correct
4 Correct 134 ms 2556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 157 ms 1904 KB Output is correct
2 Correct 174 ms 2788 KB Output is correct
3 Correct 8 ms 604 KB Output is correct
4 Correct 158 ms 2868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 4016 KB Output is correct
2 Correct 147 ms 5320 KB Output is correct
3 Correct 43 ms 1508 KB Output is correct
4 Correct 58 ms 4548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 3800 KB Output is correct
2 Correct 154 ms 5572 KB Output is correct
3 Correct 68 ms 4800 KB Output is correct
4 Correct 39 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 113 ms 4240 KB Output is correct
2 Correct 125 ms 5424 KB Output is correct
3 Correct 70 ms 5096 KB Output is correct
4 Correct 39 ms 1492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 165 ms 4300 KB Output is correct
2 Correct 147 ms 5460 KB Output is correct
3 Correct 42 ms 4420 KB Output is correct
4 Correct 122 ms 5316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 151 ms 4556 KB Output is correct
2 Correct 164 ms 5872 KB Output is correct
3 Correct 125 ms 5436 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 216 ms 5056 KB Output is correct