結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー yasuwoyasuwo
提出日時 2021-11-27 00:20:35
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,929 bytes
コンパイル時間 5,377 ms
コンパイル使用メモリ 309,040 KB
実行使用メモリ 9,156 KB
最終ジャッジ日時 2023-09-12 06:10:26
合計ジャッジ時間 7,564 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 38 ms
5,992 KB
testcase_13 WA -
testcase_14 AC 38 ms
6,072 KB
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 43 ms
8,944 KB
testcase_20 AC 42 ms
8,556 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 AC 38 ms
8,576 KB
testcase_27 AC 1 ms
4,380 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(leok, 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