Submission #153372

# Submission time Handle Problem Language Result Execution time Memory
153372 2019-09-13T18:41:31 Z brcode Growing Trees (BOI11_grow) C++14
0 / 100
499 ms 9600 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){
    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;
    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;
    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;
    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);

            long long x = pos1;
            long long y = 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,li,ri);

               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(firstpos(1,1,n,mini)==n && atpos(1,1,n,n)!=mini){
                cout<<0<<endl;
                continue;
            }
            if(lastpos(1,1,n,maxi)==1 && atpos(1,1,n,1)!=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 259 ms 8568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 504 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 350 ms 1912 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 387 ms 2108 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 232 ms 4996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 227 ms 8184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 247 ms 8120 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 391 ms 9156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 319 ms 8600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 499 ms 9600 KB Output isn't correct