結果
問題 | No.1768 The frog in the well knows the great ocean. |
ユーザー | SSRS |
提出日時 | 2021-11-26 23:10:10 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,935 ms / 3,000 ms |
コード長 | 3,452 bytes |
コンパイル時間 | 2,264 ms |
コンパイル使用メモリ | 189,736 KB |
実行使用メモリ | 25,484 KB |
最終ジャッジ日時 | 2024-06-29 19:01:04 |
合計ジャッジ時間 | 47,555 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 45 ms
6,944 KB |
testcase_02 | AC | 43 ms
6,944 KB |
testcase_03 | AC | 44 ms
6,940 KB |
testcase_04 | AC | 43 ms
6,940 KB |
testcase_05 | AC | 44 ms
6,944 KB |
testcase_06 | AC | 2,151 ms
9,288 KB |
testcase_07 | AC | 2,286 ms
13,436 KB |
testcase_08 | AC | 1,948 ms
11,600 KB |
testcase_09 | AC | 2,014 ms
9,244 KB |
testcase_10 | AC | 2,132 ms
13,788 KB |
testcase_11 | AC | 2,505 ms
14,412 KB |
testcase_12 | AC | 2,489 ms
14,288 KB |
testcase_13 | AC | 2,472 ms
14,416 KB |
testcase_14 | AC | 2,482 ms
14,416 KB |
testcase_15 | AC | 2,513 ms
14,288 KB |
testcase_16 | AC | 2,935 ms
25,484 KB |
testcase_17 | AC | 2,930 ms
25,356 KB |
testcase_18 | AC | 2,918 ms
25,228 KB |
testcase_19 | AC | 2,885 ms
25,356 KB |
testcase_20 | AC | 2,847 ms
25,356 KB |
testcase_21 | AC | 1 ms
6,940 KB |
testcase_22 | AC | 2 ms
6,944 KB |
testcase_23 | AC | 3 ms
6,944 KB |
testcase_24 | AC | 131 ms
6,940 KB |
testcase_25 | AC | 2,769 ms
25,464 KB |
testcase_26 | AC | 2,848 ms
25,352 KB |
testcase_27 | AC | 2 ms
6,940 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; template <typename T> struct sparse_table{ vector<vector<T>> ST; sparse_table(vector<T> &A){ int N = A.size(); int LOG = 32 - __builtin_clz(N); ST = vector<vector<T>>(LOG, vector<T>(N)); for (int i = 0; i < N; i++){ ST[0][i] = A[i]; } for (int i = 0; i < LOG - 1; i++){ for (int j = 0; j < N - (1 << i); j++){ ST[i + 1][j] = min(ST[i][j], ST[i][j + (1 << i)]); } } } T range_min(int L, int R){ int d = 31 - __builtin_clz(R - L); return min(ST[d][L], ST[d][R - (1 << d)]); } }; template <typename T> struct lazy_segment_tree{ int N; vector<T> ST; vector<T> lazy; lazy_segment_tree(vector<T> A){ int n = A.size(); N = 1; while (N < n){ N *= 2; } ST = vector<T>(N * 2 - 1, 0); lazy = vector<T>(N * 2 - 1, 0); for (int i = 0; i < n; i++){ ST[N - 1 + i] = A[i]; } for (int i = N - 2; i >= 0; i--){ ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]); } } void eval(int i){ if (i < N - 1){ lazy[i * 2 + 1] = max(lazy[i * 2 + 1], lazy[i]); lazy[i * 2 + 2] = max(lazy[i * 2 + 2], lazy[i]); } ST[i] = max(ST[i], lazy[i]); } void range_chmax(int L, int R, T x, int i, int l, int r){ eval(i); if (R <= l || r <= L){ return; } else if (L <= l && r <= R){ lazy[i] = max(lazy[i], x); eval(i); } else { int m = (l + r) / 2; range_chmax(L, R, x, i * 2 + 1, l, m); range_chmax(L, R, x, i * 2 + 2, m, r); ST[i] = max(ST[i * 2 + 1], ST[i * 2 + 2]); } } void range_chmax(int L, int R, T x){ return range_chmax(L, R, x, 0, 0, N); } T range_max(int L, int R, int i, int l, int r){ eval(i); if (R <= l || r <= L){ return 0; } else if (L <= l && r <= R){ return ST[i]; } else { int m = (l + r) / 2; return max(range_max(L, R, i * 2 + 1, l, m), range_max(L, R, i * 2 + 2, m, r)); } } T range_max(int L, int R){ return range_max(L, R, 0, 0, N); } }; int main(){ int T; cin >> T; for (int i = 0; i < T; i++){ int N; cin >> N; vector<int> A(N); for (int j = 0; j < N; j++){ cin >> A[j]; } vector<int> B(N); for (int j = 0; j < N; j++){ cin >> B[j]; } bool ok = true; for (int j = 0; j < N; j++){ if (B[j] < A[j]){ ok = false; } } if (!ok){ cout << "No" << endl; } else { vector<pair<int, int>> P(N); for (int j = 0; j < N; j++){ P[j] = make_pair(A[j], j); } sort(P.begin(), P.end()); lazy_segment_tree<int> ST1(A); sparse_table<int> ST2(B); for (int j = 0; j < N; j++){ int x = P[j].first; int p = P[j].second; int tv1 = p, fv1 = -1; while (tv1 - fv1 > 1){ int mid = (tv1 + fv1) / 2; if (ST1.range_max(mid, p + 1) <= x && ST2.range_min(mid, p + 1) >= x){ tv1 = mid; } else { fv1 = mid; } } int tv2 = p + 1, fv2 = N + 1; while (fv2 - tv2 > 1){ int mid = (tv2 + fv2) / 2; if (ST1.range_max(p, mid) <= x && ST2.range_min(p, mid) >= x){ tv2 = mid; } else { fv2 = mid; } } ST1.range_chmax(tv1, tv2, x); } for (int j = 0; j < N; j++){ if (ST1.range_max(j, j + 1) != B[j]){ ok = false; } } if (ok){ cout << "Yes" << endl; } else { cout << "No" << endl; } } } }