제출 #530073

#제출 시각아이디문제언어결과실행 시간메모리
530073Koosha_mvEvent Hopping 2 (JOI21_event2)C++14
0 / 100
99 ms46848 KiB
#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]);
		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:95:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   95 | main(){
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...