Submission #704043

#TimeUsernameProblemLanguageResultExecution timeMemory
704043flappybirdEvent Hopping 2 (JOI21_event2)C++17
100 / 100
209 ms32632 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,fma") using namespace std; typedef long long ll; typedef pair<ll, ll> pll; typedef pair<int, int> pii; #define MAX 201010 #define MAXS 20 #define INF 1000000000000000001 #define bb ' ' #define ln '\n' #define Ln '\n' int S[MAX]; int E[MAX]; vector<int> st[MAX]; int sp[MAX][MAXS]; int getnum(int l, int r) { int ans = 0; int i; for (i = MAXS - 1; i >= 0; i--) if (sp[l][i] <= r) l = sp[l][i], ans |= (1 << i); return ans; } signed main() { ios::sync_with_stdio(false), cin.tie(0); int N, K; cin >> N >> K; int i; vector<int> v; for (i = 1; i <= N; i++) { cin >> S[i] >> E[i]; v.push_back(S[i]); v.push_back(E[i]); } sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); for (i = 1; i <= N; i++) { S[i] = lower_bound(v.begin(), v.end(), S[i]) - v.begin() + 1; E[i] = lower_bound(v.begin(), v.end(), E[i]) - v.begin() + 1; } int X = v.size(); for (i = 1; i <= N; i++) st[S[i]].push_back(E[i]); int mn = X + 1; for (i = 0; i < MAXS; i++) sp[X + 1][i] = X + 1; for (i = X; i >= 1; i--) { for (auto v : st[i]) mn = min(mn, v); sp[i][0] = mn; } int j; for (i = 1; i < MAXS; i++) for (j = 1; j <= X; j++) sp[j][i] = sp[sp[j][i - 1]][i - 1]; set<pii> st; st.insert(pii(1, X)); vector<int> ans; int sum = getnum(1, X); for (i = 1; i <= N; i++) { int s = S[i], e = E[i]; auto it = st.lower_bound(pii(s + 1, -1e9)); if (it-- == st.begin()) continue; auto [l, r] = *it; if (!(l <= s && e <= r)) continue; int delta = -getnum(l, r) + getnum(l, s) + getnum(e, r) + 1; if (sum + delta < K) continue; sum += delta; st.erase(it); st.emplace(l, s); st.emplace(e, r); ans.push_back(i); if (ans.size() == K) break; } if (ans.size() < K) { cout << -1 << ln; return 0; } for (auto v : ans) cout << v << ln; }

Compilation message (stderr)

event2.cpp: In function 'int main()':
event2.cpp:70:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   70 |   if (ans.size() == K) break;
      |       ~~~~~~~~~~~^~~~
event2.cpp:72:17: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   72 |  if (ans.size() < 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...