Submission #590423

#TimeUsernameProblemLanguageResultExecution timeMemory
590423LoboThe short shank; Redemption (BOI21_prison)C++17
0 / 100
1 ms468 KiB
#include<bits/stdc++.h> using namespace std; const long long inf = (long long) 1e18 + 10; const int inf1 = (int) 1e9 + 10; #define int long long #define dbl long double #define endl '\n' #define sc second #define fr first #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() const int maxn = 550; int n, d, T, t[maxn], r[maxn], qtd[maxn], trT[4*maxn]; set<pair<int,int>> st; void buildT(int no, int l, int r) { trT[no] = inf; if(l != r) { int f1=2*no; int f2=2*no+1; int mid = (l+r)>>1; buildT(f1,l,mid); buildT(f2,mid+1,r); } } void attT(int no, int l, int r, int pos, int val) { if(l > pos || r < pos) return; if(l == r) { trT[no] = val; return; } int f1=2*no; int f2=2*no+1; int mid = (l+r)>>1; attT(f1,l,mid,pos,val); attT(f2,mid+1,r,pos,val); trT[no] = min(trT[f1],trT[f2]); } int findT(int no, int l, int r, int val) { if(l == r) return l; int f1 = 2*no; int f2 = 2*no+1; int mid = (l+r)/2; if(trT[f2] <= val) return findT(f2,mid+1,r,val); return findT(f1,l,mid,val); } void solve() { cin >> n >> d >> T; d = min(d,n-1); int ans = 0; for(int i = 1; i <= n; i++) cin >> t[i]; buildT(1,1,n); for(int i = 1; i <= n; i++) { attT(1,1,n,i,t[i]-i); if(trT[1] > T-i) { r[i] = n; } else { r[i] = findT(1,1,n,T-i); } if(r[i]!=n) ans++; // cout << i << " " << r[i] << endl; } //qtd[i] -> qtd de retas passando de i+1 pra i for(int i = 1; i < n; i++) { qtd[i] = 0; for(int j = i+1; j <= n; j++) { if(r[j] != 0 && r[j] <= i) qtd[i]++; } st.insert(mp(qtd[i],i)); // cout << i << " - " << qtd[i] << endl; } while(d--) { auto it = st.end(); it--; int id = it->sc; st.erase(it); //tira todos os j que tem r[j] <= id for(int j = id+1; j <= n; j++) { if(r[j] != 0 && r[j] <= id) { //diminui a qtd dos que ele tinha aumentado for(int i = r[j]; i < j; i++) { st.erase(mp(qtd[i],i)); qtd[i]--; st.insert(mp(qtd[i],i)); } r[j] = 0; ans--; } } } cout << ans << endl; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); // freopen("in.in", "r", stdin); // freopen("out.out", "w", stdout); int tt = 1; // cin >> tt; while(tt--) { solve(); } }
#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...