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>
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];
int q; cin>>q;
while (q--){
int l, r; cin>>l>>r;
vector<int> x;
set<pii> st;
for (int i = l; i <= r; i++){
x.pb(i);
st.ins({a[i], i});
}
auto cmp = [&](int i, int j){
return b[i] > b[j];
};
sort(x.begin(), x.end(), cmp);
bool ind = 1;
for (int i: x){
auto it = st.find({a[i], i});
bool k = (it != st.end());
if (k) st.erase(it);
it = st.lower_bound({b[i], 0});
if (it == st.end()){
ind = 0;
break;
}
st.erase(it);
if (k) st.ins({a[i], i});
}
cout<<((ind) ? "Yes" : "No")<<"\n";
}
}
# | 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... |