Submission #153375

# Submission time Handle Problem Language Result Execution time Memory
153375 2019-09-13T19:15:17 Z brcode Growing Trees (BOI11_grow) C++14
0 / 100
560 ms 7700 KB
#include <iostream>
#include <algorithm>
using namespace std;
const long long MAXN = 1e5+5;
long long arr[MAXN];
pair<long long,long long> seg[4*MAXN];
long long lazy[4*MAXN];
void push(long long curr,long long l,long long r){
    if(!lazy[curr]){
        return;
    }
    seg[curr].first+=lazy[curr];
    seg[curr].second+=lazy[curr];
    if(l!=r){
        lazy[2*curr]+=lazy[curr];
        lazy[2*curr+1]+=lazy[curr];
    }
    lazy[curr] = 0;
}
void build(long long curr,long long l,long long r){
    if(l==r){
        seg[curr].first = arr[l];
        seg[curr].second = arr[l];
        return;
    }
    long long mid = (l+r)/2;
    build(2*curr,l,mid);
    build(2*curr+1,mid+1,r);
    seg[curr].first = max(seg[2*curr].first,seg[2*curr+1].first);
    seg[curr].second = min(seg[2*curr].second,seg[2*curr+1].second);
}
long long atpos(long long curr,long long l,long long r,long long pos){
    if(lazy[curr]){
        push(curr,l,r);
    }
    if(l==r){
        return seg[curr].first;
    }
    long long mid = (l+r)/2;
    push(2*curr+1,mid+1,r);
    push(2*curr,l,mid);
    if(pos<=mid){
        return atpos(2*curr,l,mid,pos);
    }else{
        return atpos(2*curr+1,mid+1,r,pos);
    }

}
long long firstpos(long long curr,long long l,long long r,long long val){

    if(lazy[curr]){
        push(curr,l,r);
    }
    if(l==r){
        return l;
    }
    long long mid = (l+r)/2;
    push(2*curr+1,mid+1,r);
    push(2*curr,l,mid);
    if(seg[2*curr].first>=val){
        return firstpos(2*curr,l,mid,val);
    }else{
        return firstpos(2*curr+1,mid+1,r,val);
    }
}
long long lastpos(long long curr,long long l,long long r,long long val){
    if(lazy[curr]){
        push(curr,l,r);
    }
    if(l==r){
        return l;
    }
    long long mid =(l+r)/2;
    push(2*curr+1,mid+1,r);
    push(2*curr,l,mid);
    if(seg[2*curr+1].second<=val){
        return lastpos(2*curr+1,mid+1,r,val);
    }else{
        return lastpos(2*curr,l,mid,val);
    }
}
void update(long long curr,long long l,long long r,long long tl,long long tr){
    if(l>r){
        return;
    }
    if(lazy[curr]){
        push(curr,l,r);
    }
    if(r<tl||l>tr){
        return;
    }
    if(l>=tl && r<=tr){
        seg[curr].first++;
        seg[curr].second++;
        if(l!=r){
            lazy[2*curr]++;
            lazy[2*curr+1]++;
        }
        return;
    }
    long long mid =(l+r)/2;
    update(2*curr,l,mid,tl,tr);
    update(2*curr+1,mid+1,r,tl,tr);
    seg[curr].first = max(seg[2*curr].first,seg[2*curr+1].first);
    seg[curr].second = min(seg[2*curr].second,seg[2*curr+1].second);
}
int main(){
    long long n,q;
    cin>>n>>q;
    for(long long i=1;i<=n;i++){
        cin>>arr[i];
    }
    sort(arr+1,arr+n+1);
    build(1,1,n);
    for(long long i=1;i<=q;i++){
        char ty;
        cin>>ty;
        if(ty == 'F'){
            long long c,h;
            cin>>c>>h;
            long long pos1= firstpos(1,1,n,h);
            
            if(atpos(1,1,n,pos1)<h){
               
                continue;
            }
            
            long long x = pos1;
            long long y = min(n,x+c-1);
            
            long long val = atpos(1,1,n,y);
            
            long long li = firstpos(1,1,n,val);
           
            long long ri = lastpos(1,1,n,val);
            
           // cout<<ri<<endl;
           if(atpos(1,1,n,li) == atpos(1,1,n,pos1)){
               update(1,1,n,ri-c+1,ri);
               //cout<<ri-c+1<<endl;
               continue;
           }
            update(1,1,n,x,li-1);
            
            update(1,1,n,ri-(li-x)+1,ri);
            //cout<<ri-(li-x)+1<<" "<<ri<<endl;
        }else{
            long long mini,maxi;
            cin>>mini>>maxi;
            
            if(atpos(1,1,n,firstpos(1,1,n,mini))<mini){
                cout<<0<<endl;
                continue;
            }
            
            if(atpos(1,1,n,lastpos(1,1,n,maxi))>maxi){
                cout<<0<<endl;
                continue;
            }
            cout<<lastpos(1,1,n,maxi)-firstpos(1,1,n,mini)+1<<endl;
          
        }
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 311 ms 7316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 373 ms 1152 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 400 ms 1028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 291 ms 4168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 292 ms 7168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 314 ms 7408 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 436 ms 7436 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 384 ms 7548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 560 ms 7700 KB Output isn't correct