結果

問題 No.2242 Cities and Teleporters
ユーザー olpheolphe
提出日時 2023-03-10 21:55:53
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,310 bytes
コンパイル時間 1,302 ms
コンパイル使用メモリ 123,496 KB
実行使用メモリ 40,152 KB
最終ジャッジ日時 2023-10-18 07:41:44
合計ジャッジ時間 18,425 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
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 AC 659 ms
39,456 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 664 ms
38,408 KB
testcase_23 AC 702 ms
40,128 KB
testcase_24 AC 726 ms
40,128 KB
testcase_25 AC 726 ms
40,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

//constexpr long long int MOD = 1000000007;
constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-8;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

struct Node {
	int height;
	int to;
	int idx;
	bool operator<(const Node& n)const {
		return height < n.height;
	}
};

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N;
	vector<Node>node(N);
	for (int i = 0; i < N; i++) {
		cin >> node[i].height;
		node[i].idx = i;
	}
	for (int i = 0; i < N; i++) {
		cin >> node[i].to;
	}
	sort(node.begin(), node.end());
	vector<int>conv(N);
	for (int i = 0; i < N; i++) {
		conv[node[i].idx] = i;
	}
	vector<int>mxto(N);
	vector<int>mxh(N);
	mxto[0] = node[0].to;
	mxh[0] = node[0].height;
	for (int i = 1; i < N; i++) {
		mxto[i] = max(mxto[i - 1], node[i].to);
		mxh[i] = max(mxh[i - 1], node[i].height);
	}
	vector<vector<int>>height(20, vector<int>(N, -1));
	vector<vector<int>>to(20, vector<int>(N, -1));
	for (int i = 0; i < N; i++) {
		height[0][i] = node[i].to;
	}
	for (int i = 1; i < 20; i++) {
		for (int j = 0; j < N; j++) {
			auto it = upper_bound(mxh.begin(), mxh.end(), height[i - 1][j]);
			if (it != mxh.begin()) {
				height[i][j] = mxto[it - mxh.begin() - 1];
			}
			height[i][j] = max(height[i][j], height[i - 1][j]);
		}
	}
	cin >> K;
	while (K--) {
		cin >> L >> R;
		L--, R--;
		L = conv[L];
		R = conv[R];
		int ans = 1;
		H = node[L].to;
		if (H >= node[R].height) {
			cout << 1 << endl;
			continue;
		}
		auto it = upper_bound(mxh.begin(), mxh.end(), H);
		if (it == mxh.begin()) {
			cout << -1 << endl;
			continue;
		}
		L = it - mxh.begin() - 1;
		if (height.back()[L] < node[R].height) {
			cout << -1 << endl;
			continue;
		}
		for (int i = 19; i >= 0; i--) {
			if (height[i][L] < node[R].height) {
				ans += i << i;
				L = upper_bound(mxh.begin(), mxh.end(), height[i][L]) - mxh.begin() - 1;
			}
		}
		cout << ans + 1 << endl;
	}
}
0