結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー yasuwoyasuwo
提出日時 2021-11-27 00:21:56
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 349 ms / 3,000 ms
コード長 2,930 bytes
コンパイル時間 5,379 ms
コンパイル使用メモリ 308,248 KB
実行使用メモリ 8,964 KB
最終ジャッジ日時 2023-09-12 06:11:03
合計ジャッジ時間 8,058 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 3 ms
4,384 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 3 ms
4,376 KB
testcase_04 AC 3 ms
4,380 KB
testcase_05 AC 4 ms
4,384 KB
testcase_06 AC 48 ms
4,544 KB
testcase_07 AC 49 ms
6,004 KB
testcase_08 AC 48 ms
5,664 KB
testcase_09 AC 48 ms
4,652 KB
testcase_10 AC 49 ms
5,844 KB
testcase_11 AC 54 ms
5,944 KB
testcase_12 AC 45 ms
6,048 KB
testcase_13 AC 48 ms
6,048 KB
testcase_14 AC 44 ms
6,220 KB
testcase_15 AC 49 ms
6,076 KB
testcase_16 AC 58 ms
8,944 KB
testcase_17 AC 58 ms
8,568 KB
testcase_18 AC 59 ms
8,916 KB
testcase_19 AC 46 ms
8,896 KB
testcase_20 AC 44 ms
8,944 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 32 ms
4,380 KB
testcase_25 AC 349 ms
8,896 KB
testcase_26 AC 38 ms
8,964 KB
testcase_27 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "main.cpp"
#include <bits/stdc++.h>
#include <atcoder/all>
// #include "library/templates/template.cpp"
using namespace atcoder;
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const std::string YES = "Yes";
const std::string NO = "No";

using S = int;
S op(S x, S y) { return max(x, y); }
S e() { return 0; }

S opmin(S x, S y) { return min(x, y); }
S emin() { return 1e9; }

bool solve(int N, vector<int> &A, vector<int> &B)
{
    for (int i = 0; i < N; i++)
    {
        if (A[i] > B[i])
        {
            return false;
        }
    }
    segtree<S, op, e> seg(A);
    segtree<S, opmin, emin> segB(B);
    int le = 0, ri = 0;
    while (ri < N)
    {
        while (ri + 1 < N && B[le] == B[ri + 1])
        {
            ri++;
        }
        if (seg.prod(le, ri + 1) < B[le])
        {
            // seg.prod(le, ri + 1) < B[le]
            int riok = ri + 1, ring = N;
            while (abs(ring - riok) > 1)
            {
                int rimid = (riok + ring) / 2;
                if (seg.prod(le, rimid) < B[le])
                {
                    riok = rimid;
                }
                else
                {
                    ring = rimid;
                }
            }
            bool isok = false;
            if (seg.prod(le, ring) == B[le])
            {
                if (segB.prod(le, ring) == B[le])
                {
                    // ok
                    isok = true;
                }
            }
            if (!isok)
            {
                int leok = le, leng = 0;
                while (abs(leok - leng) > 1)
                {
                    int lemid = (leok + leng) / 2;
                    if (seg.prod(lemid, ri + 1) < B[le])
                    {
                        leok = lemid;
                    }
                    else
                    {
                        leng = lemid;
                    }
                }
                if (seg.prod(leng, ri + 1) == B[le])
                {
                    if (segB.prod(leng, ri + 1) == B[le])
                    {
                        // ok
                        isok = true;
                    }
                }
            }

            if (!isok)
            {
                return false;
            }
        }
        le = ri + 1;
        ri = ri + 1;
    }
    return true;
}

int main()
{
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int T;
    cin >> T;
    while (T--)
    {
        int N;
        cin >> N;
        vector<int> A(N), B(N);
        for (int i = 0; i < N; i++)
        {
            cin >> A[i];
        }
        for (int i = 0; i < N; i++)
        {
            cin >> B[i];
        }
        cout << (solve(N, A, B) ? YES : NO) << "\n";
    }

    return 0;
}
0