#pragma GCC optimize ("Ofast") #include using namespace std; inline void rd(int &x){ int k; int m=0; x=0; for(;;){ k = getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void rd(long long &x){ int k; int m=0; x=0; for(;;){ k = getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline int rd_int(void){ int x; rd(x); return x; } inline void wt_L(char a){ putchar_unlocked(a); } inline void wt_L(int x){ int s=0; int m=0; char f[10]; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ putchar_unlocked('-'); } while(s--){ putchar_unlocked(f[s]+'0'); } } int N; int L; int R; long long A[100000]; int up[100000]; int dw[100000]; int main(){ int KL2GvlyY, i; int res1; int res2; rd(N); { int Lj4PdHRW; for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){ rd(A[Lj4PdHRW]); } } up[N-1] = dw[N-1] = N-1; for(i=(N-1)-1;i>=(0);i--){ if(A[i+1] >= A[i]){ up[i] =up[i+1]; } else{ up[i] =i; } if(A[i+1] <= A[i]){ dw[i] =dw[i+1]; } else{ dw[i] =i; } } int Q5VJL1cS = rd_int(); for(KL2GvlyY=(0);KL2GvlyY<(Q5VJL1cS);KL2GvlyY++){ rd(L); rd(R); if(up[L] >= R){ res1 =1; } else{ res1 =0; } if(dw[L] >= R){ res2 =1; } else{ res2 =0; } wt_L(res1); wt_L(' '); wt_L(res2); wt_L('\n'); } return 0; } // cLay varsion 20191012-1 // --- original code --- // int N, L, R; ll A[1d5]; // int up[1d5], dw[1d5]; // { // int res1, res2; // rd(N,A(N)); // up[N-1] = dw[N-1] = N-1; // rrep(i,N-1){ // up[i] = if[A[i+1] >= A[i], up[i+1], i]; // dw[i] = if[A[i+1] <= A[i], dw[i+1], i]; // } // REP(rd_int()){ // rd(L,R); // res1 = if[up[L] >= R, 1, 0]; // res2 = if[dw[L] >= R, 1, 0]; // wt(res1,res2); // } // }