結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー tko919tko919
提出日時 2021-11-27 00:10:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,266 bytes
コンパイル時間 2,666 ms
コンパイル使用メモリ 206,940 KB
実行使用メモリ 15,540 KB
最終ジャッジ日時 2023-09-12 06:07:31
合計ジャッジ時間 6,515 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 AC 134 ms
7,308 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 149 ms
9,556 KB
testcase_12 WA -
testcase_13 AC 147 ms
9,760 KB
testcase_14 AC 141 ms
9,672 KB
testcase_15 AC 143 ms
9,632 KB
testcase_16 AC 163 ms
15,472 KB
testcase_17 AC 164 ms
15,540 KB
testcase_18 AC 167 ms
15,420 KB
testcase_19 AC 154 ms
15,536 KB
testcase_20 AC 153 ms
15,424 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 115 ms
15,424 KB
testcase_26 AC 115 ms
15,484 KB
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
using ll=long long int;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}

template<typename M,typename N,M (*f)(M,M),M (*g)(M,N),M (*m1)()>struct SegmentTree{
    int sz; vector<M> data;
    SegmentTree(int n){
        sz=1; while(sz<n)sz<<=1; data.assign(2*sz,m1());
    }
    void run(vector<M> v){
        rep(i,0,v.size())data[i+sz]=v[i];
        for(int k=sz-1;k>0;k--)data[k]=f(data[2*k],data[2*k+1]);
    }
    void set(int k,const M &x){
        k+=sz; data[k]=x;
        while(k>>=1)data[k]=f(data[2*k],data[2*k+1]);
    }
    void update(int k,const N &x){
        k+=sz; data[k]=g(data[k],x);
        while(k>>=1)data[k]=f(data[2*k],data[2*k+1]);
    }
    M query(int a,int b){
        M L=m1(),R=m1();
        for(a+=sz,b+=sz;a<b;a>>=1,b>>=1){
            if(a&1)L=f(L,data[a++]);
            if(b&1)R=f(data[--b],R);
       } return f(L,R);
    }
    M operator[](const int &k)const{return data[k+sz];}
};

int f(int a,int b){return max(a,b);}
int g(int a,int b){return b;}
int e(){return 0;}

void solve(int _rot){
    // printf("Case #%d: ",_rot);
    int n;
    cin>>n;
    vector<int> a(n),b(n);
    rep(i,0,n)cin>>a[i];
    rep(i,0,n)cin>>b[i];
    
    rep(i,0,n)if(a[i]>b[i]){
        puts("No");
        return;
    }

    SegmentTree<int,int,f,g,e> seg(n);
    seg.run(a);
    vector pos(n+1,vector<int>());
    rep(i,0,n)pos[a[i]].push_back(i);
    rep(i,0,n){
        if(pos[b[i]].empty()){
            puts("No");
            return;
        }
        bool ng=1;
        int id=lower_bound(ALL(pos[b[i]]),i)-pos[b[i]].begin();
        if(id!=pos[b[i]].size()){
            if(seg.query(i,pos[b[i]][id]+1)<=b[i])ng=0;
        }
        if(id){
            if(seg.query(i,pos[b[i]][id-1]+1)<=b[i])ng=0;
        }
        if(ng){
            puts("No");
            return;
        }
    }
    puts("Yes");
}

int main(){
    int t; scanf("%d",&t);
    rep(rot,0,t)solve(rot+1);
    return 0;
}
0