結果

問題 No.2242 Cities and Teleporters
ユーザー 沙耶花沙耶花
提出日時 2023-03-11 21:02:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,415 bytes
コンパイル時間 5,240 ms
コンパイル使用メモリ 263,996 KB
実行使用メモリ 31,044 KB
最終ジャッジ日時 2023-10-18 10:19:15
合計ジャッジ時間 28,637 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 RE -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 RE -
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001


int main(){
	
	int n;
	cin>>n;
	
	vector dp(n,vector<int>(20,0));
	vector<int> h(n),t(n);
	rep(i,n){
		scanf("%d",&h[i]);
	}
	vector<int> is;
	rep(i,n){
		scanf("%d",&t[i]);
		is.push_back(i);
	}
	sort(is.begin(),is.end(),[&](int x,int y){
		return h[x]<h[y];
	});
	vector<int> hs(n);
	rep(i,n){
		hs[i] = h[is[i]];
	}
	vector<int> rui(n);
	rep(i,n){
		rui[i] = is[i];
		if(i!=0){
			if(t[rui[i]]<t[rui[i-1]])rui[i] = rui[i-1];
		}
	}
	
	rep(i,n){
		int d = distance(hs.begin(),upper_bound(hs.begin(),hs.end(),t[i]));
		if(d==0){
			dp[i][0] = -1;
		}
		else{
			d--;
			dp[i][0] = rui[d];
		}
		cout<<dp[i][0]<<endl;
	}
	
	for(int i=1;i<20;i++){
		rep(j,n){
			if(dp[j][i-1]==-1){
				dp[j][i] = -1;
			}
			else{
				dp[j][i] = dp[dp[j][i-1]][i-1];
			}
			
		}
	}
	
	int q;
	cin>>q;
	
	rep(_,q){
		int a,b;
		scanf("%d %d",&a,&b);
		a--,b--;
		if(dp[a][0]==-1){
			cout<<-1<<endl;
			continue;
		}
		if(t[a]>=h[b]){
			cout<<1<<endl;
			continue;
		}
		int cur = 0;
		int cp = a;
		for(int i=19;i>=0;i--){
			if(h[b]>t[dp[cp][i]]){
				cur |= 1<<i;
				cp = dp[cp][i];
			}
			
		}
		cur+=2;
		if(cur == (1<<20)+1)cur = -1;
		cout<<cur<<endl;
	}
	
	return 0;
}
0