Submission #954515

# Submission time Handle Problem Language Result Execution time Memory
954515 2024-03-28T05:43:44 Z ezzzay Growing Trees (BOI11_grow) C++14
0 / 100
346 ms 6852 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);
            continue;
            for(int i=1;i<=n;i++){
               cout<<arr[i]+find(i)<<" ";
            }
            
            cout<<endl;
            
            cout<<p<<" "<<z-1<<" "<<t<<" "<<y<<endl;
        }
        else{
            int l,r ;
            cin>>l>>r;
            int y=findpos(r+1);
            int x=findpos(l);
            cout<<y<<" "<<x<<endl;
            ans.pb(y-x);
        }
    }
    for(auto a:ans)cout<<a<<endl;
}
# Verdict Execution time Memory Grader output
1 Incorrect 170 ms 5824 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 270 ms 3512 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 280 ms 3708 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 169 ms 4020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 179 ms 5092 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 203 ms 5716 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 219 ms 5376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 233 ms 5580 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 346 ms 6852 KB Output isn't correct
2 Halted 0 ms 0 KB -