Submission #417031

#TimeUsernameProblemLanguageResultExecution timeMemory
417031lycEvent Hopping 2 (JOI21_event2)C++14
32 / 100
3045 ms5156 KiB
#include <bits/stdc++.h> using namespace std; #define TRACE(x) cerr << #x << " :: " << x << endl #define _ << " " << #define SZ(x) ((int)(x).size()) #define ALL(x) (x).begin(), (x).end() #define FOR(i,a,b) for(int i=(a);i<=(b);++i) #define RFOR(i,a,b) for(int i=(a);i>=(b);--i) typedef long long ll; typedef pair<int,int> ii; const int mxN = 1e5+5; const int mxK = 1e5+5; int N, K; struct Event { int L, R, I; }; vector<Event> events, byR; int dp[mxN], used[mxN], ans[mxK]; int solve(int lb, int rb) { int ret = 0, ep = -1; for (auto& e : byR) if (lb <= e.L && e.R <= rb) { if (e.L >= ep) { ++ret; ep = e.R; } } return ret; } int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> N >> K; FOR(i,1,N){ int L, R; cin >> L >> R; events.push_back({L,R,i}); byR.push_back({L,R,i}); } sort(ALL(byR), [&](Event a, Event b){ return a.R < b.R; }); set<ii> cur; cur.insert(ii(-1,-1)); cur.insert(ii(1e9+5,1e9+5)); ll take = solve(-1,1e9+5); for (auto& e : events) { auto it = cur.lower_bound(ii(e.L, 0)); if (e.R > it->first) continue; if (prev(it)->second > e.L) continue; ll take2 = take; take2 -= solve(prev(it)->second, it->first); take2 += solve(prev(it)->second, e.L); take2 += solve(e.R, it->first); take2 += 1; if (take2 >= K) { cur.insert(ii(e.L,e.R)); take = take2; used[e.I] = 1; } if (SZ(cur)-2 >= K) break; } if (SZ(cur)-2 < K) { cout << -1 << '\n'; } FOR(i,1,N) if (used[i] && K) { cout << i << '\n'; --K; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...