This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define eb emplace_back
#define pii pair<int,int>
#define f first
#define s second
pii vals[100005];
int rig[100005],ans[100005];
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int n,k,a,b;
cin>>n>>k;
vector<pii>disc;//discretisation: raw value, index...
for(int i=0;i<n;i++){
cin>>a>>b;
disc.eb(a,i*2);
disc.eb(b,i*2+1);
}
sort(disc.begin(),disc.end());
a=1;
for(int i=0;i<2*n;i++){
if(i>0 && disc[i].f>disc[i-1].f)a++;
if(disc[i].s&1)vals[disc[i].s/2].s=a;
else vals[disc[i].s/2].f=a;
}
for(int i=1;i<=a;i++)rig[i]=LLONG_MAX;
for(int i=0;i<n;i++){
//cout<<vals[i].f<<' '<<vals[i].s<<'\n';
rig[vals[i].f]=min(rig[vals[i].f],vals[i].s);//both should be discretised...
}
vector<pii> v;int it;
v.eb(-a,0);
for(int i=a;i>=1;i--){
if(rig[i]>a)goto end;
it=upper_bound(v.begin(),v.end(),mp(-rig[i],LLONG_MAX))-v.begin()-1;
it=v[it].s+1;
if(v.back().s>=it)goto end;
v.eb(-i,it);
end:;
ans[i]=v.back().s;
}
//for(pii x:v){cout<<-x.f<<' '<<x.s<<'\n';}
int cnt=0,cur=ans[vals[0].f];
if(cur<k){
cout<<"-1";
return 0;
}
cur=0;
int tt;
for(int i=0;i<n && cnt<k;i++){
if(cur+ans[vals[i].f]>=k){
cout<<i+1<<'\n';
cnt++;
cur++;
if(cnt>=k)break;
tt=vals[i].s;
while(vals[i+1].f<tt){
i++;
}
}else{;
}
}
return 0;
}
# | 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... |