結果
| 問題 |
No.1768 The frog in the well knows the great ocean.
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2021-11-27 00:05:39 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 2,733 bytes |
| コンパイル時間 | 4,846 ms |
| コンパイル使用メモリ | 310,296 KB |
| 実行使用メモリ | 10,752 KB |
| 最終ジャッジ日時 | 2024-06-29 19:10:19 |
| 合計ジャッジ時間 | 9,770 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | TLE * 1 -- * 26 |
ソースコード
#line 1 "main.cpp"
#include <bits/stdc++.h>
#include <atcoder/all>
// #include "library/templates/template.cpp"
using namespace atcoder;
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const std::string YES = "Yes";
const std::string NO = "No";
using S = int;
S op(S x, S y) { return max(x, y); }
S e() { return 0; }
bool solve(int N, vector<int> &A, vector<int> &B)
{
for (int i = 0; i < N; i++)
{
if (A[i] > B[i])
{
return false;
}
}
segtree<S, op, e> seg(A), segB(B);
int le = 0, ri = 0;
while (ri < N)
{
while (ri + 1 < N && B[le] == B[ri + 1])
{
ri++;
}
if (seg.prod(le, ri + 1) == B[le])
{
// ok
}
else
{
// seg.prod(le, ri + 1) < B[le]
int riok = ri + 1, ring = N;
while (abs(ring - riok))
{
int rimid = (riok + ring) / 2;
if (seg.prod(le, rimid) < B[le])
{
riok = rimid;
}
else
{
ring = rimid;
}
}
bool isok = false;
if (seg.prod(le, ring) == B[le])
{
if (segB.prod(le, ring) == B[le])
{
// ok
isok = true;
}
}
int leok = le, leng = 0;
while (abs(ring - riok))
{
int lemid = (leok + leng) / 2;
if (seg.prod(leok, ri) < B[le])
{
leok = lemid;
}
else
{
leng = lemid;
}
}
if (seg.prod(leng, ri) == B[le])
{
if (segB.prod(leng, ri) == B[le])
{
// ok
isok = true;
}
}
if (!isok)
{
return false;
}
}
le = ri + 1;
ri = ri + 1;
}
return true;
}
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int T;
cin >> T;
while (T--)
{
int N;
cin >> N;
vector<int> A(N), B(N);
for (int i = 0; i < N; i++)
{
cin >> A[i];
}
for (int i = 0; i < N; i++)
{
cin >> B[i];
}
cout << (solve(N, A, B) ? YES : NO) << endl;
}
return 0;
}