답안 #602668

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
602668 2022-07-23T09:59:27 Z Abdulmohsen1284 Event Hopping (BOI22_events) C++14
0 / 100
509 ms 56924 KB
#include <bits/stdc++.h> 
using namespace std;

long long bg[300005],en[300005],pa[100005][35],ope=0,twos[40],inf=1e5+1;

long long fin(long long cur,long long lim)
{
	for(int i=32;i>=0;i--)
	{
		//cout<<ope<<" ";
		if(en[pa[cur][i]]<=en[lim]&&lim!=pa[cur][i])
		{
			if(pa[cur][i]!=cur)
			ope+=twos[i];
			cur=pa[cur][i];
		}
		//cout<<cur<<" ";
	}
	return cur;
}

int main()
{
	twos[0]=1;
	for(int i=1;i<34;i++)
		twos[i]=twos[i-1]*2;
	long long n,q;
	bg[inf]=2e9;
	en[inf]=2e9;

	pa[inf][0]=inf;
	cin>>n>>q;
	set <pair <pair <long long, bool> , long long > > h;
	set <pair <long long, long long > > cur;
	cur.insert({1000000,inf});
	set <long long> bef[100005];
	bef[inf].insert(99999999999);
	for(int i=0;i<n;i++)
	{
		bef[i].insert(99999999999);
		pa[i][0]=inf;
		cin>>bg[i]>>en[i];
		h.insert({{bg[i],false},i});
		h.insert({{en[i],true},i});
	}

	for(auto i: h)
	{
		if(i.first.second)
		{	
			cur.erase({i.first.first*-1,i.second});
			if(cur.size()>0){
			auto fg = *cur.begin();
			if(en[fg.second]!=en[i.second])
			pa[i.second][0]=fg.second;
			bef[fg.second].insert(bg[i.second]);
			}
		}
		else
		{
			cur.insert({en[i.second]*-1,i.second});
		}
	}
	for(int i=1;i<33;i++)
	{
		for(int j=0;j<n;j++)
		{
			pa[j][i]=pa[pa[j][i-1]][i-1];
			//cout<<pa[j][i]<<" ";
		}
	}
	for(int i=0;i<q;i++)
	{
		long long fr,sc;
		ope=1;
		cin>>fr>>sc;
		fr--;
		sc--;
		if(fr==sc){
			cout<<"0\n";
			continue;
		}
		long long las=fin(fr,sc);
		if(*bef[sc].begin()<=en[las]&&en[sc]>=en[fr]&&las!=inf)
		{
			cout<<ope<<"\n";
		}
		else{
			las=pa[las][0];
			if(*bef[sc].begin()<=en[las]&&en[sc]>=en[fr])
		{
			cout<<ope+1<<"\n";
		}
		else
			cout<<"impossible\n";
		}
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4948 KB Output is correct
2 Incorrect 468 ms 56904 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 5 ms 5412 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 5 ms 5412 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4948 KB Output is correct
2 Correct 3 ms 4948 KB Output is correct
3 Incorrect 5 ms 5412 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 509 ms 56924 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4948 KB Output is correct
2 Incorrect 468 ms 56904 KB Output isn't correct
3 Halted 0 ms 0 KB -