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>
struct ST{
vector<pii> t;
int n;
ST(int ns){
n = ns;
t.resize(4 * n);
}
void upd(int v, int tl, int tr, int& p, int& x){
if (tl == tr){
t[v] = {x, tl};
return;
}
int tm = (tl + tr) / 2, vv = 2 * v;
if (p <= tm){
upd(vv, tl, tm, p, x);
}
else {
upd(vv + 1, tm + 1, tr, p, x);
}
t[v] = max(t[vv], t[vv + 1]);
}
void upd(int p, int x){
upd(1, 1, n, p, x);
}
pii get(int v, int tl, int tr, int& l, int& r){
if (l > tr || r < tl) return {0, 0};
if (l <= tl && tr <= r) return t[v];
int tm = (tl + tr) / 2, vv = 2 * v;
return max(get(vv, tl, tm, l, r), get(vv + 1, tm + 1, tr, l, r));
}
pii get(int l, int r){
return get(1, 1, n, l, r);
}
};
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<arr3> st;
for (int i = l; i <= r; i++){
st.pb({b[i], a[i], i});
}
sort(st.begin(), st.end());
vector<pii> x;
for (int i = 0; i < (int) st.size(); i++){
x.pb({st[i][1], i + 1});
}
sort(x.begin(), x.end());
ST T(n);
vector<int> p(n + 1), xx;
for (int i = 0; i < x.size(); i++){
T.upd(i + 1, x[i].ss);
p[x[i].ss - 1] = i + 1;
xx.pb(x[i].ff);
}
vector<int> :: iterator it;
set<pii> st1;
for (int i = 0; i < st.size(); i++) st1.insert({st[i][1], i});
bool ind = 1;
for (int j = st.size() - 1; j >= 0; j--){
it = lower_bound(xx.begin(), xx.end(), st[j][0]);
int ii = (int) (it - xx.begin()) + 1;
pii mx = max(T.get(ii, p[j] - 1), T.get(p[j] + 1, n));
if (!mx.ff){
bool k = (st1.find({st[j][1], j}) != st1.end());
if (k) st1.erase({st[j][1], j});
if (st1.empty()){
ind = 0;
break;
}
auto f = prev(st1.end());
if ((*f).ff < st[j][0]){
ind = 0;
break;
}
T.upd(p[(*f).ss], 0);
st1.erase(f);
if (k) st1.insert({st[j][1], j});
continue;
}
T.upd(mx.ss, 0);
int t = x[mx.ss - 1].ss - 1;
st1.erase({st[t][1], t});
T.upd(p[j], 0);
}
cout<<((ind) ? "Yes" : "No")<<"\n";
}
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:71:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for (int i = 0; i < x.size(); i++){
| ~~^~~~~~~~~~
Main.cpp:78: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]
78 | for (int i = 0; i < st.size(); i++) st1.insert({st[i][1], 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... |