Submission #733931

#TimeUsernameProblemLanguageResultExecution timeMemory
733931myrcellaThe short shank; Redemption (BOI21_prison)C++17
10 / 100
621 ms53584 KiB
//by szh #include<bits/stdc++.h> using namespace std; #define fi first #define se second #define pii pair<int,int> #define pll pair<long long,long long> #define pb push_back #define debug(x) cerr<<#x<<"="<<x<<endl #define pq priority_queue #define inf 0x3f #define rep(i,a,b) for (int i=a;i<(b);i++) #define MP make_pair #define SZ(x) (int(x.size())) #define ll long long #define mod 1000000007 #define ALL(x) x.begin(),x.end() void inc(int &a,int b) {a=(a+b)%mod;} void dec(int &a,int b) {a=(a-b+mod)%mod;} int lowbit(int x) {return x&(-x);} ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;} const int maxn = 8e4; int n,d,T; int t[maxn]; int le[maxn]; int mn[maxn][21]; int lg[maxn]; int query(int l,int r) { int tmp = lg[r-l+1]; return min(mn[l][tmp],mn[r-(1<<tmp)+1][tmp]); } int tree[maxn*4][20],add[maxn*4][20]; void update(int id,int c,int cl,int cr,int l,int r,int val) { if (l<=cl and cr<=r) { tree[c][id] += val; add[c][id] += val; return; } int mid=cl+cr>>1; if (add[c][id]!=0) { tree[c<<1][id] += add[c][id]; tree[c<<1|1][id] += add[c][id]; add[c<<1][id] += add[c][id]; add[c<<1|1][id] += add[c][id]; add[c][id] = 0; } if (l<=mid) update(id,c<<1,cl,mid,l,r,val); if (r>mid) update(id,c<<1|1,mid+1,cr,l,r,val); tree[c][id] = max(tree[c<<1][id],tree[c<<1|1][id]); return; } int main() { // freopen("input.txt","r",stdin); std::ios::sync_with_stdio(false);cin.tie(0); cin>>n>>d>>T; rep(i,0,n) cin>>t[i],mn[i][0] = t[i]-i; lg[1] = 0; rep(i,2,maxn) lg[i] = lg[i/2]+1; for (int i = n-1;i>=0;i--) rep(j,1,21) { if (i+(1<<j)>n) break; mn[i][j] = min(mn[i][j-1],mn[i+(1<<(j-1))][j-1]); } rep(i,0,n) { if (t[i]<=T) le[i] = maxn; else { int l = 0,r=i; while (l<r) { int mid = l+r>>1; if (mid==i or query(mid,i-1)+i>T) r=mid; else l = mid+1; } le[i] = l; } } rep(i,0,maxn*4) rep(j,0,d+1) tree[i][j] = -maxn; if (le[0]==0) update(0,1,0,n-1,0,0,maxn+1); else update(0,1,0,n-1,0,0,maxn); rep(i,1,n) { for (int j = d;j>0;j--) update(j,1,0,n-1,i,i,maxn+tree[1][j-1]); if (le[i]<=i) rep(j,0,d+1) update(j,1,0,n-1,le[i],i,1); } cout<<n-tree[1][d]; return 0; }

Compilation message (stderr)

prison.cpp: In function 'void update(int, int, int, int, int, int, int)':
prison.cpp:44:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   44 |  int mid=cl+cr>>1;
      |          ~~^~~
prison.cpp: In function 'int main()':
prison.cpp:75:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   75 |     int mid = l+r>>1;
      |               ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...