Submission #494828

#TimeUsernameProblemLanguageResultExecution timeMemory
494828blueEvent Hopping 2 (JOI21_event2)C++17
32 / 100
3074 ms21044 KiB
#include <iostream> #include <vector> #include <map> #include <set> #include <cassert> #include <algorithm> using namespace std; const int mx = 200'000; const int INF = 1'000'000'001; const int lg = 19; using vi = vector<int>; using pii = pair<int, int>; #define sz(x) int(x.size()) int jmp[1+mx+1][1+lg]; vector<pii> events; int query(int L, int R) // { int ans = 0; for(auto f: events) { if(f.first < L) continue; if(f.second > R) continue; ans++; L = f.second; } return ans; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int N, K; cin >> N >> K; set<int> V; int L[1+N], R[1+N]; for(int i = 1; i <= N; i++) { cin >> L[i] >> R[i]; V.insert(L[i]); V.insert(R[i]); } map<int, int> mp; int ct = 0; for(int v: V) mp[v] = ++ct; // cerr << "normalized\n"; // for(auto y: mp) cerr << y.first << " : " << y.second << '\n'; for(int i = 1; i <= N; i++) { L[i] = mp[L[i]]; R[i] = mp[R[i]]; // cerr << L[i] << ' ' << R[i] << '\n'; events.push_back({L[i], R[i]}); } sort(events.begin(), events.end(), [] (pii u, pii v) { return u.second < v.second; }); // jmp[i][e] = jmp[ jmp[i][e-1] ][e-1]; int max_events = query(1, mx); if(max_events < K) { cout << "-1\n"; return 0; } // cerr << "max events = " << max_events << '\n'; vi res; set<pii> events; events.insert({1, 1}); events.insert({mx, mx}); for(int i = 1; i <= N && sz(res) < K; i++) { auto y2 = events.lower_bound({L[i], R[i]}); if(R[i] > y2->first) continue; auto y1 = y2; y1--; if(L[i] < y1->second) continue; int change = query(y1->second, L[i]) + query(R[i], y2->first) + 1 - query(y1->second, y2->first); if(max_events + change < K) continue; max_events += change; events.insert({L[i], R[i]}); res.push_back(i); } for(int r: res) cout << r << '\n'; // cout << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...