結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー 👑 NachiaNachia
提出日時 2021-11-26 23:21:30
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 201 ms / 3,000 ms
コード長 2,129 bytes
コンパイル時間 1,102 ms
コンパイル使用メモリ 87,800 KB
実行使用メモリ 13,332 KB
最終ジャッジ日時 2023-09-12 05:57:10
合計ジャッジ時間 5,643 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 7 ms
4,376 KB
testcase_02 AC 7 ms
4,376 KB
testcase_03 AC 7 ms
4,380 KB
testcase_04 AC 7 ms
4,380 KB
testcase_05 AC 7 ms
4,380 KB
testcase_06 AC 153 ms
5,724 KB
testcase_07 AC 159 ms
7,896 KB
testcase_08 AC 150 ms
7,816 KB
testcase_09 AC 150 ms
5,848 KB
testcase_10 AC 155 ms
8,284 KB
testcase_11 AC 168 ms
8,256 KB
testcase_12 AC 160 ms
8,376 KB
testcase_13 AC 164 ms
8,380 KB
testcase_14 AC 162 ms
8,324 KB
testcase_15 AC 164 ms
8,504 KB
testcase_16 AC 195 ms
13,332 KB
testcase_17 AC 201 ms
13,328 KB
testcase_18 AC 197 ms
13,276 KB
testcase_19 AC 189 ms
13,276 KB
testcase_20 AC 185 ms
13,332 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 48 ms
4,384 KB
testcase_25 AC 181 ms
13,296 KB
testcase_26 AC 174 ms
13,284 KB
testcase_27 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/segtree>
#include <atcoder/lazysegtree>
using namespace std;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,n) for(int i=0; i<(n); i++)



namespace rmq{
  using S = int;
  S op(S l, S r){ return min(l,r); }
  S e(){ return 1001001001; }
  using rmq = atcoder::segtree<S,op,e>;
  S opx(S l, S r){ return max(l,r); }
  S ex(){ return -1; }
  using rxq = atcoder::segtree<S,opx,ex>;
}


namespace rurmq{
  using S = int;
  S e(){ return -1; }
  S op(S l, S r){ return e(); }
  using F = int;
  S mapping(F f, S x){ if(f == -1) return x; return f; }
  F composition(F f, F x){ if(f == -1) return x; return f; }
  F id(){ return -1; }
  using rurmq = atcoder::lazy_segtree<S,op,e,F,mapping,composition,id>;
}

struct non_greater_than{
    int a;
    bool operator()(int x) const { return a >= x; }
};
struct non_less_than{
    int a;
    bool operator()(int x) const { return a <= x; }
};
struct greater_than{
    int a;
    bool operator()(int x) const { return a <= x; }
};


bool testcase(){
    int N; cin >> N;
    vector<int> A(N); rep(i,N) cin >> A[i];
    vector<int> B(N); rep(i,N) cin >> B[i];

    rmq::rxq rmqA(A);
    rmq::rmq rmqB(B);
    vector<int> idxA(N); rep(i,N) idxA[i] = i;
    sort(idxA.begin(), idxA.end(), [&](int l, int r)->bool{ return A[l] < A[r]; });

    rurmq::rurmq ruqB(N);

    for(int p : idxA){
        int l = max(rmqA.min_left(p, non_greater_than{A[p]}), rmqB.min_left(p, non_less_than{A[p]}));
        int r = min(rmqA.max_right(p, non_greater_than{A[p]}), rmqB.max_right(p, non_less_than{A[p]}));
        //cout << "(" << l <<"," << r << "," << A[p] << ")" << endl;
        ruqB.apply(l,r,A[p]);
    }

    rep(i,N) if(B[i] != ruqB.get(i)) return false;
    return true;
}


int main(){
    int T; cin >> T;
    rep(i,T){
        if(testcase()) cout << "Yes\n";
        else cout << "No\n";
    }
    return 0;
}




struct ios_do_not_sync {
    ios_do_not_sync() {
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
    }
} ios_do_not_sync_instance;
0