結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー SSRSSSRS
提出日時 2021-11-26 23:05:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,997 bytes
コンパイル時間 1,898 ms
コンパイル使用メモリ 184,896 KB
実行使用メモリ 23,420 KB
最終ジャッジ日時 2023-09-12 05:52:03
合計ジャッジ時間 10,451 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 9 ms
4,376 KB
testcase_02 AC 10 ms
4,380 KB
testcase_03 AC 9 ms
4,380 KB
testcase_04 AC 10 ms
4,376 KB
testcase_05 AC 9 ms
4,376 KB
testcase_06 AC 329 ms
8,756 KB
testcase_07 AC 349 ms
11,976 KB
testcase_08 AC 295 ms
10,496 KB
testcase_09 AC 309 ms
8,604 KB
testcase_10 AC 324 ms
12,552 KB
testcase_11 AC 408 ms
12,996 KB
testcase_12 AC 391 ms
13,008 KB
testcase_13 AC 405 ms
12,908 KB
testcase_14 AC 381 ms
13,188 KB
testcase_15 AC 407 ms
13,064 KB
testcase_16 AC 512 ms
23,076 KB
testcase_17 AC 622 ms
23,072 KB
testcase_18 AC 553 ms
23,124 KB
testcase_19 AC 533 ms
23,264 KB
testcase_20 AC 570 ms
23,064 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 213 ms
23,420 KB
testcase_26 AC 213 ms
23,120 KB
testcase_27 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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 dual_segment_tree{
	int N;
	vector<T> ST;
	dual_segment_tree(vector<T> A){
		int n = A.size();
		N = 1;
		while (N < n){
			N *= 2;
		}
		ST = vector<T>(N * 2 - 1, 0);
		for (int i = 0; i < n; i++){
			ST[N - 1 + i] = A[i];
		}
	}
	T operator [](int k){
		k += N - 1;
		T ans = ST[k];
		while (k > 0){
			k = (k - 1) / 2;
			ans = max(ans, ST[k]);
		}
		return ans;
	}
	void range_chmax(int L, int R, T x, int i, int l, int r){
		if (R <= l || r <= L){
			return;
		} else if (L <= l && r <= R){
			ST[i] = max(ST[i], x);
			return;
		} 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);
			return;
		}
	}
	void range_chmax(int L, int R, T x){
		range_chmax(L, R, x, 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());
      dual_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 (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 (ST2.range_min(p, mid) >= x){
            tv2 = mid;
          } else {
            fv2 = mid;
          }
        }
        assert(ST2.range_min(tv1, tv2) >= x);
        if (tv1 > 0){
          assert(ST2.range_min(tv1 - 1, tv2) < x);
        }
        if (tv2 < N){
          assert(ST2.range_min(tv1, tv2 + 1) < x);
        }
        ST1.range_chmax(tv1, tv2, x);
      }
      for (int j = 0; j < N; j++){
        if (ST1[j] != B[j]){
          ok = false;
        }
      }
      if (ok){
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  }
}
0