#include<bits/stdc++.h>
#define ll long long
#define ldb long double
#define db double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,ll>
using namespace std;
const int maxn = 1e5 + 5;
template <class t1,class t2> inline void maxi(t1 &x,t2 y){if (x < y) x = y;}
template <class t1,class t2> inline void mini(t1 &x,t2 y){if (x > y) x = y;}
int a[maxn],b[maxn];
pir Q[maxn];
bool dp[maxn];
void input(int &n,int &q){
cin >> n;
for (int i = 1 ; i <= n ; i++) cin >> a[i];
for (int i = 1 ; i <= n ; i++) cin >> b[i];
cin >> q;
for (int i = 1 ; i <= q ; i++) cin >> Q[i].fi >> Q[i].se;
}
bool possible(int l,int r){
vector <pir> lst;
for (int i = l ; i <= r ; i++) lst.push_back({a[i],b[i]});
sort(lst.begin(),lst.end());
int M = 0;
for (int i = 0 ; i < lst.size() ; i++){
dp[i] = (M >= lst[i].se);
if (!i || dp[i - 1])
maxi(M,lst[i].fi);
}
return dp[lst.size() - 1];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n,q;
input(n,q);
//subtask1
for (int i = 1 ; i <= q ; i++){
cout << ((possible(Q[i].fi,Q[i].se) ? "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... |