This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
vector<int> b(n);
for (int i = 0; i < n; i++) {
cin >> b[i];
}
int q;
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
--l; --r;
vector<pair<int, int>> ev;
for (int i = l; i <= r; i++) {
ev.emplace_back(b[i], +1);
ev.emplace_back(a[i], -1);
}
sort(ev.begin(), ev.end());
bool ok = true;
int bal = 0;
int mx = 0;
for (auto& p : ev) {
int v = p.second;
bal += v;
if (bal < 0) {
ok = false;
}
if (bal == 0) {
if (mx <= 1) {
ok = false;
}
mx = 0;
}
mx = max(mx, bal);
}
cout << (ok ? "Yes" : "No") << '\n';
}
return 0;
}
# | 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... |