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;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pl;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tt;
#define all(a) a.begin(), a.end()
#define filter(a) a.erase(unique(all(a)), a.end())
bool solve (vector<int> a, vector<int> b, int n) {
vector<int> pa(n), pb(n);
for (int i = 0; i < n; i++) pa[i] = pb[i] = i;
sort(all(pa), [&] (int i, int j) { return a[i] < a[j]; });
sort(all(pb), [&] (int i, int j) { return b[i] < b[j]; });
vector<int> s(n);
int pos = 0;
for (int i = 0; i < n; i++) {
while (a[pa[pos]] < b[pb[i]]) pos++;
s[i] = pos + (pa[pos] == pb[i]);
}
sort(all(s));
for (int i = 0; i < n; i++)
if (s[i] > i) return 0;
return 1;
}
const int mn = 5e5 + 5;
int a[mn], b[mn];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i];
for (int i = 1; i <= n; i++) cin >> b[i];
int q; cin >> q;
while (q--) {
int l, r; cin >> l >> r;
vector<int> vec_a, vec_b;
for (int i = l; i <= r; i++) {
vec_a.push_back(a[i]);
vec_b.push_back(b[i]);
}
cout << (solve(vec_a, vec_b, r - l + 1) ? "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... |