// ~~ icebear ~~
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
template<class T>
bool minimize(T &a, const T &b) {
if (a > b) return a = b, true;
return false;
}
template<class T>
bool maximize(T &a, const T &b) {
if (a < b) return a = b, true;
return false;
}
#define FOR(i,a,b) for(int i=(a); i<=(b); ++i)
#define FORR(i,a,b) for(int i=(a); i>=(b); --i)
#define REP(i, n) for(int i=0; i<(n); ++i)
#define RED(i, n) for(int i=(n)-1; i>=0; --i)
#define MASK(i) (1LL << (i))
#define BIT(S, i) (((S) >> (i)) & 1)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define task "icebear"
const int MOD = 1e9 + 7;
const int inf = 1e9 + 27092008;
const ll INF = 1e18 + 27092008;
const int N = 5e5 + 5;
int n, q, a[N], b[N], L[N], R[N];
vector<ii> Q[N];
bool ans[N];
struct IT {
int node[N << 4], lazy[N << 4];
void reset() {
memset(node, -0x3f, sizeof node);
memset(lazy, 0, sizeof lazy);
}
void pushDown(int id) {
if (lazy[id]) {
node[id << 1] = node[id << 1 | 1] = lazy[id];
lazy[id << 1] = lazy[id << 1 | 1] = lazy[id];
lazy[id] = 0;
}
}
void update(int id, int l, int r, int u, int v, int k) {
if (l > v || r < u) return;
if (u <= l && r <= v) {
node[id] = k;
lazy[id] = k;
return;
}
pushDown(id);
int mid = (l + r) >> 1;
update(id << 1, l, mid, u, v, k);
update(id << 1 | 1, mid + 1, r, u, v, k);
node[id] = max(node[id << 1], node[id << 1 | 1]);
}
int getPos(int id, int l, int r, int u, int v) {
if (l > v || r < u) return -inf;
if (u <= l && r <= v) return node[id];
pushDown(id);
int mid = (l + r) >> 1;
return max(getPos(id << 1, l, mid, u, v), getPos(id << 1 | 1, mid + 1, r, u, v));
}
} it;
void init(void) {
cin >> n;
FOR(i, 1, n) cin >> a[i];
FOR(i, 1, n) cin >> b[i];
cin >> q;
FOR(i, 1, q) {
int l, r;
cin >> l >> r;
Q[r].pb(mp(l, i));
}
}
void process(void) {
FOR(i, 1, n) {
L[i] = it.getPos(1, 1, 2 * n, b[i], a[i]);
it.update(1, 1, 2 * n, b[i], a[i], i);
}
it.reset();
FORR(i, n, 1) {
R[i] = -it.getPos(1, 1, 2 * n, b[i], a[i]);
it.update(1, 1, 2 * n, b[i], a[i], -i);
if (R[i] != inf) Q[R[i]].pb(mp(i, -1));
}
it.reset();
FOR(i, 1, n) {
it.update(1, 1, n, i, i, -L[i]);
sort(all(Q[i]), [&](ii &x, ii &y){
return x.se < y.se;
});
for(auto &x : Q[i]) {
if (x.se < 0) it.update(1, 1, n, x.fi, x.fi, -inf);
else {
int L_min = -it.getPos(1, 1, n, x.fi, i);
cout << x.fi << " " << i << " " << L_min << '\n';
ans[x.se] = (L_min < x.fi);
}
}
}
FOR(i, 1, q) cout << (ans[i] ? "No\n" : "Yes\n");
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int tc = 1;
// cin >> tc;
while(tc--) {
init();
process();
}
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:128:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
128 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:129:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
129 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |