Submission #406074

# Submission time Handle Problem Language Result Execution time Memory
406074 2021-05-17T07:45:05 Z jamezzz The short shank; Redemption (BOI21_prison) C++14
0 / 100
281 ms 99620 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(){
		v=max(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,s[2000005],e[2000005];
vector<ii> v;
priority_queue<ii> pq;
int dp[2000005],cnt[2000005];

int rng(int l,int r){
	return s[r]-e[r];
}

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){
			root->up(i,i,n);
			int dist=arv-t[i];
			if(dist!=0)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));
	d=min(d,sz(v));
	for(ii pr:v){
		++s[pr.fi];
		++e[pr.se+1];
	}
	int res=0;
	for(int i=1;i<n;++i){
		s[i]+=s[i-1];
		e[i]+=e[i-1];
		mxto(res,s[i]-e[i]);
	}
	pf("%d\n",ans+sz(v)-res);
	return 0;
	int lo=-n,hi=n,mid;
	while(lo<=hi){
		mid=(lo+hi)/2;
		dp[0]=s[0];cnt[0]=(s[0]>0);
		for(int i=1;i<n;++i){
			for(int j=0;j<i;++j){
				if(dp[j]+rng(j+1,i)+mid>dp[i]){
					dp[i]=dp[j]+rng(j+1,i)+mid;
					cnt[i]=cnt[j]+1;
				}
			}
		}
		if(cnt[n-1]<=d){
			res=mid;
			lo=mid+1;
		}
		else hi=mid-1;
	}
}

Compilation message

prison.cpp: In function 'int main()':
prison.cpp:86:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |  sf("%d%d%d",&n,&d,&arv);
      |    ^
prison.cpp:89:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |   sf("%d",&t[i]);
      |     ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Runtime error 281 ms 99620 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Runtime error 34 ms 15308 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -