제출 #417154

#제출 시각아이디문제언어결과실행 시간메모리
417154errorgornEvent Hopping 2 (JOI21_event2)C++17
7 / 100
91 ms12700 KiB
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define endl '\n'

#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound

#define rep(x,s,e) for (auto x=s-(s>e);x!=e-(s>e);(s<e?x++:x--))
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

struct node{
	int s,e,m;
	int val=0;
	node *l,*r;
	
	node (int _s,int _e){
		s=_s,e=_e,m=s+e>>1;
		
		if (s!=e){
			l=new node(s,m);
			r=new node(m+1,e);
		}
	}
	
	void update(int i,int k){
		if (s==e) val=k;
		else{
			if (i<=m) l->update(i,k);
			else r->update(i,k);
			
			val=max(l->val,r->val);
		}
	}
	
	int query(int i,int j){
		if (s==i && e==j) return val;
		else if (j<=m) return l->query(i,j);
		else if (m<i) return r->query(i,j);
		else return max(l->query(i,m),r->query(m+1,j));
	}
} *root=new node(0,100005);

int n,k;
int l[100005],r[100005];
int nxt[100005];
int ans[100005];

int main(){
	cin.tie(0);
	cout.tie(0);
	cin.sync_with_stdio(false);
	
	cin>>n>>k;
	rep(x,0,n) cin>>l[x]>>r[x];
	
	rep(x,0,n){
		nxt[x]=lb(l,l+n,r[x])-l;
	}
	
	rep(x,n,0){
		ans[x]=root->query(nxt[x],n)+1;
		root->update(x,ans[x]);
	}
	
	if (ans[0]<k){
		cout<<"-1"<<endl;
		return 0;
	}
	
	int curr=0;
	while (k){
		if (ans[curr]>=k){
			cout<<curr+1<<endl;
			curr=nxt[curr];
			k--;
		}
		else curr++;
	}
}

컴파일 시 표준 에러 (stderr) 메시지

event2.cpp: In constructor 'node::node(int, int)':
event2.cpp:29:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   29 |   s=_s,e=_e,m=s+e>>1;
      |               ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...