結果

問題 No.1768 The frog in the well knows the great ocean.
ユーザー auauaauaua
提出日時 2021-11-26 23:05:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,710 bytes
コンパイル時間 2,184 ms
コンパイル使用メモリ 184,764 KB
実行使用メモリ 37,100 KB
最終ジャッジ日時 2023-09-12 05:52:26
合計ジャッジ時間 9,153 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 9 ms
4,384 KB
testcase_02 AC 9 ms
4,380 KB
testcase_03 AC 9 ms
4,384 KB
testcase_04 AC 9 ms
4,380 KB
testcase_05 AC 10 ms
4,384 KB
testcase_06 AC 282 ms
12,052 KB
testcase_07 AC 326 ms
18,620 KB
testcase_08 AC 268 ms
15,496 KB
testcase_09 AC 268 ms
12,044 KB
testcase_10 AC 298 ms
19,396 KB
testcase_11 AC 364 ms
20,308 KB
testcase_12 AC 303 ms
19,632 KB
testcase_13 AC 284 ms
19,928 KB
testcase_14 AC 300 ms
19,888 KB
testcase_15 AC 348 ms
20,320 KB
testcase_16 AC 382 ms
37,100 KB
testcase_17 AC 376 ms
37,084 KB
testcase_18 AC 384 ms
37,012 KB
testcase_19 AC 300 ms
30,492 KB
testcase_20 AC 373 ms
35,972 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 2 ms
4,384 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 220 ms
28,172 KB
testcase_26 AC 201 ms
27,360 KB
testcase_27 AC 2 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
//#define vec vector<ll>
//#define mat vector<vector<ll> >
#define fi first
#define se second
#define double long double
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
//typedef long double ld;
typedef complex<double> Complex;
const ll INF=1e9+7;
const ll MOD=998244353;
const ll inf=INF*INF;
const ll mod=MOD;
const ll MAX=200010;
const double PI=acos(-1.0);
typedef vector<vector<ll> > mat;
typedef vector<ll> vec;



void solve(){
    ll t;cin>>t;
    while(t--){
        ll n;cin>>n;
        vector<ll>a(n),b(n);
        vector<vector<ll> >c(n);
        vector<pll>d(n);
        rep(i,n){
            cin>>a[i];
            a[i]--;
            c[a[i]].pb(i);
        }
        rep(i,n){
            cin>>b[i];
            b[i]--;
            d[i]=mp(b[i],i);
        }
        sort(all(d));
        bool ans=1;
        set<ll>st,st2;
        queue<ll>q;
        rep(i,n){
            ll k=d[i].se;
            if(b[k]<a[k]){
                ans=0;
                break;
            }else if(b[k]>a[k]){
                auto itr=lower_bound(all(c[b[k]]),k);
                bool f=0;
                if(itr!=c[b[k]].end()){
                    ll s=*itr;
                    auto itr2=st.lower_bound(k);
                    if(itr2!=st.end()){
                        ll z=*itr2;
                        if(z>s){
                            f=1;
                        }
                    }else{
                        f=1;
                    }
                }
                if(itr!=c[b[k]].begin()){
                    itr--;
                    ll s=*itr;
                    auto itr2=st2.lower_bound(-k);
                    if(itr2!=st2.end()){
                        ll z=-*itr2;
                        if(z<s){
                            f=1;
                        }
                    }else{
                        f=1;
                    }
                }
                if(!f){
                    ans=0;
                    break;
                }
            }
            q.push(k);
            if(i<n-1&&d[i+1].fi>d[i].fi){
                while(!q.empty()){
                    ll l=q.front();
                    q.pop();
                    st.insert(l);
                    st2.insert(-l);
                }
            }
        }
        cout<<(ans?"Yes":"No")<<endl;
    }
}

signed main(){
    //cin.tie(0);
    //ios::sync_with_stdio(false);
    solve();
}
0