結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー first_vilfirst_vil
提出日時 2021-10-23 20:13:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,956 bytes
コンパイル時間 2,457 ms
コンパイル使用メモリ 217,892 KB
実行使用メモリ 41,176 KB
最終ジャッジ日時 2023-09-12 05:46:31
合計ジャッジ時間 9,890 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 11 ms
4,376 KB
testcase_02 AC 11 ms
4,376 KB
testcase_03 AC 10 ms
4,380 KB
testcase_04 AC 11 ms
4,380 KB
testcase_05 AC 11 ms
4,380 KB
testcase_06 AC 311 ms
13,868 KB
testcase_07 AC 342 ms
19,848 KB
testcase_08 AC 295 ms
16,880 KB
testcase_09 AC 297 ms
13,860 KB
testcase_10 AC 318 ms
21,044 KB
testcase_11 AC 372 ms
21,856 KB
testcase_12 AC 340 ms
21,792 KB
testcase_13 AC 313 ms
21,860 KB
testcase_14 AC 338 ms
21,732 KB
testcase_15 AC 356 ms
21,732 KB
testcase_16 AC 429 ms
40,704 KB
testcase_17 AC 455 ms
41,176 KB
testcase_18 AC 461 ms
40,760 KB
testcase_19 AC 388 ms
40,556 KB
testcase_20 AC 448 ms
40,640 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 278 ms
38,700 KB
testcase_26 AC 240 ms
38,624 KB
testcase_27 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;++i)

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; }return false; }

template<class Op> class SparseTable {
	using T = typename Op::T;
	vector<vector<T>> dat;
	vector<int> len;
	int n, log;
public:
	SparseTable(const vector<T>& a) : n(a.size()), log(log2(n)) {
		dat = vector<vector<T>>(log + 1, vector<T>(n));
		len.resize(n + 1);
		rep(i, n)dat[0][i] = a[i];
		rep(j, log)rep(i, n - (1 << j)) {
			dat[j + 1][i] = Op::comp(dat[j][i], dat[j][i + (1 << j)]);
		}
		for (int i = 2; i <= n; ++i)len[i] = len[i >> 1] + 1;
	}
	T value(int l, int r) {
		int k = len[r - l];
		return Op::comp(dat[k][l], dat[k][r - (1 << k)]);
	}
};
template<class Type> struct node {
	using T = Type;
	inline static T comp(T x, T y) { return max(x, y); }
};

void solve() {
	int n; cin >> n;
	vector<int> a(n), b(n);
	rep(i, n) {
		cin >> a[i];
		--a[i];
	}
	rep(i, n) {
		cin >> b[i];
		--b[i];
	}

	set<int> sa, sb;
	rep(i, n)sa.insert(i);
	vector<vector<pair<int, int>>> p(n);
	rep(i, n)p[a[i]].emplace_back(i, true);
	rep(i, n)p[b[i]].emplace_back(i, false);
	SparseTable<node<int>> sp(a);

	for (auto& val : p) {
		for (auto [i, f] : val)if (f)sa.erase(i);
		for (auto [i, f] : val) {
			if (f)continue;
			int l = -1, r = n;
			for (auto it = sa.lower_bound(i);;) {
				if (it != sa.begin())chmax(l, *prev(it));
				if (it != sa.end())chmin(r, *it);
				break;
			}
			for (auto it = sb.lower_bound(i);;) {
				if (it != sb.begin())chmax(l, *prev(it));
				if (it != sb.end())chmin(r, *it);
				break;
			}
			++l, --r;
			if (l > r || sp.value(l, r + 1) != b[i]) {
				cout << "No\n";
				return;
			}
		}
		for (auto [i, f] : val)if (!f)sb.insert(i);
	}

	cout << "Yes\n";
}

int main() {
	int t; cin >> t;
	while (t--)solve();

	return 0;
}
0