This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//#pragma GCC optimize("Ofast,unroll-loops,O3")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,fma,tune=native")
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define x first
#define y second
#define N 500015
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n, q, nxt[N];
pii arr[N];
struct segtree1{
int seg[4 * N];
void init(int l, int r, int i, int c){
seg[i] = c;
if (l == r) return;
int mid = (l + r) >> 1;
init(l, mid, 2 * i, c);
init(mid + 1, r, 2 * i + 1, c);
}
void modify(int l, int r, int i, int p, int c){
if (l == r){
seg[i] = c;
return;
}
int mid = (l + r) >> 1;
if (p <= mid) modify(l, mid, 2 * i, p, c);
else modify(mid + 1, r, 2 * i + 1, p, c);
seg[i] = min(seg[2 * i], seg[2 * i + 1]);
}
int queryp(int l, int r, int i, int ll, int rr, int c){
int mid = (l + r) >> 1;
if (l == r)
return (seg[i] > c) ? 1e9 : l;
else if (ll <= l && rr >= r){
if (seg[i] > c)
return 1e9;
else if (seg[2 * i] <= c)
return queryp(l, mid, 2 * i, ll, rr, c);
else return queryp(mid + 1, r, 2 * i + 1, ll, rr, c);
}
int res = 1e9;
if (ll <= mid)
res = queryp(l, mid, 2 * i, ll, rr, c);
if (rr > mid && res > 1e8)
res = queryp(mid + 1, r, 2 * i + 1, ll, rr, c);
return res;
}
}seg1;
struct segtree2{
int seg[4 * N];
void modify(int l, int r, int i, int p, int c){
if (l == r){
seg[i] = c;
return;
}
int mid = (l + r) >> 1;
if (p <= mid) modify(l, mid, 2 * i, p, c);
else modify(mid + 1, r, 2 * i + 1, p, c);
seg[i] = max(seg[2 * i], seg[2 * i + 1]);
}
int query(int l, int r, int i, int ll, int rr){
if (ll <= l && rr >= r)
return seg[i];
int mid = (l + r) >> 1;
if (rr <= mid) return query(l, mid, 2 * i, ll, rr);
else if (ll > mid) return query(mid + 1, r, 2 * i + 1, ll, rr);
else return max(query(l, mid, 2 * i, ll, rr),
query(mid + 1, r, 2 * i + 1, ll, rr));
}
}seg2;
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
vector<pair<pii, int> > all;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> arr[i].x;
for (int i = 1; i <= n; i++)
cin >> arr[i].y;
seg1.init(1, n, 1, (int)1e9);
for (int i = n; i >= 1; i--){
nxt[i] = seg1.queryp(1, n, 1, i, n, arr[i].x);
seg1.modify(1, n, 1, i, arr[i].y);
}
// for (int i = 1; i <= n; i++)
// cerr << nxt[i] << " \n"[i == n];
for (int i = 1; i < n; i++)
seg2.modify(1, n, 1, i, min(nxt[i], nxt[i + 1]));
cin >> q;
while (q--){
int l, r; cin >> l >> r;
int ans = seg2.query(1, n, 1, l, r - 1);
cout << ((ans > r || nxt[l] > r) ? "No\n" : "Yes\n");
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |