This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
int cnt=0;
sort(all(v));
for(int i=0;i<d;++i){
if(cnt==sz(v))break;
int mx=0,id=0,cur=0;
for(int j=0;j<n;++j){
while(!pq.empty()&&pq.top().fi<j)pq.pop();
while(cur<sz(v)&&v[cur].fi<=j){
if(!use[cur])pq.push(ii(v[cur].se,v[cur].fi));
++cur;
}
if(sz(pq)>mx)mx=sz(pq),id=j;
}
for(int j=0;j<sz(v);++j){
if(v[j].fi<=id&&id<=v[j].se&&!use[j]){
use[j]=true;
++cnt;
}
}
while(!pq.empty())pq.pop();
}
pf("%d\n",ans+sz(v)-cnt);
return 0;
}
Compilation message (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |