Submission #110747

# Submission time Handle Problem Language Result Execution time Memory
110747 2019-05-12T07:31:17 Z ckodser Cake (CEOI14_cake) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>

#define ll long long
#define pb push_back
#define mp make_pair
#define ld long double
#define F first
#define S second
#define pii pair<ll,ll> 

using namespace :: std;

const ll mod=1e9+7;
const ll maxn=5e5+500;
const ll inf=1e9+900;
const ll sq=12;

ll p[maxn];
ll seg[4*maxn];
ll nmx;

void bild(ll L,ll R,ll node){
    if(L+1==R){
	seg[node]=p[L];
	return ;
    }
    ll mid=(L+R)/2;
    bild(L,mid,2*node);
    bild(mid,R,2*node+1);
    seg[node]=max(seg[2*node+1],seg[2*node]);
}

ll find_first_high_min(ll L,ll R,ll node,ll l,ll r,ll v){
    if(r<=L || R<=l || seg[node]<=v){
	return inf;
    }
    if(L+1==R){
	return L;
    }
    ll mid=(L+R)/2;
    ll e1=find_first_high_min(L,mid,2*node,l,r,v);
    if(e1!=inf)return e1;
    return find_first_high_min(mid,R,2*node+1,l,r,v);
}
ll find_first_high_max(ll L,ll R,ll node,ll l,ll r,ll v){
    if(r<=L || R<=l || seg[node]<=v){
	return inf;
    }
    if(L+1==R){
	return L;
    }
    ll mid=(L+R)/2;
    ll e1=find_first_high_max(mid,R,2*node+1,l,r,v);
    if(e1!=inf)return e1;
    return find_first_high_max(L,mid,2*node,l,r,v);
}
ll find_seg_max(ll L,ll R,ll node,ll l,ll r){
    if(r<=L || R<=l){
	return 0;
    }
    if(l<=L && R<=r){
	return  seg[node];
    }
    ll mid=(L+R)/2;
    return max(find_seg_max(L,mid,2*node,l,r),find_seg_max(mid,R,2*node+1,l,r));
}
void update_seg(ll L,ll R,ll node,ll x,ll v){
    if(L+1==R){
	seg[node]=v;
	return;
    }
    ll mid=(L+R)/2;
    if(x<mid){
	update_seg(L,mid,2*node,x,v);
    }else{
	update_seg(mid,R,2*node+1,x,v);
    }
    seg[node]=max(seg[2*node+1],seg[2*node]);
}






ll n,a;
vector<pii> best;

ll find_max(ll e){
    ll l=e;
    ll r=a;
    if(r<l){
	swap(l,r);
    }
    ll ans=0;
    for(ll i=l;i<=r;i++){
	if(i!=a){
	    ans=max(ans,p[i]);
	}
    }
    return ans;
}
ll find_first_high(ll x,ll f){
    for(ll i=a+f;;i+=f){
	if(p[i]>x)return i;
    }
    return 0;
}
void update(ll x,ll v){
    ll b=best[best.size()-v].F;
    p[x]=b+1;
    bool bod=0;
    for(ll i=0;i<best.size();i++){
	if(best[i].F>b && best[i].S!=x){
	    best[i].F++;
	    p[best[i].S]++;
	}
	if(best[i].S==x){
	    best[i].F=b+1;
	    bod=1;
	}
    }
    if(!bod){
	best.pb(mp(p[x],x));
    }
    sort(best.begin(),best.end());
    if(best.size()>sq){
	reverse(best.begin(),best.end());
	pii e=best.back();
	avaz(e.S,e.F);
	best.pop_back();
	reverse(best.begin(),best.end());
    }  
}
int main(){
    cin>>n>>a;
    nmx=n+5
    p[0]=inf;
    p[n+1]=inf;
    for(ll i=1;i<=n;i++){
	cin>>p[i];
	if(p[i]>n-sq){
	    best.pb(mp(p[i],i));
	}
    }	
    bild(0,nmx,1);
    sort(best.begin(),best.end());
    ll q;
    cin>>q;
    for(ll i=0;i<q;i++){
	char c;
	cin>>c;
	if(c=='F'){
	    ll e;
	    cin>>e;
	    ll mi=find_max(e);
	    ll o;
	    if(e==a){
		cout<<0<<endl;
		continue;
	    }	
	    if(e<a){
		o=find_first_high(mi,1);
	    }else{
		o=find_first_high(mi,-1);
	    }
	    cout<<abs(o-e)-1<<endl;
	}else{
	    ll x,v;
	    cin>>x>>v;
	    update(x,v);
	}
    }

}

Compilation message

cake.cpp: In function 'void update(long long int, long long int)':
cake.cpp:113:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(ll i=0;i<best.size();i++){
                ~^~~~~~~~~~~~
cake.cpp:130:2: error: 'avaz' was not declared in this scope
  avaz(e.S,e.F);
  ^~~~
cake.cpp:130:2: note: suggested alternative: 'atan'
  avaz(e.S,e.F);
  ^~~~
  atan
cake.cpp: In function 'int main()':
cake.cpp:138:5: error: expected ';' before 'p'
     p[0]=inf;
     ^