#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define show(x,y) cout << y << " " << #x << endl;
#define show2(x,y,i,j) cout << y << " " << #x << " " << j << " " << #i << endl;
#define show3(x,y,i,j,p,q) cout << y << " " << #x << " " << j << " " << #i << " " << q << " " << #p << endl;
#define show4(x,y) for(auto it:y) cout << it << " "; cout << #x << endl;
typedef pair<int,int>pii;
typedef pair<pii,int>pi2;
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
inline int combine(int a, int b){
return max(a,b);
}
struct node{
int s,e,m;
node *l,*r;
int v;
node(int ss, int ee):s(ss),e(ee),m((s+e)>>1),v(1e15){
if(s!=e){
l=new node(s,m);
r=new node(m+1,e);
}
}
void upd(int x, int y){
if(s==e){
v=y;
return;
}
if(x<=m) l->upd(x,y);
else r->upd(x,y);
v=combine(l->v,r->v);
}
int query(int x, int y){
if(x<=s&&y>=e){
return v;
}
if(y<=m) return l->query(x,y);
if(x>m) return r->query(x,y);
return combine(l->query(x,m),r->query(m+1,y));
}
}*root;
bool cmp(const pii a, const pii b){
return a.second < b.second;
}
int two[20][200005];
pii arr2[100005];
int n,k;
int f(int st, int rgt){
if(st>rgt) return 0;
int l=0;
int r=n-1;
int best=n;
int mid;
while(l<=r){
mid=(l+r)/2;
int hold=root->query(0,mid);
if(hold>=st){
best=mid;
r=mid-1;
}
else l=mid+1;
}
st=best;
int ans=arr2[st].second<=rgt;
for(int y=18;y>=0;y--){
if(two[y][st]==0) continue;
if(arr2[two[y][st]].second<=rgt){
st=two[y][st];
ans+=1<<y;
}
}
return ans;
}
void solve(){
cin >> n >> k;
pii arr[n];
vector<int>dis;
for(int x=0;x<n;x++){
cin >> arr[x].first >> arr[x].second;
dis.push_back(arr[x].first);
dis.push_back(arr[x].second);
}
sort(dis.begin(),dis.end());
dis.resize(unique(dis.begin(),dis.end())-dis.begin());
for(int x=0;x<n;x++){
arr[x].first=lower_bound(dis.begin(),dis.end(),arr[x].first)-dis.begin()+1;
arr[x].second=lower_bound(dis.begin(),dis.end(),arr[x].second)-dis.begin()+1;
//cout << arr[x].first << " " << arr[x].second << "\n";
arr2[x]=arr[x];
}
sort(arr2,arr2+n,cmp);
root=new node(0,n+5);
for(int x=0;x<n;x++){
//show2(x,x,arr[x].first,arr[x].first);
root->upd(x,arr2[x].first);
}
for(int x=n-1;x>=0;x--){
int l=0;
int r=n-1;
int best=n;
int mid;
while(l<=r){
mid=(l+r)/2;
int hold=root->query(0,mid);
if(hold>=arr2[x].second){
best=mid;
r=mid-1;
}
else l=mid+1;
}
//show2(x,x,best,best);
if(best!=n){
two[0][x]=best;
for(int y=0;y<18;y++){
two[y+1][x]=two[y][two[y][x]];
}
}
}
set<pair<pii,int>>se;
int counter=f(1,2*n);
//show(counter,counter);
if(counter<k){
cout << -1;
return;
}
se.insert({{1,2*n},counter});
//show(counter,counter);
vector<int>v;
for(int x=0;x<n;x++){
auto it=se.upper_bound({{arr[x].first,1e15},1e15});
if(it==se.begin()) continue;
//show(x,x);
it--;
pair<pii,int>hold=*it;
if(hold.first.first>arr[x].first || hold.first.second<arr[x].second) continue;
//show(x,x);
int a=f(hold.first.first,arr[x].first);
int b=f(arr[x].second,hold.first.second);
//show2(a,a,b,b);
if(counter-hold.second+a+b+1>=k){
se.erase(se.find(hold));
if(hold.first.first<arr[x].first){
se.insert({{hold.first.first,arr[x].first},a});
}
if(arr[x].second<hold.first.second){
se.insert({{arr[x].second,hold.first.second},b});
}
v.push_back(x+1);
}
}
for(int x=0;x<k;x++) cout << v[x] << "\n";
}
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
//freopen("lineup.in","r",stdin);
//freopen("lineup.out","w",stdout);
int t=1;
//cin >> t;
while(t--){
solve();
}
}
# | 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... |