#include <iostream>
#include "obstacles.h"
#define fi first
#define se second
#define ll long long
#define pb push_back
using namespace std;
const int N=200005;
int t[N],h[N];
int n,MAXT=0;
bool good(int v, int mah){
int l=v,r=v,mat=t[0],mih=h[v],e=1,y=0;
while(e){
e=0;
if(mat>mah) return true;
if(l>0){
if(mat>h[l-1]){
l--;
e=1;
mih=min(mih,h[l]);
}
}
if(r<n-1){
if(mat>h[r+1]){
r++;
e=1;
mih=min(mih,h[r]);
}
}
if(mih<t[y+1]){
y++;
e=1;
mat=max(mat,t[y]);
}
}
return false;
}
void initialize(vector<int> T, vector<int> H) {
for(int i=0; i<T.size(); i++){
t[i]=T[i];
MAXT=max(MAXT,t[i]);
}
for(int i=0; i<H.size(); i++) h[i]=H[i];
n=H.size();
return;
}
bool can_reach(int L, int R, int S, int D) {
int l=L,r=R,s=S,d=D;
if(s>d) swap(s,d);
if(s==d || s+1==d) return true;
int mah=0;
for(int i=s+1; i<d; i++) mah=max(mah,h[i]);
if(mah>=MAXT) return false;
if(good(s,mah) && good(d,mah)) return true;
return false;
}
/*
3 4
2 1 3
0 1 2 0
1
0 3 1 3
*/