Submission #727917

#TimeUsernameProblemLanguageResultExecution timeMemory
727917sysiaEvent Hopping 2 (JOI21_event2)C++17
100 / 100
291 ms42092 KiB
//Sylwia Sapkowska #include <bits/stdc++.h> #pragma GCC optimize("O3", "unroll-loops") using namespace std; void __print(int x) {cerr << x;} void __print(long long x) {cerr << x;} void __print(long double x) {cerr << x;} void __print(char x) {cerr << "'" << x << "'";} void __print(const char *x) {cerr << '"' << x << '"';} void __print(const string &x) {cerr << '"' << x << '"';} void __print(bool x) {cerr << (x ? "true" : "false");} template<typename T, typename V> void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ", "; __print(x.second); cerr << '}';} template<typename T> void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? ", " : ""), __print(i); cerr << "}";} void _print() {cerr << "]\n";} template <typename T, typename... V> void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);} #ifdef LOCAL #define debug(x...) cerr << "[" << #x << "] = ["; _print(x) #else #define debug(x...) #endif typedef pair<int, int> T; const int K = 20; struct seg{ int l, r, i; bool operator < (const seg&y) const { return l == y.l ? r < y.r : l < y.l; } }; void solve(){ int n, k; cin >> n >> k; vector<seg>tab(n); vector<int>s; int ck = 0; for (auto &[l, r, i]: tab) { cin >> l >> r; i = ck++; s.emplace_back(l); s.emplace_back(r); } sort(s.begin(), s.end()); s.erase(unique(s.begin(), s.end()), s.end()); auto scale = [&](int x)->int { return lower_bound(s.begin(), s.end(), x) - s.begin(); }; for (auto &[l, r, i]: tab){ l = scale(l); r = scale(r); } int M = (int)s.size(); sort(tab.begin(), tab.end()); vector up(M+1, vector<int>(K)); vector<int>dp(M+1); ck = n-1; set<int>what; for (int rep = M-1; rep>=0; rep--){ while (ck >= 0 && tab[ck].l >= rep) { what.insert(tab[ck].r); ck--; } //z minimalnym prawym koncem if (what.empty()){ up[rep][0] = M; continue; } up[rep][0] = *what.begin(); dp[rep] = dp[up[rep][0]]+1; debug(rep, up[rep][0], dp[rep]); } int curr = *max_element(dp.begin(), dp.end()); if (curr < k){ cout << "-1\n"; return; } for (int j = 1; j<K; j++){ for (int i = 0; i <= M; i++){ up[i][j] = up[up[i][j-1]][j-1]; } } sort(tab.begin(), tab.end(), [](auto x, auto y){return x.i < y.i;}); set<int>alive; auto ask = [&](int l, int r)->int { int ile = dp[l] - dp[r]; int now = l; for (int i = K-1; i>=0; i--){ if (ile&(1<<i)){ now = up[now][i]; } } if (now <= r) return ile; return ile-1; }; vector<int>ret; for (auto [l, r, i]: tab){ auto it = alive.lower_bound(l); if (it != alive.end() && *it < r) continue; debug(l, r, i); auto Lit = alive.upper_bound(l); auto Rit = alive.lower_bound(r); int L = (Lit == alive.begin() ? 0 : *(--Lit)+1); int R = (Rit == alive.end() ? M : *Rit); debug(L, l, r, R); debug(ask(L, l), ask(r, R), ask(L, R)); int change = ask(L, l) + ask(r, R) + 1 - ask(L, R); if (curr + change >= k){ debug(i); for (int rep = l; rep < r; rep++){ alive.insert(rep); } curr += change; ret.emplace_back(i); if ((int)ret.size() == k) break; } } for (auto x: ret) cout << x+1 << "\n"; } int32_t main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...