This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
struct node {
int l, r, mx = 0;
node *left = NULL, *right = NULL;
node(int l, int r):l(l), r(r) {}
};
void check(node *x) {
if(x->left == NULL) {
x->left = new node(x->l, (x->l + x->r) / 2);
}
if(x->right == NULL) {
x->right = new node((x->l + x->r) / 2, x->r);
}
}
void update(int pos, int val, node *x) {
if(x->l + 1 == x->r) {
x->mx = val;
return;
}
check(x);
pos < x->left->r ?
update(pos, val, x->left) :
update(pos, val, x->right) ;
x->mx = max(x->left->mx, x->right->mx);
}
int find(int r, node *x) {
if(r <= x->l) {
return x->mx;
}
check(x);
int res = 0;
if(x->left->r > r && x->left->mx) {
res = find(r, x->left);
}
if(x->right->mx) {
res = max(res, find(r, x->right));
}
return res;
}
main() {
#ifdef Home
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // Home
ios_base::sync_with_stdio(0);
cin.tie(0);
bool tsk = true;
int n, k, mxr = -1;
cin >> n >> k;
vector < pair < int, int > > V(n);
for(int i = 0; i < n; ++ i) {
cin >> V[i].first >> V[i].second;
tsk &= (!i || V[i - 1].first <= V[i].first);
mxr = max(mxr, V[i].second);
}
if(tsk) {
int t = 1;
for(; t <= mxr; t <<= 1);
node *root = new node(0, t);
int dp[n + 10];
for(int i = n; i --> 0;) {
dp[i] = 1 + find(V[i].second, root);
update(V[i].first, dp[i], root);
}
if(root->mx < k) {
cout << -1;
return 0;
}
for(int i = 0, j = 0; i < n && k; ++ i) {
if(j <= V[i].first && k <= dp[i]) {
cout << i + 1 << '\n';
-- k;
j = V[i].second;
}
}
return 0;
}
int t = 1;
for(; t <= mxr; t <<= 1);
node *root = new node(0, t);
vector < int > pos(n);
iota(pos.begin(), pos.end(), 0);
sort(pos.rbegin(), pos.rend(), [&](int i, int j) {
return V[i] < V[j];
});
int dp[n + 10];
for(auto &i : pos) {
dp[i] = 1 + find(V[i].second, root);
update(V[i].first, dp[i], root);
}
if(root->mx < k) {
cout << -1 << '\n';
return 0;
}
bool use[n + 10] = {};
for(int j = 0; k --> 0;) {
for(int i = 0; i < n; ++ i) {
if(!use[i] && j <= V[i].first && k < dp[i]) {
use[i] = true;
j = V[i].second;
break;
}
}
}
for(int i = 0; i < n; ++ i) {
if(use[i]) {
cout << i + 1 << '\n';
}
}
}
Compilation message (stderr)
event2.cpp:55:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
55 | main() {
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |