Submission #406204

# Submission time Handle Problem Language Result Execution time Memory
406204 2021-05-17T09:26:26 Z jamezzz The short shank; Redemption (BOI21_prison) C++14
0 / 100
1 ms 204 KB
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#include <ext/rope>
using namespace __gnu_cxx;

typedef tree<long long, null_type, less<long long>,
rb_tree_tag, tree_order_statistics_node_update> pbds;
//less_equal for identical elements

#define DEBUG

#ifdef DEBUG
#define debug(...) printf(__VA_ARGS__);
#else
#define debug(...)
#endif
#define sf scanf
#define pf printf
#define fi first
#define se second
#define pb emplace_back
#define sz(x) (int)x.size()
#define mnto(x,y) x=min(x,(__typeof__(x))y)
#define mxto(x,y) x=max(x,(__typeof__(x))y)
#define INF 1023456789
#define LINF 1023456789123456789
#define all(x) x.begin(), x.end()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
typedef tuple<int, int, int> iii;
typedef tuple<int, int, int, int> iiii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<pll> vll;

struct node{
	int s,e,m,v,lz;
	node *l,*r;
	
	node(int _s,int _e){
		s=_s;e=_e;m=(s+e)/2;v=-1;lz=-1;
		if(s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
		}
	}
	void propo(){
		mxto(v,lz);
		if(s!=e){
			mxto(l->lz,lz);
			mxto(r->lz,lz);
		}
		lz=-1;
	}
	void up(int x,int y,int nv){
		if(s==x&&e==y){
			mxto(lz,nv);return;
		}
		if(y<=m)l->up(x,y,nv);
		else if(x>m)r->up(x,y,nv);
		else l->up(x,m,nv),r->up(m+1,y,nv);
	}
	int qry(int x){
		propo();
		if(s==x&&e==x)return v;
		if(x<=m)return l->qry(x);
		else return r->qry(x);
	}
}*root;

int n,d,t[2000005],arv;
bool use[2000005];
vector<ii> v;
priority_queue<ii,vector<ii>,greater<ii>> pq;

int main(){
	sf("%d%d%d",&n,&d,&arv);
	root=new node(0,n-1);
	for(int i=0;i<n;++i){
		sf("%d",&t[i]);
		if(t[i]<=arv){
			int dist=arv-t[i];
			if((i+1)<=min(i+dist,n-1))root->up(i+1,min(i+dist,n-1),i);
		}
	}
	int ans=0;
	for(int i=0;i<n;++i){
		if(t[i]<=arv){
			++ans;continue;
		}
		if(root->qry(i)==-1)continue;
		v.pb(root->qry(i),i-1);
	}
	sort(all(v));
	int lo=1,hi=n,mid,res=0;
	while(lo<=hi){
		mid=(lo+hi)/2;
		int cnt=0,cur=0,tmp=0;
		for(int i=0;i<n;++i){
			while(!pq.empty()&&pq.top().fi<i)pq.pop();
			while(cur<sz(v)&&v[cur].fi<=i){
				pq.push(ii(v[cur].se,v[cur].fi));
				++cur;
			}
			if(sz(pq)>=mid){
				tmp+=sz(pq);
				while(!pq.empty())pq.pop();
				++cnt;
			}
		}
		if(cnt>d)lo=mid+1;
		else{
			hi=mid-1;
			res=tmp;
		}
	}
	pf("%d\n",ans+sz(v)-res);
	return 0;
}

Compilation message

prison.cpp: In function 'int main()':
prison.cpp:82:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |  sf("%d%d%d",&n,&d,&arv);
      |    ^
prison.cpp:85:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |   sf("%d",&t[i]);
      |     ^
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -