Submission #1064583

#TimeUsernameProblemLanguageResultExecution timeMemory
1064583onbertEvent Hopping 2 (JOI21_event2)C++17
100 / 100
136 ms40992 KiB
#include <bits/stdc++.h> using namespace std; #define int long long const int maxn = 2e5 + 5, lg = 18, INF = 1e18; int n, k, m; int st[maxn][lg]; int cnt(int l, int r){ int val = 0; for (int i=lg-1;i>=0;i--) { if (st[l][i]<=r) { val += (1<<i); l = st[l][i]; } } return val; } signed main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> k; vector<int> vals = {-1}; pair<int,int> a[n]; for (auto &[x, y]:a) { cin >> x >> y; vals.push_back(x); vals.push_back(y); } sort(vals.begin(), vals.end()); vals.erase(unique(vals.begin(), vals.end()), vals.end()); m = vals.size() - 1; for (int i=1;i<=m;i++) for (int j=0;j<lg;j++) st[i][j] = INF; for (auto &[x, y]:a) { x = lower_bound(vals.begin(), vals.end(), x) - vals.begin(); y = lower_bound(vals.begin(), vals.end(), y) - vals.begin(); st[x][0] = min(y, st[x][0]); } for (int i=m-1;i>=1;i--) st[i][0] = min(st[i][0], st[i+1][0]); for (int i=m-1;i>=1;i--) { for (int j=1;j<lg;j++) { if (st[i][j-1]==INF) break; st[i][j] = st[st[i][j-1]][j-1]; } } vector<int> ans; set<pair<int, int>> s; s.insert({1, 1}); s.insert({m, m}); int cur = cnt(1, m); // cout << cur << endl; for (int i=0;i<n && ans.size()<k;i++) { auto [l, r] = a[i]; auto it = s.lower_bound(make_pair(l, r)); int lhs = prev(it)->second, rhs = it->first; if (lhs > l || rhs < r) continue; int delta = -cnt(lhs, rhs) + cnt(lhs, l) + cnt(r, rhs); if (cur + delta + ans.size() + 1 >= k) { ans.push_back(i+1); cur += delta; s.insert({l, r}); } } if (ans.size() < k) cout << "-1\n"; else { for (int i:ans) cout << i << "\n"; } }

Compilation message (stderr)

event2.cpp: In function 'int main()':
event2.cpp:49:35: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   49 |     for (int i=0;i<n && ans.size()<k;i++) {
      |                         ~~~~~~~~~~^~
event2.cpp:55:42: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'long long int' [-Wsign-compare]
   55 |         if (cur + delta + ans.size() + 1 >= k) {
      |             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
event2.cpp:61:20: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   61 |     if (ans.size() < k) cout << "-1\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...