結果

問題 No.2242 Cities and Teleporters
ユーザー kotatsugamekotatsugame
提出日時 2023-03-10 21:46:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 634 ms / 3,000 ms
コード長 1,179 bytes
コンパイル時間 808 ms
コンパイル使用メモリ 86,428 KB
実行使用メモリ 48,048 KB
最終ジャッジ日時 2023-10-18 07:31:58
合計ジャッジ時間 13,082 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
24,124 KB
testcase_01 AC 6 ms
24,124 KB
testcase_02 AC 6 ms
24,124 KB
testcase_03 AC 6 ms
24,124 KB
testcase_04 AC 6 ms
24,124 KB
testcase_05 AC 515 ms
48,048 KB
testcase_06 AC 350 ms
48,048 KB
testcase_07 AC 501 ms
48,048 KB
testcase_08 AC 634 ms
48,048 KB
testcase_09 AC 508 ms
48,048 KB
testcase_10 AC 382 ms
48,048 KB
testcase_11 AC 439 ms
48,048 KB
testcase_12 AC 442 ms
48,048 KB
testcase_13 AC 450 ms
48,048 KB
testcase_14 AC 508 ms
48,048 KB
testcase_15 AC 450 ms
48,048 KB
testcase_16 AC 498 ms
48,048 KB
testcase_17 AC 583 ms
48,048 KB
testcase_18 AC 383 ms
47,768 KB
testcase_19 AC 380 ms
47,640 KB
testcase_20 AC 414 ms
47,000 KB
testcase_21 AC 412 ms
47,120 KB
testcase_22 AC 369 ms
47,048 KB
testcase_23 AC 396 ms
48,048 KB
testcase_24 AC 391 ms
48,048 KB
testcase_25 AC 385 ms
48,048 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
using namespace std;
int N;
int H[2<<17],T[2<<17];
int to[19][2<<17];
map<int,vector<int> >idx;
vector<int>Hs;
int inv[2<<17];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>H[i];
		idx[H[i]].push_back(i);
	}
	for(int i=0;i<N;i++)cin>>T[i];
	for(const pair<int,vector<int> >&p:idx)Hs.push_back(p.first);
	{
		auto it=idx.begin();
		to[0][0]=-1;
		for(int i=0;i<Hs.size();i++)
		{
			if(i>0)to[0][i]=to[0][i-1];
			for(int id:it->second)
			{
				inv[id]=i;
				int t=T[id];
				int r=upper_bound(Hs.begin(),Hs.end(),t)-Hs.begin();
				to[0][i]=max(to[0][i],r-1);
			}
			it++;
		}
	}
	for(int k=1;k<19;k++)for(int i=0;i<Hs.size();i++)
	{
		if(to[k-1][i]!=-1)to[k][i]=to[k-1][to[k-1][i]];
		else to[k][i]=-1;
	}
	int Q;cin>>Q;
	for(;Q--;)
	{
		int a,b;cin>>a>>b;a--,b--;
		if(T[a]>=H[b])
		{
			cout<<"1\n";
			continue;
		}
		int u=upper_bound(Hs.begin(),Hs.end(),T[a])-Hs.begin();
		u--;
		if(u<0||to[18][u]<inv[b])
		{
			cout<<"-1\n";
			continue;
		}
		int ans=2;
		for(int k=19;k--;)if(to[k][u]<inv[b])u=to[k][u],ans+=1<<k;
		cout<<ans<<"\n";
	}
}
0