結果
問題 | No.1768 The frog in the well knows the great ocean. |
ユーザー |
👑 ![]() |
提出日時 | 2021-11-26 23:21:30 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 165 ms / 3,000 ms |
コード長 | 2,129 bytes |
コンパイル時間 | 3,536 ms |
コンパイル使用メモリ | 136,336 KB |
最終ジャッジ日時 | 2025-01-26 01:52:16 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 27 |
ソースコード
#include <iostream> #include <vector> #include <algorithm> #include <atcoder/segtree> #include <atcoder/lazysegtree> using namespace std; using i32 = int32_t; using u32 = uint32_t; using i64 = int64_t; using u64 = uint64_t; #define rep(i,n) for(int i=0; i<(n); i++) namespace rmq{ using S = int; S op(S l, S r){ return min(l,r); } S e(){ return 1001001001; } using rmq = atcoder::segtree<S,op,e>; S opx(S l, S r){ return max(l,r); } S ex(){ return -1; } using rxq = atcoder::segtree<S,opx,ex>; } namespace rurmq{ using S = int; S e(){ return -1; } S op(S l, S r){ return e(); } using F = int; S mapping(F f, S x){ if(f == -1) return x; return f; } F composition(F f, F x){ if(f == -1) return x; return f; } F id(){ return -1; } using rurmq = atcoder::lazy_segtree<S,op,e,F,mapping,composition,id>; } struct non_greater_than{ int a; bool operator()(int x) const { return a >= x; } }; struct non_less_than{ int a; bool operator()(int x) const { return a <= x; } }; struct greater_than{ int a; bool operator()(int x) const { return a <= x; } }; bool testcase(){ int N; cin >> N; vector<int> A(N); rep(i,N) cin >> A[i]; vector<int> B(N); rep(i,N) cin >> B[i]; rmq::rxq rmqA(A); rmq::rmq rmqB(B); vector<int> idxA(N); rep(i,N) idxA[i] = i; sort(idxA.begin(), idxA.end(), [&](int l, int r)->bool{ return A[l] < A[r]; }); rurmq::rurmq ruqB(N); for(int p : idxA){ int l = max(rmqA.min_left(p, non_greater_than{A[p]}), rmqB.min_left(p, non_less_than{A[p]})); int r = min(rmqA.max_right(p, non_greater_than{A[p]}), rmqB.max_right(p, non_less_than{A[p]})); //cout << "(" << l <<"," << r << "," << A[p] << ")" << endl; ruqB.apply(l,r,A[p]); } rep(i,N) if(B[i] != ruqB.get(i)) return false; return true; } int main(){ int T; cin >> T; rep(i,T){ if(testcase()) cout << "Yes\n"; else cout << "No\n"; } return 0; } struct ios_do_not_sync { ios_do_not_sync() { ios::sync_with_stdio(false); cin.tie(nullptr); } } ios_do_not_sync_instance;