結果
問題 | No.1768 The frog in the well knows the great ocean. |
ユーザー | auaua |
提出日時 | 2021-11-26 23:19:06 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 409 ms / 3,000 ms |
コード長 | 3,968 bytes |
コンパイル時間 | 2,169 ms |
コンパイル使用メモリ | 188,908 KB |
実行使用メモリ | 41,304 KB |
最終ジャッジ日時 | 2023-09-12 05:57:53 |
合計ジャッジ時間 | 9,412 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,380 KB |
testcase_01 | AC | 10 ms
4,360 KB |
testcase_02 | AC | 10 ms
4,380 KB |
testcase_03 | AC | 10 ms
4,380 KB |
testcase_04 | AC | 10 ms
4,376 KB |
testcase_05 | AC | 10 ms
4,376 KB |
testcase_06 | AC | 293 ms
13,480 KB |
testcase_07 | AC | 328 ms
20,684 KB |
testcase_08 | AC | 276 ms
17,812 KB |
testcase_09 | AC | 283 ms
13,248 KB |
testcase_10 | AC | 302 ms
21,452 KB |
testcase_11 | AC | 378 ms
22,484 KB |
testcase_12 | AC | 316 ms
21,532 KB |
testcase_13 | AC | 287 ms
22,168 KB |
testcase_14 | AC | 301 ms
22,160 KB |
testcase_15 | AC | 359 ms
22,372 KB |
testcase_16 | AC | 397 ms
41,304 KB |
testcase_17 | AC | 405 ms
41,260 KB |
testcase_18 | AC | 409 ms
41,076 KB |
testcase_19 | AC | 323 ms
34,524 KB |
testcase_20 | AC | 401 ms
40,180 KB |
testcase_21 | AC | 2 ms
4,376 KB |
testcase_22 | AC | 2 ms
4,376 KB |
testcase_23 | AC | 3 ms
4,380 KB |
testcase_24 | AC | 149 ms
4,380 KB |
testcase_25 | AC | 263 ms
32,328 KB |
testcase_26 | AC | 234 ms
31,488 KB |
testcase_27 | AC | 1 ms
4,376 KB |
ソースコード
#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; //SegmentTree template< typename Monoid > struct SegmentTree { using F = function< Monoid(Monoid, Monoid) >; int sz; vector< Monoid > seg; const F f; const Monoid M1; SegmentTree(int n, const F f, const Monoid &M1) : f(f), M1(M1) { sz = 1; while(sz < n) sz <<= 1; seg.assign(2 * sz, M1); } void set(int k, const Monoid &x) { seg[k + sz] = x; } void build() { for(int k = sz - 1; k > 0; k--) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } void update(int k, const Monoid &x) { k += sz; seg[k] = x; while(k >>= 1) { seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]); } } Monoid query(int a, int b) { Monoid L = M1, R = M1; for(a += sz, b += sz; a < b; a >>= 1, b >>= 1) { if(a & 1) L = f(L, seg[a++]); if(b & 1) R = f(seg[--b], R); } return f(L, R); } Monoid operator[](const int &k) const { return seg[k + sz]; } }; 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); SegmentTree<ll>seg(n,[](ll a,ll b){return max(a,b);},0); rep(i,n){ cin>>a[i]; a[i]--; c[a[i]].pb(i); seg.update(i,a[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(seg.query(k,s+1)<=b[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(seg.query(s,k+1)<=b[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(); }