이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<(x.F)<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
#define int ll
const int N=4e5+99,lg=20;
int n,k,a[N],L[N],R[N],fenwik[N],par[lg][N];
set<int> st;
void add(int x, int val){ for(x++;x<N;x+=x&-x) fenwik[x]+=val; }
int get(int x) { int res=0; for (x++;x>0;x-=x&-x) res+=fenwik[x]; return res; }
void read(){
cin>>n>>k;
vector<int> vec;
f(i,1,n+1){
cin>>L[i]>>R[i];
vec.pb(L[i]);
vec.pb(R[i]);
}
sort(all(vec));
f(i,0,2*n+1) par[0][i]=2*n;
f(i,1,n+1){
L[i]=lower_bound(all(vec),L[i])-vec.begin();
R[i]=lower_bound(all(vec),R[i])-vec.begin();
minm(par[0][L[i]],R[i]);
}
}
void build(){
f(l,0,lg) par[l][2*n]=2*n;
f_(i,2*n-1,0){
minm(par[0][i],par[0][i+1]);
f(l,1,lg) par[l][i]=par[l-1][par[l-1][i]];
}
}
int get(int l,int r){
int now=l,ans=0;
f_(l,lg-1,0){
if(par[l][now]<=r){
ans+=(1<<l);
now=par[l][now];
}
}
return ans;
}
void solve(){
vector<int> res;
int ans=get(0,2*n-1);
add(0,1);
add(2*n-1,0);
st.insert(0);
st.insert(2*n-1);
if(ans<k){
cout<<-1;
return ;
}
f(i,1,n+1){
if(get(R[i]-1)-get(L[i]) || bit(get(L[i]),0)==0 || k==0){
continue ;
}
int l=*prev(st.upper_bound(L[i])),r=*st.upper_bound(L[i]);
if(ans-get(l,r)+get(l,L[i])+get(R[i],r)+1<k) continue ;
k--;
ans=ans-get(l,r)+get(l,L[i])+get(R[i],r);
add(L[i],1);
add(R[i],1);
st.insert(L[i]);
st.insert(R[i]);
res.pb(i);
}
for(auto x : res){
cout<<x<<" ";
}
}
main(){
ios:: sync_with_stdio(0), cin.tie(0), cout.tie(0);
read();
build();
solve();
}
컴파일 시 표준 에러 (stderr) 메시지
event2.cpp:96:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
96 | 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... |