이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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> p(n);
for (int i = 0; i < n; i++) p[i] = i;
sort(all(p), [&] (int i, int j) { return b[i] < b[j]; });
bool pre = 0; int maxCur = 0;
for (int i = 0; i < n; i++) {
maxCur = max(maxCur, a[p[i]]);
bool cur = (i + 1 < n && b[p[i + 1]] < maxCur);
if (!pre && !cur) return 0;
if (!cur) maxCur = 0;
pre = cur;
}
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... |