Submission #1014640

#TimeUsernameProblemLanguageResultExecution timeMemory
1014640vjudge1Event Hopping 2 (JOI21_event2)C++17
100 / 100
161 ms48712 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define int long long #define FOR(i, a, b) for (int i = (a); i <= (b); i++) #define FORD(i, a, b) for (int i = (b); i >= (a); i --) #define REP(i, n) for (int i = 0; i < (n); ++i) #define REPD(i, n) for (int i = (n) - 1; i >= 0; --i) #define MASK(i) (1LL << (i)) #define BIT(x, i) (((x) >> (i)) & 1) constexpr ll LINF = (1ll << 60); constexpr int INF = (1ll << 30); constexpr int Mod = 1e9 + 7; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); /* Phu Trong from Nguyen Tat Thanh High School for gifted student */ template <class X, class Y> bool minimize(X &x, const Y &y){ X eps = 1e-9; if (x > y + eps) {x = y; return 1;} return 0; } template <class X, class Y> bool maximize(X &x, const Y &y){ X eps = 1e-9; if (x + eps < y) {x = y; return 1;} return 0; } #define MAX 200005 int numEvent, numChoose; struct Info{ int l, r; Info(){} Info(int _l, int _r): l(_l), r(_r){} } A[MAX]; template<class T = vector<int>> T compress(T& v){ sort(v.begin(), v.end()); v.resize(unique(v.begin(), v.end()) - v.begin()); return v; } vector<int> comp; int find(int x){ return lower_bound(comp.begin(), comp.end(), x) - comp.begin() + 1; } int nxt[MAX], up[MAX][22]; void process(void){ cin >> numEvent >> numChoose; for (int i = 1; i <= numEvent; ++i){ cin >> A[i].l >> A[i].r; comp.push_back(A[i].l); comp.push_back(A[i].r); } comp = compress(comp); int n = 2 * numEvent; for (int i = 1; i <= n; ++i) nxt[i] = n + 1; for (int i = 1; i <= numEvent; ++i){ A[i].l = find(A[i].l); A[i].r = find(A[i].r); minimize(nxt[A[i].l], A[i].r); } REP(i, 21) FOR(u, 1, n + 1) up[u][i] = n + 1; for (int i = n; i > 0; --i){ up[i][0] = min(up[i + 1][0], nxt[i]); } for (int i = 1; i <= 20; ++i){ for (int u = 1; u <= n; ++u){ up[u][i] = up[up[u][i - 1]][i - 1]; } } auto dp = [&](int l, int r) -> int{ int ans = 0; for (int i = 20; i >= 0; --i){ if (up[l][i] <= r){ l = up[l][i]; ans |= MASK(i); } } return ans; }; int ans = dp(1, n); if (ans < numChoose) return void(cout << -1); set<pair<int, int>> mySet; mySet.insert(make_pair(1, n)); vector<int> ID; for (int i = 1; i <= numEvent; ++i){ auto it = prev(mySet.lower_bound(make_pair(A[i].l + 1, 0))); int l, r; tie(l, r) = *it; if (A[i].r <= r){ int nw_ans = ans - dp(l, r) + dp(l, A[i].l) + dp(A[i].r, r) + 1; if (nw_ans >= numChoose){ ans = nw_ans; ID.push_back(i); mySet.erase(it); mySet.insert(make_pair(l, A[i].l)); mySet.insert(make_pair(A[i].r, r)); } } } assert((int)ID.size() >= numChoose); for (int i = 0; i < numChoose; ++i){ cout << ID[i] << "\n"; } } signed main(){ #define name "Whisper" cin.tie(nullptr) -> sync_with_stdio(false); //freopen(name".inp", "r", stdin); //freopen(name".out", "w", stdout); process(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...