結果
| 問題 | No.1768 The frog in the well knows the great ocean. | 
| コンテスト | |
| ユーザー |  tko919 | 
| 提出日時 | 2021-11-27 00:10:42 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,266 bytes | 
| コンパイル時間 | 2,064 ms | 
| コンパイル使用メモリ | 202,324 KB | 
| 最終ジャッジ日時 | 2025-01-26 02:04:10 | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 14 WA * 13 | 
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:82:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   82 |     int t; scanf("%d",&t);
      |            ~~~~~^~~~~~~~~
            
            ソースコード
#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;
}
            
            
            
        