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 pii pair<int,int>
#define fs first
#define sc second
#define _all(T) T.begin(),T.end()
const int mxn = 2e5+10;
struct SEG{
#define mid ((l+r)>>1)
#define ls now*2+1
#define rs now*2+2
int seg[mxn*4];
SEG(){
for(auto &i:seg)i = 0;
}
void init(){
for(auto &i:seg)i = 0;
return;
}
void modify(int now,int l,int r,int p,int v){
if(l == r){
seg[now] = max(seg[now],v);
return;
}
if(mid>=p)modify(ls,l,mid,p,v);
else modify(rs,mid+1,r,p,v);
seg[now] = max(seg[ls],seg[rs]);
}
int getval(int now,int l,int r,int s,int e){
if(l>=s&&e>=r)return seg[now];
if(mid>=e)return getval(ls,l,mid,s,e);
else if(mid<s)return getval(rs,mid+1,r,s,e);
else return max(getval(ls,l,mid,s,e),getval(rs,mid+1,r,s,e));
}
};
struct SEG2{
pii seg[mxn*4];
SEG2(){}
void modify(int now,int l,int r,int s,int e){
if(l>=s&&e>=r){
seg[now].sc = 1;
return;
}
if(mid>=s)modify(ls,l,mid,s,e);
if(mid<e)modify(rs,mid+1,r,s,e);
seg[now].fs = seg[ls].fs|seg[rs].fs|seg[ls].sc|seg[rs].sc;
return;
}
int getval(int now,int l,int r,int s,int e){
if(l>=s&&e>=r)return seg[now].fs|seg[now].sc;
if(mid>=e)return seg[now].sc|getval(ls,l,mid,s,e);
else if(mid<s)return seg[now].sc|getval(rs,mid+1,r,s,e);
else return seg[now].sc|getval(ls,l,mid,s,e)|getval(rs,mid+1,r,s,e);
}
#undef ls
#undef rs
#undef mid
};
SEG seg;
SEG2 seg2;
pii arr[mxn];
vector<int> all;
int N,K;
int rdp[mxn],ldp[mxn];
vector<int> v[mxn];
set<pii> st;
int main(){
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>N>>K;
for(int i = 1;i<=N;i++){
auto &[a,b] = arr[i];
cin>>a>>b;
all.push_back(a);all.push_back(b-1);
}
all.push_back(-1);
sort(_all(all));all.resize(unique(_all(all))-all.begin());
for(int i = 1;i<=N;i++){
auto &[a,b] = arr[i];
a = lower_bound(_all(all),a)-all.begin();
b = lower_bound(_all(all),b-1)-all.begin();
}
vector<int> perm(N);
iota(perm.begin(),perm.end(),1);
sort(perm.begin(),perm.end(),[](int a,int b){return arr[a].fs>arr[b].fs;});
seg.init();
for(auto &now:perm){
rdp[now] = seg.getval(0,0,all.size(),arr[now].sc+1,all.size())+1;
seg.modify(0,0,all.size(),arr[now].fs,rdp[now]);
}
seg.init();
sort(perm.begin(),perm.end(),[](int a,int b){return arr[a].sc<arr[b].sc;});
for(auto &now:perm){
ldp[now] = seg.getval(0,0,all.size(),0,arr[now].fs-1)+1;
seg.modify(0,0,all.size(),arr[now].sc,ldp[now]);
}
vector<int> ans;
int rp = -1;
for(int now = 1;now<=N&&ans.size()<K;now++){
if(K-ans.size()<=rdp[now]&&rp<arr[now].fs)rp = arr[now].sc,ans.push_back(now);
}
/*
for(int now = 1;now<=N&&ans.size()<K;now++){
if(ldp[now]+rdp[now]-1<K||seg2.getval(0,0,all.size(),arr[now].fs,arr[now].sc))continue;
ans.push_back(now);
seg2.modify(0,0,all.size(),arr[now].fs,arr[now].sc);
}
*/
if(ans.size() == K)for(auto &i:ans)cout<<i<<'\n';
else cout<<"-1\n";
return 0;
}
Compilation message (stderr)
event2.cpp: In function 'int main()':
event2.cpp:106:36: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
106 | for(int now = 1;now<=N&&ans.size()<K;now++){
| ~~~~~~~~~~^~
event2.cpp:107:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
107 | if(K-ans.size()<=rdp[now]&&rp<arr[now].fs)rp = arr[now].sc,ans.push_back(now);
| ~~~~~~~~~~~~^~~~~~~~~~
event2.cpp:116:16: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
116 | if(ans.size() == K)for(auto &i:ans)cout<<i<<'\n';
| ~~~~~~~~~~~^~~~
# | 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... |