結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー milanis48663220milanis48663220
提出日時 2021-11-27 00:27:14
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 325 ms / 3,000 ms
コード長 3,059 bytes
コンパイル時間 1,634 ms
コンパイル使用メモリ 128,532 KB
実行使用メモリ 24,972 KB
最終ジャッジ日時 2023-09-12 05:58:01
合計ジャッジ時間 7,786 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 9 ms
4,380 KB
testcase_02 AC 9 ms
4,376 KB
testcase_03 AC 9 ms
4,380 KB
testcase_04 AC 9 ms
4,376 KB
testcase_05 AC 9 ms
4,376 KB
testcase_06 AC 245 ms
9,980 KB
testcase_07 AC 264 ms
12,844 KB
testcase_08 AC 239 ms
11,168 KB
testcase_09 AC 232 ms
9,172 KB
testcase_10 AC 247 ms
13,372 KB
testcase_11 AC 287 ms
14,108 KB
testcase_12 AC 268 ms
14,096 KB
testcase_13 AC 246 ms
14,012 KB
testcase_14 AC 255 ms
14,184 KB
testcase_15 AC 282 ms
14,252 KB
testcase_16 AC 325 ms
24,272 KB
testcase_17 AC 324 ms
24,348 KB
testcase_18 AC 320 ms
24,284 KB
testcase_19 AC 288 ms
24,288 KB
testcase_20 AC 313 ms
24,176 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 3 ms
4,380 KB
testcase_24 AC 126 ms
4,376 KB
testcase_25 AC 312 ms
24,944 KB
testcase_26 AC 288 ms
24,972 KB
testcase_27 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cmath>
#include <numeric>
#include <functional>
#include <cassert>
#include <atcoder/lazysegtree>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

template<typename T>
vector<vector<T>> vec2d(int n, int m, T v){
    return vector<vector<T>>(n, vector<T>(m, v));
}

template<typename T>
vector<vector<vector<T>>> vec3d(int n, int m, int k, T v){
    return vector<vector<vector<T>>>(n, vector<vector<T>>(m, vector<T>(k, v)));
}

template<typename T>
void print_vector(vector<T> v, char delimiter=' '){
    if(v.empty()) {
        cout << endl;
        return;
    }
    for(int i = 0; i+1 < v.size(); i++) cout << v[i] << delimiter;
    cout << v.back() << endl;
}


using T = int;
using S = int;
T INF = 1e9;
T e(){
    return -INF;
}
T op(T a, T b){
    return max(a, b);
}
T id(){
    return -1;
}
T mapping(S a, T b){
    if(a == id()) return b;
    return a;
}
T composition(T a, T b){
    return max(a, b);
}

using Seg = atcoder::lazy_segtree<T, op, e, S, mapping, composition, id>;

void solve(){
    int n; cin >> n;
    vector<int> a(n), b(n);
    vector<vector<int>> a_idx(n), b_idx(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
        a_idx[a[i]].push_back(i);
    }
    for(int i = 0; i < n; i++) {
        cin >> b[i];
        b[i]--;
        b_idx[b[i]].push_back(i);
    }
    Seg seg(n);
    for(int j = 0; j < n; j++) seg.apply(j, j+1, a[j]);
    for(int i = 0; i < n; i++){
        for(int idx: a_idx[i]){
            auto g = [&](T x){
                return x <= i;
            };
            int l = seg.min_left(idx+1, g);
            int r = seg.max_right(idx, g);
            // cout << seg.prod(l, idx+1) << endl; 
            // cout << l << ':' << r << ' ' << i << endl;
            // for(int j = l; j < r; j++) seg.set(j, i);
            // for(int j = 0; j < n; j++) cout << seg.get(j) << ' ';
            // cout << endl;
            seg.apply(l, r, i);
            // seg.apply(idx, r, i);
            // for(int j = 0; j < n; j++) cout << seg.get(j) << ' ';
            // cout << endl;
        }
        // for(int j = 0; j < n; j++) cout << seg.get(j) << ' ';
        // cout << endl;
        for(int idx: b_idx[i]){
            if(seg.get(idx) != i){
                cout << "No" << endl;
                return;
            }
            seg.set(idx, INF);
        }
    }
    cout << "Yes" << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int t; cin >> t;
    while(t--) solve();
}
0