結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー gazellegazelle
提出日時 2021-11-26 23:08:40
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,990 bytes
コンパイル時間 2,350 ms
コンパイル使用メモリ 213,844 KB
実行使用メモリ 9,728 KB
最終ジャッジ日時 2023-09-12 05:53:01
合計ジャッジ時間 6,053 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 6 ms
4,380 KB
testcase_02 AC 6 ms
4,376 KB
testcase_03 AC 6 ms
4,380 KB
testcase_04 AC 6 ms
4,376 KB
testcase_05 AC 6 ms
4,376 KB
testcase_06 AC 115 ms
5,280 KB
testcase_07 AC 122 ms
6,492 KB
testcase_08 AC 114 ms
6,024 KB
testcase_09 AC 114 ms
5,072 KB
testcase_10 AC 116 ms
6,480 KB
testcase_11 AC 125 ms
6,752 KB
testcase_12 AC 123 ms
6,792 KB
testcase_13 AC 124 ms
6,720 KB
testcase_14 AC 123 ms
6,744 KB
testcase_15 AC 124 ms
6,816 KB
testcase_16 AC 138 ms
9,584 KB
testcase_17 AC 136 ms
9,648 KB
testcase_18 AC 136 ms
9,584 KB
testcase_19 AC 137 ms
9,728 KB
testcase_20 AC 136 ms
9,636 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 102 ms
9,516 KB
testcase_26 AC 114 ms
9,636 KB
testcase_27 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define FOR(i, n, m) for(long long i = (n); i < (long long)(m); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define pb push_back
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
constexpr ll inf = 1000000000;
constexpr ll mod = 998244353;
constexpr ld eps = 1e-6;

template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> p) {
    os << to_string(p.first) << " " << to_string(p.second);
    return os;
}
template <typename T> ostream &operator<<(ostream &os, vector<T> &v) {
    REP(i, v.size()) {
        if(i)
            os << " ";
        os << v[i];
    }
    return os;
}

template <typename T> struct segment_tree {
  private:
    int n;
    const function<T(T, T)> op;
    const T ie;
    vector<T> seq;

  public:
    segment_tree(int _n, function<T(T, T)> op, const T ie) : op(op), ie(ie) {
        n = 1;
        while(n < _n)
            n *= 2;
        seq.resize(2 * n - 1);
        for(int i = 0; i < 2 * n - 1; i++)
            seq[i] = ie;
    }

    void update(int k, const T e) {
        k += n - 1;
        seq[k] = e;
        while(k > 0) {
            k = (k - 1) / 2;
            seq[k] = op(seq[k * 2 + 1], seq[k * 2 + 2]);
        }
    }

    T get(int k) {
        k += n - 1;
        return seq[k];
    }

    T query(int a, int b, int k = 0, int l = 0, int r = -1) {
        if(r == -1)
            r = n;
        if(r <= a || b <= l)
            return ie;
        if(a <= l && r <= b)
            return seq[k];
        T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return op(vl, vr);
    }
};
// segment_tree<ll> rsq(n, [] (ll a, ll b) { return a + b; }, 0)
// segment_tree<ll> rMq(n, [] (ll a, ll b) { return max(a, b); }, -1e18)
// segment_tree<ll> rmq(n, [] (ll a, ll b) { return min(a, b); }, 1e18)

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

    int t;
    cin >> t;

    REP(testcase, t) {
        int n;
        cin >> n;
        vector<int> a(n), b(n);
        REP(i, n) cin >> a[i];
        REP(i, n) cin >> b[i];
        vector<bool> ok(n, false);
        segment_tree<ll> rmq(
            n + 1, [](ll a, ll b) { return min(a, b); }, 1e18);
        REP(i, n) rmq.update(i, b[i]);
        vector<int> last_i(n + 1, -1);

        REP(i, n) {
            last_i[a[i]] = i;
            if(last_i[b[i]] != -1 && rmq.query(last_i[b[i]], i + 1) >= b[i])
                ok[i] = true;
        }

        REP(i, n + 1) last_i[i] = -1;

        for(int i = n - 1; i >= 0; i--) {
            last_i[a[i]] = i;
            if(last_i[b[i]] != -1 && rmq.query(i, last_i[b[i]] + 1) >= b[i])
                ok[i] = true;
        }

        REP(i, n) if(a[i] > b[i]) ok[i] = false;

        if(count(ALL(ok), false) == 0)
            cout << "Yes"
                 << "\n";
        else
            cout << "No"
                 << "\n";
    }
    return 0;
}
0