結果
| 問題 | No.1768 The frog in the well knows the great ocean. |
| コンテスト | |
| ユーザー |
auaua
|
| 提出日時 | 2021-11-26 23:05:15 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,710 bytes |
| 記録 | |
| コンパイル時間 | 1,856 ms |
| コンパイル使用メモリ | 187,672 KB |
| 実行使用メモリ | 37,076 KB |
| 最終ジャッジ日時 | 2024-06-29 18:58:21 |
| 合計ジャッジ時間 | 7,203 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 25 WA * 2 |
ソースコード
#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();
}
auaua