#include <bits/stdc++.h>
using namespace std;
constexpr int MAX_N = 100'000;
constexpr int MAX_logN = 18;
constexpr int MAX_LR = 1'000'000'000;
int N, K;
int L[MAX_N], R[MAX_N];
vector<int> z;
vector<int> invL[MAX_N * 2 + 1];
int doubling[MAX_N * 2 + 1][MAX_logN];
int count(int l, int r)
{
int res = 0;
for (int j = MAX_logN - 1; j >= 0; j--)
{
if (doubling[l][j] <= r)
{
l = doubling[l][j];
res += 1 << j;
}
}
return res;
}
int main()
{
cin >> N >> K;
for (int i = 0; i < N; i++)
{
cin >> L[i] >> R[i];
z.push_back(L[i]);
z.push_back(R[i]);
}
sort(z.begin(), z.end());
z.erase(unique(z.begin(), z.end()), z.end());
for (int i = 0; i < N; i ++)
{
L[i] = lower_bound(z.begin(), z.end(), L[i]) - z.begin();
R[i] = lower_bound(z.begin(), z.end(), R[i]) - z.begin();
}
for (int i = 0; i < N; i ++)
invL[L[i]].push_back(i);
int r = (int)z.size();
for (int i = z.size(); i >= 0; i --)
{
for (int j = 0; j < (int)invL[i].size(); j ++)
r = min(r, R[invL[i][j]]);
doubling[i][0] = r;
}
for (int i = 1; i < MAX_logN; i ++)
for (int j = 0; j <= (int)z.size(); j ++)
doubling[j][i] = doubling[doubling[j][i - 1]][i - 1];
int now = count(0, z.size() - 1);
if (now < K)
{
cout << "-1\n";
return 0;
}
set<pair<int, int>> used = {{0, 0}, {z.size() - 1, z.size() - 1}};
for (int i = 0; (int)used.size() - 2 < K; i ++)
{
int st = prev(used.lower_bound({R[i], 0}))->second;
int dr = used.lower_bound({R[i], 0})->first;
if (L[i] < st)
continue;
int tmp = now - count(st, dr) + count(st, L[i]) + 1 + count(R[i], dr);
if (tmp >= K)
{
cout << i + 1 << '\n';
now = tmp;
used.insert({L[i], R[i]});
}
}
}
# | 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... |