제출 #1225243

#제출 시각아이디문제언어결과실행 시간메모리
1225243kokoxuyaThe short shank; Redemption (BOI21_prison)C++20
80 / 100
1185 ms531200 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define pb push_back #define mp make_pair #define pii pair<int,int> #define ss second #define ff first #define piii pair<int,pii> #define debu(x) (cerr << #x << " = "<< x << "\n") #define debu2(x,y) (cerr << #x << " = "<< x << " " << #y << " = " << y << "\n") #define debu3(x,y,z) (cerr << #x << " = "<< x << " " << #y << " = " << y << " " << #z << " = " << z<< "\n") #define bitout(x,y) {\ cerr << #x << " : ";\ for (int justforbits = y; justforbits >=0; justforbits--)cout << (((1 << justforbits) & x)>=1);\ cout << "\n";\ } #define rangeout(j,rangestart,rangeend) {\ cerr << "outputting" << #j<< ":\n";\ for (int forrang = rangestart; forrang <= rangeend; forrang++)cerr << j[forrang] << " ";\ cerr<<"\n";\ } #define c1 {cerr << "Checkpoint 1! \n\n";cerr.flush();} #define c2 {cerr << "Checkpoint 2! \n\n";cerr.flush();} #define c3 {cerr << "Checkpoint 3! \n\n";cerr.flush();} #define c4 {cerr << "Checkpoint 4! \n\n";cerr.flush();} #define defN 2000001 vector<int>parent(defN); vector<set<int>>childlist(defN); vector<priority_queue<pii>>childlist2(defN); vector<bool>riot(defN,true); vector<int>mydepth(defN); priority_queue<pii>trees; int dfs(int cn,int cd) { int currmax=mydepth[cn]=cd; for(auto x=childlist[cn].begin();x!=childlist[cn].end();x++) { int curr=dfs(*x,cd+1); currmax=max(curr,currmax); childlist2[cn].push(mp(curr,*x)); } return currmax; } void godown(int cn) { riot[cn]=false; if(!childlist2[cn].empty()) { int to=childlist2[cn].top().ss; childlist2[cn].pop(); godown(to); } while(!childlist2[cn].empty()) { trees.push(mp(childlist2[cn].top().ff-mydepth[cn],childlist2[cn].top().ss)); childlist2[cn].pop(); } } signed main() { int t1,t2,t3,t4; mt19937_64 rnd(chrono::high_resolution_clock::now().time_since_epoch().count()); //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int n,d,t;cin>>n>>d>>t; priority_queue<piii,vector<piii>,greater<piii>>pq; for(int a=1;a<=n;a++) { cin>>t1; if(t1<=t)pq.push(mp(a,mp(a+(t-t1),a))); } set<int>curr; priority_queue<pii,vector<pii>,greater<pii>>ends; vector<int>foreach(n+1,0); int tots=0; for(int a=1;a<=n;a++) { while(!pq.empty()&&pq.top().ff<=a) { curr.insert(pq.top().ss.ss); ends.push(pq.top().ss); pq.pop(); } while(!ends.empty()&&ends.top().ff<a) { curr.erase(ends.top().ss); ends.pop(); } if(!curr.empty()) { tots++; foreach[a]=(*prev(curr.end())); } } //new : build that treeeeee! :D //tis a bracket sequence stack<int>opens; for(int a=1;a<=n;a++) { if(foreach[a]==a){continue;} if(foreach[a]==0){riot[a]=false;continue;} while(!opens.empty()&&opens.top()>foreach[a]) { parent[opens.top()]=a; childlist[a].insert(opens.top()); opens.pop(); } opens.push(a); } while(!opens.empty()) { int cm=dfs(opens.top(),1); trees.push(mp(cm,opens.top())); opens.pop(); } for(int a=1;a<=d;a++) { if(trees.empty())break; t1=trees.top().ss; trees.pop(); godown(t1); } int ans=0; for(int a=1;a<=n;a++){if(riot[a])ans++;} cout<<ans; }
#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...