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;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
#define ins insert
#define arr3 array<int, 3>
const int inf = 1e9;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin>>n;
vector<int> a(n + 1), b(n + 1);
for (int i = 1; i <= n; i++) cin>>a[i];
for (int i = 1; i <= n; i++) cin>>b[i];
auto f = [&](int l, int r){
vector<arr3> all;
for (int i = l; i <= r; i++){
all.pb({b[i], a[i], i});
}
sort(all.begin(), all.end());
vector<pii> st;
for (int i = 0; i < all.size(); i++){
st.pb({all[i][1], i});
}
for (int i = (int) all.size() - 1; i >= 0; i--){
int mn = n;
for (auto [x, j]: st){
if (j == i) continue;
if (x >= all[i][0]){
mn = min(mn, j);
}
}
if (mn == n) return 0;
int j = (int) (find(st.begin(), st.end(), make_pair(all[mn][1], mn)) - st.begin());
st.erase(st.begin() + j);
}
return 1;
};
int q; cin>>q;
while (q--){
int l, r; cin>>l>>r;
cout<<(f(l, r) ? "Yes" : "No")<<"\n";
}
}
Compilation message (stderr)
Main.cpp: In lambda function:
Main.cpp:30:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | for (int i = 0; i < all.size(); i++){
| ~~^~~~~~~~~~~~
# | 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... |