#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define ff first
#define ss second
#define pb push_back

const int N = 200005;

int n, m, q;
int p[N], v[N];
int ma[N];
int at[N];
vector<int> idx[N];
int mi[N];

bool init(int id){
	at[v[id]] = *lower_bound(idx[v[id]].begin(), idx[v[id]].end(), id);
	int lst = id;
	for(int i = 1; i < n; i++){
		auto x = lower_bound(idx[(v[id] + i) % n].begin(), idx[(v[id] + i) % n].end(), lst);
		if(x == idx[(v[id] + i) % n].end()){
			for(int j = 0; j < i; j++){
				mi[at[(v[id] + j) % n]] = m;
			}
			return 0;
		}
		if(mi[*x] != m + 1){
			for(int j = 0; j < i; j++){
				mi[at[(v[id] + j) % n]] = mi[at[(v[id] + j) % n] - 1];
			}
			return 0;
		}
		at[(v[id] + i) % n] = *x;
		lst = *x;
	}
	return 1;
}

bool prox(int id){
	mi[id] = at[(v[id] - 1 + n) % n];
	auto x = lower_bound(idx[v[id]].begin(), idx[v[id]].end(), at[(v[id] - 1 + n) % n]);
	if(x == idx[v[id]].end())
		return 0;
	at[v[id]] = *x;
	return 1;
}

int dn[200005][20];

int fn(int i, int j){
	if(j == 0) return mi[i];
	if(~dn[i][j]) return dn[i][j];
	return dn[i][j] = min(fn(i, j-1), fn(i + (1 << (j-1)), j-1));
}

int lg(int x){
	return 31 - __builtin_clz(x);
}

int getmn(int l, int r){ // [l, r]
	int lz = lg(r - l + 1);
	return min(fn(l, lz), fn(r - (1 << lz) + 1, lz));
}

int main(){
	scanf("%d %d %d", &n, &m, &q);
	for(int i = 0; i < n; i++){
		scanf("%d", &p[i]);
		ma[p[i]] = i;
	}
	for(int i = 0; i < m; i++){
		scanf("%d", &v[i]);
		v[i] = ma[v[i]];
		idx[v[i]].pb(i);
		mi[i] = m + 1;
	}
	if(n > 1){
		memset(dn, -1, sizeof dn);
		for(int i = 0; i < m; i++){
			if(mi[i] == m + 1){
				if(init(i)){
					int ida = i;
					while(prox(ida)) ida = at[(v[ida] + 1) % n];
				}
			}
		}
		while(q--){
			int l, r;
			scanf("%d %d", &l, &r);
			l--;
			r--;
			printf("%d", getmn(l, r) <= r);
		}
	}
	else{
		while(q--){
			printf("1");
		}
	}
	printf("\n");

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define ff first
#define ss second
#define pb push_back

const int N = 200005;

int n, m, q;
int p[N], v[N];
int ma[N];
int at[N];
vector<int> idx[N];
int mi[N];

bool init(int id){
	at[v[id]] = *lower_bound(idx[v[id]].begin(), idx[v[id]].end(), id);
	int lst = id;
	for(int i = 1; i < n; i++){
		auto x = lower_bound(idx[(v[id] + i) % n].begin(), idx[(v[id] + i) % n].end(), lst);
		if(x == idx[(v[id] + i) % n].end()){
			for(int j = 0; j < i; j++){
				mi[at[(v[id] + j) % n]] = m;
			}
			return 0;
		}
		if(mi[*x] != m + 1){
			for(int j = 0; j < i; j++){
				mi[at[(v[id] + j) % n]] = mi[at[(v[id] + j) % n] - 1];
			}
			return 0;
		}
		at[(v[id] + i) % n] = *x;
		lst = *x;
	}
	return 1;
}

bool prox(int id){
	mi[id] = at[(v[id] - 1 + n) % n];
	auto x = lower_bound(idx[v[id]].begin(), idx[v[id]].end(), at[(v[id] - 1 + n) % n]);
	if(x == idx[v[id]].end())
		return 0;
	at[v[id]] = *x;
	return 1;
}

int dn[200005][20];

int fn(int i, int j){
	if(j == 0) return mi[i];
	if(~dn[i][j]) return dn[i][j];
	return dn[i][j] = min(fn(i, j-1), fn(i + (1 << (j-1)), j-1));
}

int lg(int x){
	return 31 - __builtin_clz(x);
}

int getmn(int l, int r){ // [l, r]
	int lz = lg(r - l + 1);
	return min(fn(l, lz), fn(r - (1 << lz) + 1, lz));
}

int main(){
	scanf("%d %d %d", &n, &m, &q);
	for(int i = 0; i < n; i++){
		scanf("%d", &p[i]);
		ma[p[i]] = i;
	}
	for(int i = 0; i < m; i++){
		scanf("%d", &v[i]);
		v[i] = ma[v[i]];
		idx[v[i]].pb(i);
		mi[i] = m + 1;
	}
	if(n > 1){
		for(int i = 0; i < m; i++){
			if(mi[i] == m + 1){
				if(init(i)){
					int ida = i;
					while(prox(ida)) ida = at[(v[ida] + 1) % n];
				}
			}
		}
		memset(dn, -1, sizeof dn);
	}
	while(q--){
		int l, r;
		scanf("%d %d", &l, &r);
		l--;
		r--;
		printf("%d", getmn(l, r) <= r);
	}
	printf("\n");

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define ff first
#define ss second
#define pb push_back

const int N = 200005;

int n, m, q;
int p[N], v[N];
int ma[N];
int at[N];
vector<int> idx[N];
int mi[N];

bool init(int id){
	at[v[id]] = *lower_bound(idx[v[id]].begin(), idx[v[id]].end(), id);
	int lst = id;
	for(int i = 1; i < n; i++){
		auto x = lower_bound(idx[(v[id] + i) % n].begin(), idx[(v[id] + i) % n].end(), lst);
		if(x == idx[(v[id] + i) % n].end()){
			for(int j = 0; j < i; j++){
				mi[at[(v[id] + j) % n]] = m;
			}
			return 0;
		}
		if(mi[*x] != m + 1){
			for(int j = 0; j < i; j++){
				mi[at[(v[id] + j) % n]] = mi[*(lower_bound(idx[(v[id] + j) % n].begin(), idx[(v[id] + j) % n].end(), at[(v[id] + j) % n]) - 1)];
			}
			return 0;
		}
		at[(v[id] + i) % n] = *x;
		lst = *x;
	}
	return 1;
}

bool prox(int id){
	mi[id] = at[(v[id] - 1 + n) % n];
	auto x = lower_bound(idx[v[id]].begin(), idx[v[id]].end(), at[(v[id] - 1 + n) % n]);
	if(x == idx[v[id]].end())
		return 0;
	at[v[id]] = *x;
	return 1;
}

int dn[200005][20];

int fn(int i, int j){
	if(j == 0) return mi[i];
	if(~dn[i][j]) return dn[i][j];
	return dn[i][j] = min(fn(i, j-1), fn(i + (1 << (j-1)), j-1));
}

int lg(int x){
	return 31 - __builtin_clz(x);
}

int getmn(int l, int r){ // [l, r]
	int lz = lg(r - l + 1);
	return min(fn(l, lz), fn(r - (1 << lz) + 1, lz));
}

int main(){
	scanf("%d %d %d", &n, &m, &q);
	for(int i = 0; i < n; i++){
		scanf("%d", &p[i]);
		ma[p[i]] = i;
	}
	for(int i = 0; i < m; i++){
		scanf("%d", &v[i]);
		v[i] = ma[v[i]];
		idx[v[i]].pb(i);
		mi[i] = m + 1;
	}
	if(n > 1){
		memset(dn, -1, sizeof dn);
		for(int i = 0; i < m; i++){
			if(mi[i] == m + 1){
				if(init(i)){
					int ida = i;
					while(prox(ida)) ida = at[(v[ida] + 1) % n];
				}
			}
		}
		while(q--){
			int l, r;
			scanf("%d %d", &l, &r);
			l--;
			r--;
			printf("%d", getmn(l, r) <= r);
		}
	}
	else{
		while(q--){
			printf("1");
		}
	}
	printf("\n");

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define ff first
#define ss second
#define pb push_back

const int N = 200005;

int n, m, q;
int p[N], v[N];
int ma[N];
int at[N];
vector<int> idx[N];
int mi[N];

bool init(int id){
	at[v[id]] = *lower_bound(idx[v[id]].begin(), idx[v[id]].end(), id);
	int lst = id;
	for(int i = 1; i < n; i++){
		auto x = lower_bound(idx[(v[id] + i) % n].begin(), idx[(v[id] + i) % n].end(), lst);
		if(x == idx[(v[id] + i) % n].end()){
			for(int j = 0; j < i; j++){
				mi[at[(v[id] + j) % n]] = m;
			}
			return 0;
		}
		at[(v[id] + i) % n] = *x;
		lst = *x;
	}
	return 1;
}

bool prox(int id){
	auto it = lower_bound(idx[(v[id] + 1) % n].begin(), idx[(v[id] + 1) % n].end(), at[(v[id] + 1) % n]);
	if(it != idx[(v[id] + 1) % n].begin()){
		it--;
		it = lower_bound(idx[v[id]].begin(), idx[v[id]].end(), *it);
	}
	else{
		it = lower_bound(idx[v[id]].begin(), idx[v[id]].end(), id);
	}
	while(*it < at[(v[id] + 1) % n]){
		mi[*it] = at[(v[id] - 1 + n) % n];
		it++;
	}
	auto x = lower_bound(idx[v[id]].begin(), idx[v[id]].end(), at[(v[id] - 1 + n) % n]);
	if(x == idx[v[id]].end())
		return 0;
	at[v[id]] = *x;
	return 1;
}

int dn[200005][20];

int fn(int i, int j){
	if(j == 0) return mi[i];
	if(~dn[i][j]) return dn[i][j];
	return dn[i][j] = min(fn(i, j-1), fn(i + (1 << (j-1)), j-1));
}

int lg(int x){
	return 31 - __builtin_clz(x);
}

int getmn(int l, int r){ // [l, r]
	int lz = lg(r - l + 1);
	return min(fn(l, lz), fn(r - (1 << lz) + 1, lz));
}

int main(){
	scanf("%d %d %d", &n, &m, &q);
	for(int i = 0; i < n; i++){
		scanf("%d", &p[i]);
		ma[p[i]] = i;
	}
	for(int i = 0; i < m; i++){
		scanf("%d", &v[i]);
		v[i] = ma[v[i]];
		idx[v[i]].pb(i);
		mi[i] = m + 1;
	}
	if(n > 1){
		memset(dn, -1, sizeof dn);
		for(int i = 0; i < m; i++){
			if(mi[i] == m + 1){
				if(init(i)){
					int ida = i;
					while(prox(ida)){
					   	ida = at[(v[ida] + 1) % n];
						if(mi[ida] != m + 1) break;
					}
				}
			}
		}
		while(q--){
			int l, r;
			scanf("%d %d", &l, &r);
			l--;
			r--;
			printf("%d", getmn(l, r) <= r);
		}
	}
	else{
		while(q--){
			printf("1");
		}
	}
	printf("\n");

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define ff first
#define ss second
#define pb push_back

const int N = 200005;

int n, m, q;
int p[N], v[N];
int ma[N];
int at[N];
vector<int> idx[N];
int mi[N];

bool init(int id){
	at[v[id]] = *lower_bound(idx[v[id]].begin(), idx[v[id]].end(), id);
	int lst = id;
	for(int i = 1; i < n; i++){
		auto x = lower_bound(idx[(v[id] + i) % n].begin(), idx[(v[id] + i) % n].end(), lst);
		if(x == idx[(v[id] + i) % n].end()){
			for(int j = 0; j < i; j++){
				mi[at[(v[id] + j) % n]] = m;
			}
			return 0;
		}
		if(mi[*x] != m + 1){
			for(int j = 0; j < i; j++){
				mi[at[(v[id] + j) % n]] = mi[at[(v[id] + j) % n] - 1];
			}
			return 0;
		}
		at[(v[id] + i) % n] = *x;
		lst = *x;
	}
	return 1;
}

bool prox(int id){
	mi[id] = at[(v[id] - 1 + n) % n];
	auto x = lower_bound(idx[v[id]].begin(), idx[v[id]].end(), at[(v[id] - 1 + n) % n]);
	if(x == idx[v[id]].end())
		return 0;
	at[v[id]] = *x;
	return 1;
}

int dn[200005][20];

int fn(int i, int j){
	if(j == 0) return mi[i];
	if(~dn[i][j]) return dn[i][j];
	return dn[i][j] = min(fn(i, j-1), fn(i + (1 << (j-1)), j-1));
}

int lg(int x){
	return 31 - __builtin_clz(x);
}

int getmn(int l, int r){ // [l, r]
	int lz = lg(r - l + 1);
	return min(fn(l, lz), fn(r - (1 << lz) + 1, lz));
}

int main(){
	scanf("%d %d %d", &n, &m, &q);
	for(int i = 0; i < n; i++){
		scanf("%d", &p[i]);
		ma[p[i]] = i;
	}
	for(int i = 0; i < m; i++){
		scanf("%d", &v[i]);
		v[i] = ma[v[i]];
		idx[v[i]].pb(i);
		mi[i] = m + 1;
	}
	if(n > 1){
		for(int i = 0; i < m; i++){
			if(mi[i] == m + 1){
				if(init(i)){
					int ida = i;
					while(prox(ida)) ida = at[(v[ida] + 1) % n];
				}
			}
		}
		while(q--){
			int l, r;
			scanf("%d %d", &l, &r);
			l--;
			r--;
			printf("%d", getmn(l, r) <= r);
		}
	}
	else{
		while(q--){
			printf("1");
		}
	}
	printf("\n");

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define ff first
#define ss second
#define pb push_back

const int N = 200005;

int n, m, q;
int p[N], v[N];
int ma[N];
int at[N];
vector<int> idx[N];
int mi[N];

bool init(int id){
	at[v[id]] = *lower_bound(idx[v[id]].begin(), idx[v[id]].end(), id);
	int lst = id;
	for(int i = 1; i < n; i++){
		auto x = lower_bound(idx[(v[id] + i) % n].begin(), idx[(v[id] + i) % n].end(), lst);
		if(x == idx[(v[id] + i) % n].end()){
			for(int j = 0; j < i; j++){
				mi[at[(v[id] + j) % n]] = m;
			}
			return 0;
		}
		if(mi[*x] != m + 1){
			for(int j = 0; j < i; j++){
				mi[at[(v[id] + j) % n]] = mi[at[(v[id] + j) % n] - 1];
			}
			return 0;
		}
		at[(v[id] + i) % n] = *x;
		lst = *x;
	}
	return 1;
}

bool prox(int id){
	mi[id] = at[(v[id] - 1 + n) % n];
	auto x = lower_bound(idx[v[id]].begin(), idx[v[id]].end(), at[(v[id] - 1 + n) % n]);
	if(x == idx[v[id]].end())
		return 0;
	at[v[id]] = *x;
	return 1;
}

int dn[200005][20];

int fn(int i, int j){
	if(j == 0) return mi[i];
	if(~dn[i][j]) return dn[i][j];
	return dn[i][j] = min(fn(i, j-1), fn(i + (1 << (j-1)), j-1));
}

int lg(int x){
	return 31 - __builtin_clz(x);
}

int getmn(int l, int r){ // [l, r]
	int lz = lg(r - l + 1);
	return min(fn(l, lz), fn(r - (1 << lz) + 1, lz));
}

int main(){
	scanf("%d %d %d", &n, &m, &q);
	for(int i = 0; i < n; i++){
		scanf("%d", &p[i]);
		ma[p[i]] = i;
	}
	for(int i = 0; i < m; i++){
		scanf("%d", &v[i]);
		v[i] = ma[v[i]];
		idx[v[i]].pb(i);
		mi[i] = m + 1;
	}

	for(int i = 0; i < m; i++){
		if(mi[i] == m + 1){
			if(init(i)){
				int ida = i;
				while(prox(ida)) ida = at[(v[ida] + 1) % n];
			}
		}
	}
	memset(dn, -1, sizeof dn);
	while(q--){
		int l, r;
		scanf("%d %d", &l, &r);
		l--;
		r--;
		printf("%d", getmn(l, r) <= r);
	}
	printf("\n");

	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define sc second
#define gc getchar
#define pb push_back
using namespace std;
const int N=2e5+10;
typedef long long ll;
typedef double db;

int n,m,q,p[N],a[N],rv[N],blk,in[N];
char s[N];
int t[N],bel[N],pre[N],cnt,mx[N];

char cp;
template<class T>inline void rd(T &x)
{
	cp=gc();x=0;int f=0;
	for(;!isdigit(cp);cp=gc()) if(cp=='-') f=1;
	for(;isdigit(cp);cp=gc()) x=x*10+(cp^48);
	if(f) x=-x;
}

struct qr{
   int l,r,id;
   bool operator<(const qr&ky)const{
       if(in[l]!=in[ky.l]) return l<ky.l;
       return r<ky.r;
   }
}c[N];

struct P{int id,v;bool operator <(const P&ky)const{return v<ky.v;};};
priority_queue<P>que;

int main(){
	int i,fr,x,L,R;ll ix,iy;
	rd(n);rd(m);rd(q);blk=(int)sqrt(n)+1;
	for(i=1;i<=n;++i) rd(p[i]);
	for(i=1;i<=m;++i) rd(a[i]);
	for(i=1;i<=n;++i) in[i]=(i-1)/blk+1,rv[p[i]]=i;
	for(i=1;i<=q;++i) rd(c[i].l),rd(c[i].r),c[i].id=i;
	sort(c+1,c+q+1);
	for(i=1;i<=m;++i){
		fr=(rv[a[i]]==1)?n:(rv[a[i]]-1);
		if(!pre[fr]) bel[i]=++cnt;
		else if(pre[rv[a[i]]]<pre[fr]) bel[i]=bel[fr];
		pre[rv[a[i]]]=i;
	}

	L=c[1].l;R=c[1].r;
	for(i=L;i<=R;++i)if((x=bel[i])){
	    t[x]++;que.push((P){x,t[x]});
	}
	s[c[1].id]=(que.top().v>=n)?'1':'0';

	for(i=2;i<=q;++i){
		for(;R<c[i].r;) if((x=bel[++R])) {t[x]++;que.push((P){x,t[x]});}
		for(;L>c[i].l;) if((x=bel[--L])) {t[x]++;que.push((P){x,t[x]});}
		for(;L<c[i].l;L++) if((x=bel[L])) {t[x]--;que.push((P){x,t[x]});}
		for(;R>c[i].r;R--) if((x=bel[R])) {t[x]--;que.push((P){x,t[x]});}
		for(;que.top().v!=t[que.top().id];que.pop());
		if(que.empty()) s[c[i].id]='0';
		else s[c[i].id]=(que.top().v>=n)?'1':'0';
	}
	printf("%s",s+1);
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define sc second
#define gc getchar
#define pb push_back
#define lc (k<<1)
#define rc (k<<1|1)
#define mid ((l+r)>>1)
using namespace std;
const int N=2e5+10;
typedef long long ll;
typedef double db;

int n,m,q,p[N],a[N],rv[N];
int tg[N],bel[N],pre[N],cnt,v[N],mx[N<<2];
int nt[N][20];
map<int,int>g[N];

char cp;
template<class T>inline void rd(T &x)
{
	cp=gc();x=0;int f=0;
	for(;!isdigit(cp);cp=gc()) if(cp=='-') f=1;
	for(;isdigit(cp);cp=gc()) x=x*10+(cp^48);
	if(f) x=-x;
}

void build(int k,int l,int r)
{
	if(l==r) {mx[k]=v[l];return;}
	build(lc,l,mid);build(rc,mid+1,r);
	mx[k]=max(mx[lc],mx[rc]);
}

int ask(int k,int l,int r,int L,int R)
{
	if(L<=l && r<=R) return mx[k];
	int re=0;
	if(L<=mid) re=ask(lc,l,mid,L,R);
	if(R>mid) re=max(re,ask(rc,mid+1,r,L,R));
	return re;
}

int main(){
	int i,j,k,x,L,R;
	rd(n);rd(m);rd(q);
	for(i=0;i<n;++i) rd(p[i]);
	for(i=1;i<=m;++i) rd(a[i]);
	for(i=0;i<n;++i) rv[p[i]]=p[(i-1+n)%n];
	for(i=1;i<=m;++i){
		pre[a[i]]=i;x=pre[rv[a[i]]];nt[i][0]=x;
		for(j=1;j<20;++j) nt[i][j]=nt[nt[i][j-1]][j-1];
		for(L=n-2,j=0;(1<<j)<=L;++j) if((L>>j)&1) x=nt[x][j];
		v[i]=x;
	}
	build(1,1,m);
	for(;q;--q){
		rd(L);rd(R);
		if(ask(1,1,m,L,R)>=L) putchar('1');
		else putchar('0');
	}
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define sc second
#define gc getchar
#define pb push_back
using namespace std;
const int N=2e5+10;
typedef long long ll;
typedef double db;

int n,m,q,p[N],a[N],rv[N],blk,in[N];
char s[N];
int tg[N],bel[N],pre[N],cnt,mx[N];
multiset<int>up[N];

char cp;
template<class T>inline void rd(T &x)
{
	cp=gc();x=0;int f=0;
	for(;!isdigit(cp);cp=gc()) if(cp=='-') f=1;
	for(;isdigit(cp);cp=gc()) x=x*10+(cp^48);
	if(f) x=-x;
}

struct qr{
   int l,r,id;
   bool operator<(const qr&ky)const{
       if(in[l]!=in[ky.l]) return l<ky.l;
       return r<ky.r;
   }
}c[N];

struct P{int id,v;bool operator <(const P&ky)const{return v<ky.v;};};
priority_queue<P>que;

multiset<int>::iterator it;

inline int cal(int x)
{
	if(up[x].empty()) return 0;it=up[x].end();
// cerr<<*(--it)<<" "<<*(up[x].begin())<<endl;
    it--;
	int re=(-(*(up[x].begin()))+(*(it))+1);
	return re;
}

int main(){
	int i,fr,x,L,R;ll ix,iy;
	rd(n);rd(m);rd(q);blk=(int)sqrt(n)+1;
	for(i=1;i<=n;++i) rd(p[i]);
	for(i=1;i<=m;++i) rd(a[i]);
	for(i=1;i<=n;++i) in[i]=(i-1)/blk+1,rv[p[i]]=i;
	for(i=1;i<=q;++i) rd(c[i].l),rd(c[i].r),c[i].id=i;
	sort(c+1,c+q+1);
	for(i=1;i<=m;++i){
		fr=(rv[a[i]]==1)?n:(rv[a[i]]-1);
		if(!pre[fr]) bel[i]=++cnt,tg[i]=1;
		else bel[i]=bel[pre[fr]],tg[i]=tg[pre[fr]]+1;
		pre[rv[a[i]]]=i;
	}

	L=c[1].l;R=c[1].r;
	for(i=L;i<=R;++i){
	    x=bel[i];
		up[x].insert(tg[i]);que.push((P){x,cal(x)});
	}
	s[c[1].id]=(que.top().v>=n)?'1':'0';

	for(i=2;i<=q;++i){
		for(;R<c[i].r;)
		{R++;up[(x=bel[R])].insert(tg[R]);que.push((P){x,cal(x)});}
		for(;L>c[i].l;)
		{L--;up[(x=bel[L])].insert(tg[L]);que.push((P){x,cal(x)});}
		for(;L<c[i].l;L++)
		{x=bel[L];up[x].erase(up[x].find(tg[L]));
		que.push((P){x,cal(x)});}
		for(;R>c[i].r;R--)
		{x=bel[R];up[x].erase(up[x].find(tg[R]));
		que.push((P){x,cal(x)});}
		for(;(!que.empty()) && (que.top().v!=cal(que.top().id));)
		   que.pop();
		if(que.empty()) s[c[i].id]='0';
		else s[c[i].id]=(que.top().v>=n)?'1':'0';
	}
	printf("%s",s+1);
	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define sc second
#define gc getchar
#define pb push_back
#define lc k<<1
#define rc k<<1|1
#define mid ((l+r)>>1)
using namespace std;
const int N=2e5+10;
typedef long long ll;
typedef double db;

int n,m,q,p[N],a[N],rv[N];
int tg[N],bel[N],pre[N],cnt,v[N],mx[N<<1];
vector<int>g[N];

char cp;
template<class T>inline void rd(T &x)
{
	cp=gc();x=0;int f=0;
	for(;!isdigit(cp);cp=gc()) if(cp=='-') f=1;
	for(;isdigit(cp);cp=gc()) x=x*10+(cp^48);
	if(f) x=-x;
}

void build(int k,int l,int r)
{
	if(l==r) {mx[k]=v[l];return;}
	build(lc,l,mid);build(rc,mid+1,r);
	mx[k]=max(mx[lc],mx[rc]);
}

int ask(int k,int l,int r,int L,int R)
{
	if(L<=l && r<=R) return mx[k];
	int re=0;
	if(L<=mid) re=ask(lc,l,mid,L,R);
	if(R>mid) re=max(re,ask(rc,mid+1,r,L,R));
	return re;
}

int main(){
	int i,fr,x,L,R;
	rd(n);rd(m);rd(q);
	for(i=1;i<=n;++i) rd(p[i]);
	for(i=1;i<=m;++i) rd(a[i]);
	for(i=1;i<=n;++i) rv[p[i]]=i,g[i].pb(0);
	for(i=1;i<=m;++i){
		x=rv[a[i]];fr=(x==1)?n:(x-1);
		if(!pre[fr]) bel[i]=++cnt,tg[i]=1;
		else bel[i]=bel[pre[fr]],tg[i]=tg[pre[fr]]+1;
		pre[x]=i;x=bel[i];g[x][tg[i]]=i;
		v[i]=g[x][max(tg[i]-n+1,0)];
	}
	build(1,1,m);
	for(;q;--q){
		rd(L);rd(R);
		putchar(ask(1,1,m,L,R)>=L?'1':'0');
	}

	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define sc second
#define gc getchar
#define pb push_back
#define lc k<<1
#define rc k<<1|1
#define mid ((l+r)>>1)
using namespace std;
const int N=2e5+10;
typedef long long ll;
typedef double db;

int n,m,q,p[N],a[N],rv[N];
int tg[N],bel[N],pre[N],cnt,v[N],mx[N<<2];
map<int,int>g[N];

char cp;
template<class T>inline void rd(T &x)
{
	cp=gc();x=0;int f=0;
	for(;!isdigit(cp);cp=gc()) if(cp=='-') f=1;
	for(;isdigit(cp);cp=gc()) x=x*10+(cp^48);
	if(f) x=-x;
}

void build(int k,int l,int r)
{
	if(l==r) {mx[k]=v[l];return;}
	build(lc,l,mid);build(rc,mid+1,r);
	mx[k]=max(mx[lc],mx[rc]);
}

int ask(int k,int l,int r,int L,int R)
{
	if(L<=l && r<=R) return mx[k];
	int re=0;
	if(L<=mid) re=ask(lc,l,mid,L,R);
	if(R>mid) re=max(re,ask(rc,mid+1,r,L,R));
	return re;
}

int main(){
	int i,fr,x,L,R;
	rd(n);rd(m);rd(q);
	for(i=1;i<=n;++i) rd(p[i]);
	for(i=1;i<=m;++i) rd(a[i]);
	for(i=1;i<=n;++i) rv[p[i]]=i;
	for(i=1;i<=m;++i){
		x=rv[a[i]];fr=(x==1)?n:(x-1);
		if(!pre[fr]){
		   if(!pre[x]) bel[i]=++cnt;
		   else bel[i]=bel[pre[x]];tg[i]=1;
		}else bel[i]=bel[pre[fr]],tg[i]=tg[pre[fr]]+1;
		pre[x]=i;x=bel[i];g[x][tg[i]]=i;
		v[i]=g[x][max(tg[i]-n+1,0)];
	}
	build(1,1,m);
	for(;q;--q){
		rd(L);rd(R);
		putchar(ask(1,1,m,L,R)>=L?'1':'0');
	}

	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define sc second
#define gc getchar
#define pb push_back
#define lc k<<1
#define rc k<<1|1
#define mid ((l+r)>>1)
using namespace std;
const int N=2e5+10;
typedef long long ll;
typedef double db;

int n,m,q,p[N],a[N],rv[N];
int tg[N],bel[N],pre[N],cnt,v[N],mx[N<<2];
vector<int>g[N];

char cp;
template<class T>inline void rd(T &x)
{
	cp=gc();x=0;int f=0;
	for(;!isdigit(cp);cp=gc()) if(cp=='-') f=1;
	for(;isdigit(cp);cp=gc()) x=x*10+(cp^48);
	if(f) x=-x;
}

void build(int k,int l,int r)
{
	if(l==r) {mx[k]=v[l];return;}
	build(lc,l,mid);build(rc,mid+1,r);
	mx[k]=max(mx[lc],mx[rc]);
}

int ask(int k,int l,int r,int L,int R)
{
	if(L<=l && r<=R) return mx[k];
	int re=0;
	if(L<=mid) re=ask(lc,l,mid,L,R);
	if(R>mid) re=max(re,ask(rc,mid+1,r,L,R));
	return re;
}

int main(){
	int i,fr,x,L,R;
	rd(n);rd(m);rd(q);
	for(i=1;i<=n;++i) rd(p[i]);
	for(i=1;i<=m;++i) rd(a[i]);
	for(i=1;i<=n;++i) rv[p[i]]=i,g[i].pb(0);
	for(i=1;i<=m;++i){
		x=rv[a[i]];fr=(x==1)?n:(x-1);
		if(!pre[fr]) bel[i]=++cnt,tg[i]=1;
		else bel[i]=bel[pre[fr]],tg[i]=tg[pre[fr]]+1;
		pre[x]=i;x=bel[i];g[x][tg[i]]=i;
		v[i]=g[x][max(tg[i]-n+1,0)];
	}
	build(1,1,m);
	for(;q;--q){
		rd(L);rd(R);
		putchar(ask(1,1,m,L,R)>=L?'1':'0');
	}

	return 0;
}


#include<bits/stdc++.h>
#define fi first
#define sc second
#define gc getchar
#define pb push_back
#define lc k<<1
#define rc k<<1|1
#define mid ((l+r)>>1)
using namespace std;
const int N=2e5+10;
typedef long long ll;
typedef double db;

int n,m,q,p[N],a[N],rv[N];
int tg[N],bel[N],pre[N],cnt,v[N],mx[N<<2];
vector<int>g[N];

char cp;
template<class T>inline void rd(T &x)
{
	cp=gc();x=0;int f=0;
	for(;!isdigit(cp);cp=gc()) if(cp=='-') f=1;
	for(;isdigit(cp);cp=gc()) x=x*10+(cp^48);
	if(f) x=-x;
}

void build(int k,int l,int r)
{
	if(l==r) {mx[k]=v[l];return;}
	build(lc,l,mid);build(rc,mid+1,r);
	mx[k]=max(mx[lc],mx[rc]);
}

int ask(int k,int l,int r,int L,int R)
{
	if(L<=l && r<=R) return mx[k];
	int re=0;
	if(L<=mid) re=ask(lc,l,mid,L,R);
	if(R>mid) re=max(re,ask(rc,mid+1,r,L,R));
	return re;
}

int main(){
	int i,fr,x,L,R;
	rd(n);rd(m);rd(q);
	for(i=1;i<=n;++i) rd(p[i]);
	for(i=1;i<=m;++i) rd(a[i]);
	for(i=1;i<=n;++i) rv[p[i]]=i,g[i].pb(0);
	for(i=1;i<=m;++i){
		x=rv[a[i]];fr=(x==1)?n:(x-1);
		if(!pre[fr]){
		   if(!pre[x]) bel[i]=++cnt;
		   else bel[i]=bel[pre[x]];tg[i]=1;
		}else bel[i]=bel[pre[fr]],tg[i]=tg[pre[fr]]+1;
		pre[x]=i;x=bel[i];g[x][tg[i]]=i;
		v[i]=g[x][max(tg[i]-n+1,0)];
	}
	build(1,1,m);
	for(;q;--q){
		rd(L);rd(R);
		putchar(ask(1,1,m,L,R)>=L?'1':'0');
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int SIZE = 200000 + 5;

int n, m, Q;
int p[SIZE], a[SIZE], pre[SIZE], last[SIZE], f[21][SIZE], st[21][SIZE], logs[SIZE];

namespace ae86 {
	const int bufl = 1 << 15;
	char buf[bufl], *s = buf, *t = buf;
	inline int fetch() {
		if (s == t) { t = (s = buf) + fread(buf, 1, bufl, stdin); if (s == t) return EOF; }
		return *s++;
	}
	inline int read() {
		int a = 0, b = 1, c = fetch();
		while (!isdigit(c))b ^= c == '-', c = fetch();
		while (isdigit(c)) a = a * 10 + c - 48, c = fetch();
		return b ? a : -a;
	}
}
using ae86::read;

inline int Query(int l, int r)
{
    int k = logs[r - l + 1];
    return std::max(st[k][l], st[k][r - (1 << k) + 1]);
}

int main()
{
    // freopen("data.in", "r", stdin);
    // freopen("data.out", "w", stdout);
    n = read(), m = read(), Q = read();
    for (int i = 1; i <= n; i++) p[i] = read();
    p[0] = p[n];
    for (int i = 1; i <= n; i++) pre[p[i]] = p[i - 1];
    for (int i = 1; i <= m; i++) a[i] = read();
    for (int i = 1; i <= m; i++) f[0][i] = last[pre[a[i]]], last[a[i]] = i;
    for (int i = 2; i <= n || i <= m; i++) logs[i] = logs[i >> 1] + 1;
    for (int i = 1; i <= logs[n]; i++)
        for (int j = 1; j <= m; j++)
            f[i][j] = f[i - 1][f[i - 1][j]];
    int j;
    for (int i = 1; i <= m; i++)
        for (st[j = 0][i] = i; j <= logs[n - 1]; j++) {
            if ((n - 1) & (1 << j)) st[0][i] = f[j][st[0][i]];
        }
    for (int i = 1; i <= logs[m]; i++)
        for (int j = 1; j + (1 << i) - 1 <= m; j++) st[i][j] = std::max(st[i - 1][j], st[i - 1][j + (1 << i - 1)]);
    while (Q--) {
        int l = read(), r = read();
        printf("%c", Query(l, r) >= l ? '1' : '0');
    }
    return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <utility>
#include <algorithm>
#include <vector>
#define rg register
#define il inline
#define ll long long
using namespace std;
il void read(int &x){
    rg char c=getchar();
    while(c<'0'||c>'9') c=getchar();
    x=c^48;
	c=getchar();
    while(c>='0'&&c<='9'){
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
}

const int N=2e5+5;
struct Edge{
	int to,nxt;
}edge[N];
int cnt,head[N];
int n,m,q,l,r;
int p[N],a[N];
int dep[N],anc[N];
int pre[N],lst[N];
int s[N],val[N],k[N];

il void add_edge(int u,int v){
	edge[++cnt].to=v;
	edge[cnt].nxt=head[u];
	head[u]=cnt;
}
il void dfs(int u){
    anc[dep[u]]=u;
	if(dep[u]>=n)
		val[u]=anc[dep[u]-n+1];
	else
		val[u]=m+1;
    for(rg int i=head[u];i;i=edge[i].nxt){
    	int v=edge[i].to;
        dep[v]=dep[u]+1;
        dfs(v);
    }
}

signed main(){
	read(n);
	read(m);
	read(q);
	for(rg int i(1);i<=n;++i){
		read(p[i]);
		k[p[i]]=p[i-1];
	}
	k[p[1]]=p[n];
	for(rg int i(1);i<=m;++i){
		read(a[i]);
		pre[i]=lst[a[i]];
		lst[a[i]]=i;
        for(rg int j(lst[k[a[i]]]);(j)&&(s[j]==0);j=pre[j])
			s[j]=i;
	}
	for(rg int i(1);i<=m;++i)
		if(!s[i])
			s[i]=m+1;
	for(rg int i(1);i<=m;++i)
		add_edge(s[i],i);
	dfs(m+1);
	for(rg int i(m-1);i;--i)
		val[i]=min(val[i],val[i+1]);
	while(q--){
		read(l);
		read(r);
		putchar('0'+(val[l]<=r));
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#define il inline
#define ri register
#define Size 200050
using namespace std;
struct point{
	point*next;int to;
}*head[Size];
int p[Size],q[Size],sta[Size],
	top,a[Size],n,m,q1;
il void read(int&),dfs(int),
	link(int,int);
int main(){
	read(n),read(m),read(q1);
	for(int i(1);i<=n;++i)
		read(p[i]),q[p[i]]=p[i-1];
	q[p[1]]=p[n],memset(p,0,sizeof(p));
	for(int i(1),x;i<=m;++i)
		read(x),link(p[q[x]],i),p[x]=i;
	dfs(0);for(int i(1);i<=m;++i)a[i]=max(a[i],a[i-1]);
	for(int i(1),l,r;i<=q1;++i)
		read(l),read(r),putchar(a[r]>=l?49:48);
	return 0;
}
void dfs(int x){
	sta[++top]=x,a[x]=sta[max(top-n+1,0)];
	for(point*i(head[x]);i!=NULL;i=i->next)
		dfs(i->to);--top;
}
il void link(int u,int v){
	head[u]=new point{head[u],v};
}
il void read(int&x){
	x^=x;ri char c;while(c=getchar(),c<'0'||c>'9');
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
}


#include<bits/stdc++.h>
using namespace std;
#define RI register int
#define LL long long
inline int read()
{
    int res=0,f=1;
    char ch=getchar();
    while(ch!='-'&&(ch>'9'||ch<'0'))
        ch=getchar();
    if(ch=='-')
        f=-1,ch=getchar();
    while(ch>='0'&&ch<='9')
        res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
    return res*f;
}
const int N=2e5+5;
int a[N],b[N];
int nxt[N],lst[N];
int f[N][20];
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n=read(),m=read(),q=read();
	for(RI i=1;i<=n;++i)
		a[i]=read();
	for(RI i=1;i<n;++i)
		nxt[a[i]]=a[i+1];
	nxt[a[n]]=a[1];
	for(RI i=1;i<=m;++i)
		b[i]=read();
	for(RI i=m;i>=1;i--)
	{
		if(lst[nxt[b[i]]])
			f[i][0]=lst[nxt[b[i]]];
		lst[b[i]]=i;
	}
	int T=log(n)/log(2);
	for(RI t=1;t<=T;++t)
		for(RI i=1;i<=m;++i)
			f[i][t]=f[f[i][t-1]][t-1];
	for(RI i=1;i<=q;++i)
	{
		int l=read(),r=read();
		bool flag=false;
		for(RI j=l;j<=r-n+1;++j)
		{
			int p=j;
			for(RI t=T;t>=0;t--)
			{
				if((n-1)&(1<<t))
					p=f[p][t];
			}
			if(p<=r&&p)
			{
				flag=true;
				break;
			}
		}
		printf("%d",flag);
	}
	return 0;
}


#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
const int N=2e5+2;
int p[N],a[N],lst[N],inxt[N],pre[N],c[N],dep[N],nd[N],r[N],lj[N],nxt[N],fir[N];
int n,m,q,i,j,cc,bs;
inline void add(int x,int y)
{
	lj[++bs]=y;
	nxt[bs]=fir[x];
	fir[x]=bs;
}
inline void read(int &x)
{
	cc=getchar();
	while ((cc<48)||(cc>57)) cc=getchar();
	x=cc^48;cc=getchar();
	while ((cc>=48)&&(cc<=57))
	{
		x=x*10+(cc^48);
		cc=getchar();
	}
}
void dfs(int x)
{
	int i;nd[dep[x]]=x;if (dep[x]>=n) r[x]=nd[dep[x]-(n-1)]; else r[x]=m+1;
	for (i=fir[x];i;i=nxt[i])
	{
		dep[lj[i]]=dep[x]+1;
		dfs(lj[i]);
	}
}
int main()
{
	read(n);read(m);read(q);
	for (i=1;i<=n;i++) {read(p[i]);inxt[p[i]]=p[i-1];}
	inxt[p[1]]=p[n];
	for (i=1;i<=m;i++)
	{
		read(a[i]);pre[i]=lst[a[i]];lst[a[i]]=i;
		for (j=lst[inxt[a[i]]];(j)&&(c[j]==0);j=pre[j]) c[j]=i;
	}for (i=1;i<=m;i++) if (!c[i]) c[i]=m+1;
	for (i=1;i<=m;i++) add(c[i],i);dfs(m+1);
	for (i=m-1;i;i--) r[i]=min(r[i+1],r[i]);
	while (q--)
	{
		read(i);read(j);
		putchar(48+(r[i]<=j));
	}
}


#include <iostream>
#include <cstdio>
#include <cmath>
#define il inline
#define ri register
#define Size 200050
using namespace std;
int p[Size],a[Size],b[Size],
	c[Size],dp[Size][18];
il void read(int&);
il int ask(int,int);
int main(){
	int n,m,q;
	read(n),read(m),read(q);
	for(int i(1);i<=n;++i)read(p[i]);
	for(int i(1);i<=m;++i)read(a[i]);
	for(int i(1);i<n;++i)b[p[i]]=p[i+1];
	b[p[n]]=p[1];
	for(int i(1);i<=n;++i)c[i]=m+1;
	for(int i(m);i;--i)
		dp[i][0]=c[b[a[i]]],c[a[i]]=i;
	for(int i,j(1);j<18;++j)
		for(i=1;i<=m;++i)
			if(dp[i][j-1]>m)dp[i][j]=m+1;
			else dp[i][j]=dp[dp[i][j-1]][j-1];
	for(int i(1),j,k;i<=m;++i)
		for(j=n-1,a[i]=i,k=17;~k;--k)
			if(j>>k&1)a[i]=dp[a[i]][k];
	for(int i(1);i<=m;++i)dp[i][0]=a[i];
	for(int i,j(1);j<18;++j)
		for(i=1;i+(1<<j)-1<=m;++i)
			dp[i][j]=min(dp[i][j-1],dp[i+(1<<j-1)][j-1]);
	for(int i(1),l,r;i<=q;++i)
		read(l),read(r),putchar(ask(l,r)<=r?49:48);
	return 0;
}
il int ask(int l,int r){
	int t(log2(r-l+1));
	return min(dp[l][t],dp[r-(1<<t)+1][t]);
}
il void read(int &x){
	x^=x;ri char c;while(c=getchar(),c<'0'||c>'9');
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <utility>
#include <algorithm>
#include <vector>
#define rg register
#define il inline
#define ll long long
using namespace std;
il void read(int &x){
    rg char c=getchar();
    while(c<'0'||c>'9') c=getchar();
    x=c^48;
	c=getchar();
    while(c>='0'&&c<='9'){
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
}

const int N=2e5+5;
struct Edge{
	int to,nxt;
}edge[N];
int cnt,head[N];
int n,m,q,l,r;
int p[N],a[N];
int dep[N],anc[N];
int pre[N],lst[N];
int s[N],val[N],k[N];

il void add_edge(int u,int v){
	edge[++cnt].to=v;
	edge[cnt].nxt=head[u];
	head[u]=cnt;
}
il void dfs(int u){
    anc[dep[u]]=u;
	if(dep[u]>=n)
		val[u]=anc[dep[u]-n+1];
	else
		val[u]=m+1;
    for(rg int i=head[u];i;i=edge[i].nxt){
    	int v=edge[i].to;
        dep[v]=dep[u]+1;
        dfs(v);
    }
}

signed main(){
	read(n);
	read(m);
	read(q);
	for(rg int i(1);i<=n;++i){
		read(p[i]);
		k[p[i]]=p[i-1];
	}
	k[p[1]]=p[n];
	for(rg int i(1);i<=m;++i){
		read(a[i]);
		pre[i]=lst[a[i]];
		lst[a[i]]=i;
        for(rg int j(lst[k[a[i]]]);j&&(s[j]==0);j=pre[j])
			s[j]=i;
	}
	for(rg int i(1);i<=m;++i)
		if(!s[i])
			s[i]=m+1;
	for(rg int i(1);i<=m;++i){
		add_edge(s[i],i);
		dfs(m+1);
	}
	for(rg int i(m-1);i;--i)
		val[i]=min(val[i],val[i+1]);
	while(q--){
		read(l);
		read(r);
		putchar('0'+(val[l]<=r));
	}
	return 0;
}


// -*- coding: utf-8 -*-
// @Date    : 2019-04-28 16:55:39

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v)
{
	for(auto i : v)
		os << i << " ";
	return os;
}

template<typename T>
ostream& operator << (ostream& os, const set<T>& v)
{
	for(auto i : v)
		os << i << " ";
	return os;
}

const int N = 2e5 + 233;
int dp[N][20], lst[N], nxt[N], ans[N], a[N], b[N];

// #define local
int main()
{
#ifdef local
	freopen("data.in", "r", stdin);
	freopen("ans.out", "w", stdout);
#endif
	int n, m, t;
	scanf("%d%d%d", &n, &m, &t);
	for(int i = 1; i <= n; ++i)
		scanf("%d", a+i);
	for(int i = 1; i <= n; ++i)
	{
		nxt[a[i-1]] = a[i];
		lst[i] = m+1;
	}
	nxt[a[n]] = a[1];
	for(int i = 1; i <= m; ++i)
		scanf("%d", b+i);
	for(int i = 0; i < 20; ++i)
		dp[m+1][i] = m+1;
	ans[m+1] = m+1;

	for(int i = m; i; --i)
	{
		dp[i][0] = lst[nxt[b[i]]];
		lst[b[i]] = i;
		for(int j = 1; j < 20; ++j)
			dp[i][j] = dp[dp[i][j-1]][j-1];
		int cnt = n-1;
		int p = i;
		for(int j = 19; j+1; --j)
			if(cnt >= (1<<j))
			{
				cnt -= (1<<j);
				p = dp[p][i];
			}
		ans[i] = min(ans[i+1], p);
	}

	while(t--)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		if(ans[l] <= r)
			printf("1");
		else
			printf("0");
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int ret=0,f=1;
	char ch=getchar();
	while(ch>'9'||ch<'0')
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		ret=(ret<<1)+(ret<<3)+ch-'0';
		ch=getchar();
	}
	return ret*f;
}
int n,m,q,h[200005],b[200005],la,nxt[200005],near[200005],f[200005][19],ans[200005],l,r;
int main()
{
    n=read();
	m=read();
	q=read();
    for(register int i=1;i<=n;i++)
		h[read()]=i;
    for(register int i=1;i<=m;i++)
		b[i]=h[read()];
    for(register int i=m;i;i--)
	{
        la=b[i]+1;
        if(la==n+1)
			la=1;
        if(!near[la])
			nxt[i]=m+1;
        else
			nxt[i]=near[la];
        near[b[i]]=i;
    }
    for(register int i=1;i<=m;i++)
		f[i][0]=nxt[i];
    f[m+1][0]=m+1;
    for(register int i=1;i<19;i++)
        for(register int j=1;j<=m+1;j++)
            f[j][i]=f[f[j][i-1]][i-1];
    n--;
    for(register int i=1;i<=m;i++)
	{
        ans[i]=i;
        for(register int j=18;j>=0;j--)
            if(n&(1<<j))
				ans[i]=f[ans[i]][j];
    }
    for(register int i=m-1;i;i--)
		ans[i]=min(ans[i],ans[i+1]);
    while(q--)
	{
		l=read();
		r=read();
        if(ans[l]>r)
			printf("0");
        else
			printf("1");
    }
    return 0;
}
//Written By Peter0701


#include<bits/stdc++.h>
using namespace std;
const int N=400000;

int n,m,q,Pow[N],a[N],b[N],nxt[N],now[N];
int p[N][20],ans[N],t[N*10];

void build(int i,int l,int r)
{
	if (l==r) {t[i]=ans[l];return;}
	int mid=(l+r)>>1;
	build(i<<1,l,mid);build(i<<1|1,mid+1,r);
	t[i]=min(t[i<<1],t[i<<1|1]);
}

int query(int i,int l,int r,int x,int y)
{
	if (l>=x&&r<=y) return t[i];
	int mid=(l+r)>>1;
	if (mid>=y) return query(i<<1,l,mid,x,y);
		else if (mid<x) return query(i<<1|1,mid+1,r,x,y);
			else return min(query(i<<1,l,mid,x,y),query(i<<1|1,mid+1,r,x,y));
}

int main()
{
	scanf("%d%d%d",&n,&m,&q);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) nxt[a[i]]=a[i%n+1];
	for (int i=1;i<=m;i++) scanf("%d",&b[i]);
	for (int i=m;i>=1;i--)
		p[i][0]=now[nxt[b[i]]],now[b[i]]=i;
	int h=int(log(m)/log(2));
	for (int i=1;i<=h;i++)
		for (int j=1;j<=m;j++)
			p[j][i]=p[p[j][i-1]][i-1];
	Pow[0]=1;
	for (int i=1;i<=20;i++) Pow[i]=Pow[i-1]*2;
	for (int i=1;i<=m;i++)
	{
		int x=n-1;ans[i]=i;
		for (int j=20;j>=0;j--)
			if (Pow[j]<=x) {x-=Pow[j];ans[i]=p[ans[i]][j];}
		if (ans[i]==0) ans[i]=998244353;
	}
	build(1,1,m);
	for (int i=1;i<=q;i++)
	{
		int l,r;scanf("%d%d",&l,&r);
		if (query(1,1,m,l,r)>r) putchar('0');else putchar('1');
	}
}


#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int n,m,q;
int a[N],p[N],pre[N],lst[N],f[N][20],mx[N];
struct Segtree{int l,r,maxx;} tr[N<<2];
void build(int l,int r,int k)
{
	tr[k].l=l,tr[k].r=r;
	if(l==r) {tr[k].maxx=mx[l]; return;}
	int mid=(l+r)>>1;
	build(l,mid,k<<1); build(mid+1,r,k<<1|1);
	tr[k].maxx=max(tr[k<<1].maxx,tr[k<<1|1].maxx);
}
int query(int l,int r,int k)
{
	if(l<=tr[k].l && tr[k].r<=r) return tr[k].maxx;
	int ret=0,mid=(tr[k].l+tr[k].r)>>1;
	if(l<=mid) ret=max(ret,query(l,r,k<<1));
	if(r>mid) ret=max(ret,query(l,r,k<<1|1));
	return ret;
}
int main()
{
	scanf("%d%d%d",&n,&m,&q);
	for(int i=1;i<=n;++i) scanf("%d",&p[i]);
	for(int i=2;i<=n;++i) pre[p[i]]=p[i-1];
	pre[p[1]]=p[n];
	for(int i=1;i<=m;++i) scanf("%d",&a[i]);
	for(int i=1;i<=m;++i)
		f[i][0]=lst[pre[a[i]]],lst[a[i]]=i;
	for(int i=1;i<=19;++i)
		for(int j=1;j<=m;++j)
			f[j][i]=f[f[j][i-1]][i-1];
	for(int i=1;i<=m;++i)
	{
		int s=n-1,c=0; mx[i]=i;
		while(s)
		{
			if(s&1) mx[i]=f[mx[i]][c];
			s>>=1,++c;
		}
	}
	build(1,m,1);
	while(q--)
	{
		int l,r;
		scanf("%d%d",&l,&r);
		printf("%s",query(l,r,1)>=l?"1":"0");
	}
	return 0;
}


#include<cstdio>
#include<set>
using namespace std;

set <int> s1[200050];
int nxt[200050], fa[200050], end[200050], a[200050], b[200050];

int getend(int w, int n){
	while(n) w = fa[w], n--;
	return w;
}

int test(int l, int r){
	for(int i = l; i <= r; i++) if(end[i] >= l && end[i] <= r) return 1;
	return 0;
}

int main(){
	int n, m, q;
	scanf("%d %d %d", &n, &m, &q);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(int i = 1; i < n; i++) nxt[a[i]] = a[i+1];
	nxt[a[n]] = a[1];
	for(int i = 1; i <= m; i++) {
		scanf("%d", &b[i]);
		s1[b[i]].insert(i);
	}
	for(int i = 1; i <= m; i++) {
		int k = *s1[nxt[b[i]]].upper_bound(i);
		if(k > i && k <= m) fa[i] = k;
	}
	for(int i = 1; i <= m; i++) end[i] = getend(i, n-1);
	for(int i = 1; i <= q; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		printf("%d", test(x, y));
	}
}


//@winlere
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;  typedef long long ll;
inline int qr(){
	register int ret=0,f=0;
	register char c=getchar();
	while(!isdigit(c))f|=c==45,c=getchar();
	while(isdigit(c)) ret=ret*10+c-48,c=getchar();
	return f?-ret:ret;
}
const int maxn=2e5+5;
int p[maxn],data[maxn];
int st[19][maxn],Pair[maxn],Min[19][maxn];
int lg[maxn];
int last[maxn];
int n,m,T;
const int inf=0x3f3f3f3f;
int main(){
	/*
#ifndef ONLINE_JUDGE
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	*/
	m=qr(); n=qr();  T=qr();
	lg[1]=0;
	for(int t=2;t<=n;++t) lg[t]=lg[t>>1]+1;
	for(int t=1;t<=m;++t) p[t]=qr();
	for(int t=1;t<=n;++t) data[t]=p[qr()];
	//for(int t=1;t<=n;++t) cerr<<data[t]<<' ';
	//cerr<<('\n');
	for(int t=n;t;--t){
		if(last[data[t]+1]) st[0][t]=last[data[t]+1];
		if(data[t]==m&&last[1]) st[0][t]=last[1];
		last[data[t]]=t;
	}
	//for(int t=1;t<=n;++t) cerr<<st[0][t]<<' ';
	//cerr<<endl;
	for(int t=1;t<=lg[m];++t)
		for(int i=1;i<=n;++i)
			st[t][i]=st[t-1][st[t-1][i]];
	memset(Min,0x3f,sizeof Min);
	for(int t=1;t<=n;++t){
		int k=t;
		for(int i=0;i<=lg[m-1];++i)
			if(((m-1)>>i&1))
				k=st[i][k];
		if(k) Min[0][t]=k;
	}
	for(int t=1;t<=lg[n];++t)
		for(int i=1;i<=n;++i)
			Min[t][i]=min(Min[t-1][i]?Min[t-1][i]:inf,Min[t-1][i+(1<<t>>1)]?Min[t-1][i+(1<<t>>1)]:inf);
	//for(int t=1;t<=n;++t) cerr<<Min[1][t]<<' ';
	//cerr<<endl;
	while(T--){
		int l=qr(),r=qr();
		//cerr<<"min="<<Min[lg[r-l+1]][l]<<' '<<Min[lg[r-l+1]][r-(1<<lg[r-l+1])+1] <<endl;
		if(min(Min[lg[r-l+1]][l],Min[lg[r-l+1]][r-(1<<lg[r-l+1])+1])<=r) putchar(49);
		else putchar(48);
	}
	putchar(10);
	return 0;
}


#include <bits/stdc++.h>
#define add push_back
#define ll long long
using namespace std;
const int N = 200005;
int n, m, q, log2n;
int f[N][50], a[N], b[N], c[N], pos[N], ps[N];
vector<int> p[N];
int father(int u, int k){
	for (int i = 0; k; i++, k >>= 1) if (k&1) u = f[u][i];
	return u;
}
int main(){
	std::ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
//	freopen("test_file/in.txt", "r", stdin);
//	freopen("test_file/out.out", "w", stdout);
	memset(pos, 0, sizeof(pos));
	cin >> n >> m >> q;
	for (int i = 1; i <= n; i++) cin >> a[i], ps[a[i]] = i;
	for (int i = 1; i <= m; i++) cin >> b[i];
	a[n+1] = a[1];
	for (int i = m; i >= 1; i--){
		if (pos[a[ps[b[i]]+1]] != 0){
			p[i].add(pos[a[ps[b[i]]+1]]);
			p[pos[a[ps[b[i]]+1]]].add(i);
			f[i][0] = pos[a[ps[b[i]]+1]];
		}
		pos[b[i]]= i;
	}
	log2n = round(log2(m));
	for (int j = 1; j <= log2n; j++)
		for (int i = 1; i <= m; i++)
			f[i][j] = f[f[i][j-1]][j-1];
	for (int i = 1; i <= n; i++) c[i] = father(i, n-1);
	for (int i = 0; i < q; i++){
		int u, v;
		cin >> u >> v;
		cout << (c[u] != 0 && v >= c[u]);
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <utility>
#include <algorithm>
#include <vector>
#define rg register
#define il inline
#define ll long long
using namespace std;
il void read(int &x){
    rg char c=getchar();
    while(c<'0'||c>'9') c=getchar();
    x=c^48;
	c=getchar();
    while(c>='0'&&c<='9'){
        x=(x<<1)+(x<<3)+(c^48);
        c=getchar();
    }
}

const int Inf=0x3f3f3f3f;
const int N=2e5+5;
struct Edge{
	int to,nxt;
}edge[N];
int cnt,head[N];
int n,m,q,l,r;
int p[N],a[N];
int dep[N],anc[N];
int pre[N],lst[N];
int s[N],val[N],k[N];

il void add_edge(int u,int v){
	edge[++cnt].to=v;
	edge[cnt].nxt=head[u];
	head[u]=cnt;
}
il void dfs(int u){
    anc[dep[u]]=u;
	if(dep[u]>=n)
		val[u]=anc[dep[u]-n+1];
	else
		val[u]=m+1;
    for(rg int i=head[u];i;i=edge[i].nxt){
    	int v=edge[i].to;
        dep[v]=dep[u]+1;
        dfs(v);
    }
}

signed main(){
	read(n);
	read(m);
	read(q);
	for(rg int i(1);i<=n;++i){
		read(p[i]);
		k[p[i]]=p[i-1];
	}
	k[p[1]]=p[n];
	for(rg int i(1);i<=m;++i){
		read(a[i]);
		pre[i]=lst[a[i]];
		lst[a[i]]=i;
        for(rg int j(lst[k[a[i]]]);j&&(s[j]==0);j=pre[j])
			s[j]=i;
	}
	for(rg int i(1);i<=m;++i)
		if(!s[i])
			s[i]=m+1;
	for(rg int i(1);i<=m;++i){
		add_edge(s[i],i);
		dfs(m+1);
	}
	for(rg int i(m-1);i;--i)
		val[i]=min(val[i],val[i+1]);
	while(q-->0){
		read(l);
		read(r);
		putchar('0'+(r[i]<=j))
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cmath>
#define il inline
#define ri register
#define Size 200050
using namespace std;
int p[Size],a[Size],b[Size],
	c[Size],dp[Size][18];
il void read(int&);
il int ask(int,int);
int main(){
	int n,m,q;
	read(n),read(m),read(q);
	for(int i(1);i<=n;++i)read(p[i]);
	for(int i(1);i<=m;++i)read(a[i]);
	for(int i(1);i<n;++i)b[p[i]]=p[i+1];
	b[p[n]]=p[1];
	for(int i(1);i<=n;++i)c[i]=m+1;
	for(int i(m);i;--i)
		dp[i][0]=c[b[a[i]]],c[a[i]]=i;
	for(int i,j(1);j<18;++j)
		for(i=1;i<=m;++i)
			if(dp[i][j-1]>m)dp[i][j]=m+1;
			else dp[i][j]=dp[dp[i][j-1]][j-1];
	for(int i(1),j,k;i<=m;++i)
		for(j=n-1,a[i]=i,k=17;~k;--k)
			if(j>>k&1&&a[i]<=m)a[i]=dp[a[i]][k];
	for(int i(1);i<=m;++i)dp[i][0]=a[i];
	for(int i,j(1);j<18;++j)
		for(i=1;i+(1<<j)-1<=m;++i)
			dp[i][j]=min(dp[i][j-1],dp[i+(1<<j-1)][j-1]);
	for(int i(1),l,r;i<=q;++i)
		read(l),read(r),putchar(ask(l,r)<=r?49:48);
	return 0;
}
il int ask(int l,int r){
	int t(log2(r-l+1));
	return min(dp[l][t],dp[r-(1<<t)+1][t]);
}
il void read(int &x){
	x^=x;ri char c;while(c=getchar(),c<'0'||c>'9');
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
}


#include<bits/stdc++.h>
using namespace std;
#define RI register int
#define LL long long
inline int read()
{
    int res=0,f=1;
    char ch=getchar();
    while(ch!='-'&&(ch>'9'||ch<'0'))
        ch=getchar();
    if(ch=='-')
        f=-1,ch=getchar();
    while(ch>='0'&&ch<='9')
        res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
    return res*f;
}
const int N=2e5+5;
int a[N],b[N];
int nxt[N],lst[N];
int f[N][20],to[N];
int g[N][20];
int ask(int l,int r)
{
	int t=log(r-l+1)/log(2);
	return min(g[l][t],g[r-(1<<t)+1][t]);
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int n=read(),m=read(),q=read();
	for(RI i=1;i<=n;++i)
		a[i]=read();
	for(RI i=1;i<n;++i)
		nxt[a[i]]=a[i+1];
	nxt[a[n]]=a[1];
	for(RI i=1;i<=m;++i)
		b[i]=read();
	for(RI i=m;i>=1;i--)
	{
		if(lst[nxt[b[i]]])
			f[i][0]=lst[nxt[b[i]]];
		lst[b[i]]=i;
	}
	int T=log(n)/log(2);
	for(RI t=1;t<=T;++t)
		for(RI i=1;i<=m;++i)
			f[i][t]=f[f[i][t-1]][t-1];
	for(RI j=1;j<=m;++j)
	{
		int p=j;
		for(RI t=T;t>=0;t--)
		{
			if(!p)
				break;
			if((n-1)&(1<<t))
				p=f[p][t];
		}
		if(p)
			to[j]=p;
		else
			to[j]=1<<30;
	}
	for(RI i=1;i<=m;++i)
		g[i][0]=to[i];
	T=log(m)/log(2);
	for(RI t=1;t<=T;++t)
		for(RI i=1;i<=m;++i)
			g[i][t]=min(g[i][t-1],g[i+(1<<(t-1))][t-1]);
	for(RI i=1;i<=q;++i)
	{
		int l=read(),r=read();
		int t=ask(l,r);
		if(t<=r)
			printf("1");
		else
			printf("0");
	}
	return 0;
}


#include <algorithm>
#include <cstdio>

inline int read(){
	char c=getchar(); int x=0,ft=1;
	for(;c<'0'||c>'9';c=getchar()) if(c=='-') ft=-1;
	for(;c>='0'&&c<='9';c=getchar()) x=x*10+c-'0';
	return x*ft;
}

const int N=2e5+5;

int n,m,q,p[N],a[N],pos[N],mint[N],fa[20][N];

int rig[N],ql[N],qr[N],id[N],sum[N],ans[N];

inline void add(int x,int c){
	for(int p=x;p<=m;p+=p&-p) sum[p]+=c;
}

inline int ask(int x){
	int res=0;
	for(int p=x;p;p-=p&-p) res+=sum[p];
	return res;
}

int main(){
	n=read(); m=read(); q=read(); ql[0]=m+1;
	for(int i=1;i<=n;++i) pos[p[i]=read()]=i;
	for(int i=1;i<=m;++i) a[i]=read();
	for(int i=m;i>=1;--i){
		fa[0][i]=mint[p[pos[a[i]]%n+1]]; mint[a[i]]=i;
	}
	for(int i=m;i>=1;--i){
		for(int j=1;j<=17;++j) fa[j][i]=fa[j-1][fa[j-1][i]];
	}
	for(int l=1;l<=m;++l){
		int lim=n-1; int& r=rig[l]; r=l;
		for(int j=0;j<=17;++j) if((lim>>j)&1) r=fa[j][r];
	}
	for(int i=1;i<=q;++i) ql[i]=read(),qr[i]=read(),id[i]=i;
	std::sort(id+1,id+1+q,[&](int a,int b){ return ql[a]>ql[b]; });
	for(int i=1;i<=q;++i){
		for(int j=ql[id[i]];j<ql[id[i-1]];++j){
			if(rig[j]) add(rig[j],1);
		}
		ans[id[i]]=(ask(qr[id[i]])>0);
	}
	for(int i=1;i<=q;++i) printf("%d",ans[i]);
	puts(""); return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define dd(x) cout<<#x<<"="<<x<<" , "
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<"="<<x<<"\n"
#define mes(p) memset(p,0,sizeof(p))
#define fi first
#define se second
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define pb push_back
#define ls (rt<<1)
#define rs (ls|1)
#define all(x) x.begin(),x.end()
const int maxn=200005;
typedef long long ll;
typedef vector <int > vi;
typedef pair <int ,int > pi;
const ll mod= 1000000007;
const int N=1e6+5;
int n,m,q;
int lg[maxn], a[maxn], pos[maxn], p[maxn], pre[maxn][21], st[maxn][21];
int last[maxn], b[maxn];
int rmq(int l,int r){
	int t=lg[l-r+1];
	return max(st[l][t],st[r-(1<<t)+1][t]);
}
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin>>n>>m>>q;
	rep(i,1,n+1) cin>>a[i], pos[a[i]] = i;
	a[0]=a[n];
	rep(i,1,n+1){
		p[a[i]] = a[i-1];
	}
	rep(i,1,m+1){
		cin>> b[i];
		pre[i][0] = last[p[b[i]]];
		last[b[i]] = i;
	}
	for(int i=1;i<=max(n,m);i++) lg[i]= lg[i>>1]+1;
	rep(t,1,lg[m]+1)
	rep(i,1,m+1)
		pre[i][t] = pre[pre[i][t-1]][t-1];
	rep(i,1,m+1){
		st[i][0] = i;
		rep(j,0,lg[n-1]+1){
			if((n-1)>>j&1)
			st[i][0]=pre[st[i][0]][j];
		}
	}
	rep(t,1,lg[m]+1){
		for(int j=1;j+(1<<t)-1<=m;j++)
			st[j][t] = max(st[j][t-1],st[j+(1<<(t-1))][t-1]);
	}
	while(q--){
		int l, r;
		cin>> l>> r;
		if(rmq(l,r)>=l)cout << "1";
		else cout << "0";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define dd(x) cout<<#x<<"="<<x<<" , "
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<"="<<x<<"\n"
#define mes(p) memset(p,0,sizeof(p))
#define fi first
#define se second
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define pb push_back
#define ls (rt<<1)
#define rs (ls|1)
#define all(x) x.begin(),x.end()
const int maxn=200005;
typedef long long ll;
typedef vector <int > vi;
typedef pair <int ,int > pi;
const ll mod= 1000000007;
const int N=1e6+5;
int n,m,q;
int lg[maxn], a[maxn], pos[maxn], p[maxn], pre[maxn][21], st[maxn][21];
int last[maxn], b[maxn];
int rmq(int l,int r){
	int t=lg[r-l+1];
	return max(st[l][t],st[r-(1<<t)+1][t]);
}
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin>>n>>m>>q;
	rep(i,1,n+1) cin>>a[i], pos[a[i]] = i;
	a[0]=a[n];
	rep(i,1,n+1){
		p[a[i]] = a[i-1];
	}
	rep(i,1,m+1){
		cin>> b[i];
		pre[i][0] = last[p[b[i]]];
		last[b[i]] = i;
	}
	for(int i=2;i<=max(n,m);i++) lg[i]= lg[i>>1]+1;
	rep(t,1,lg[n]+1)
	rep(i,1,m+1)
		pre[i][t] = pre[pre[i][t-1]][t-1];
	rep(i,1,m+1){
		st[i][0] = i;
		rep(j,0,lg[n-1]+1){
			if(((n-1)>>j)&1)
			st[i][0]=pre[st[i][0]][j];
		}
	}
	rep(t,1,lg[m]+1){
		for(int j=1;j+(1<<t)-1<=m;j++)
			st[j][t] = max(st[j][t-1],st[j+(1<<(t-1))][t-1]);
	}
	while(q--){
		int l, r;
		cin>> l>> r;
		if(rmq(l,r)>=l)cout << "1";
		else cout << "0";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define dd(x) cout<<#x<<"="<<x<<" , "
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<"="<<x<<"\n"
#define mes(p) memset(p,0,sizeof(p))
#define fi first
#define se second
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define pb push_back
#define ls (rt<<1)
#define rs (ls|1)
#define all(x) x.begin(),x.end()
const int maxn=200005;
typedef long long ll;
typedef vector <int > vi;
typedef pair <int ,int > pi;
const ll mod= 1000000007;
const int N=1e6+5;
int n,m,q;
int lg[maxn], a[maxn], pos[maxn], p[maxn], pre[maxn][21], st[maxn][21];
int last[maxn], b[maxn];
int rmq(int l,int r){
	int t=lg[l-r+1];
	return max(st[l][t],st[r-(1<<t)+1][t]);
}
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin>>n>>m>>q;
	rep(i,1,n+1) cin>>a[i], pos[a[i]] = i;
	a[0]=a[n];
	rep(i,1,n+1){
		p[a[i]] = a[i-1];
	}
	rep(i,1,m+1){
		cin>> b[i];
		pre[i][0] = last[p[b[i]]];
		last[b[i]] = i;
	}
	for(int i=2;i<=max(n,m);i++) lg[i]= lg[i>>1]+1;
	rep(t,1,lg[n]+1)
	rep(i,1,m+1)
		pre[i][t] = pre[pre[i][t-1]][t-1];
	rep(i,1,m+1){
		st[i][0] = i;
		rep(j,0,lg[n-1]+1){
			if(((n-1)>>j)&1)
			st[i][0]=pre[st[i][0]][j];
		}
	}
	rep(t,1,lg[m]+1){
		for(int j=1;j+(1<<t)-1<=m;j++)
			st[j][t] = max(st[j][t-1],st[j+(1<<(t-1))][t-1]);
	}
	while(q--){
		int l, r;
		cin>> l>> r;
		if(rmq(l,r)>=l)cout << "1";
		else cout << "0";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define dd(x) cout<<#x<<"="<<x<<" , "
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define de(x) cout<<#x<<"="<<x<<"\n"
#define mes(p) memset(p,0,sizeof(p))
#define fi first
#define se second
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define sz(x) (int)x.size()
#define pb push_back
#define ls (rt<<1)
#define rs (ls|1)
#define all(x) x.begin(),x.end()
const int maxn=200005;
typedef long long ll;
typedef vector <int > vi;
typedef pair <int ,int > pi;
const ll mod= 1000000007;
const int N=1e6+5;
int n,m,q;
int lg[maxn], a[maxn], pos[maxn], p[maxn], pre[maxn][21], st[maxn][21];
int last[maxn], b[maxn];
int rmq(int l,int r){
	int t=lg[l-r+1];
	return max(st[l][t],st[r-(1<<t)+1][t]);
}
int main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
	cin>>n>>m>>q;
	rep(i,1,n+1) cin>>a[i], pos[a[i]] = i;
	a[0]=a[n];
	rep(i,1,n+1){
		p[a[i]] = a[i-1];
	}
	rep(i,1,m+1){
		cin>> b[i];
		pre[i][0] = last[p[b[i]]];
		last[b[i]] = i;
	}
	for(int i=2;i<=max(n,m);i++) lg[i]= lg[i>>1]+1;
	rep(t,1,lg[m]+1)
	rep(i,1,m+1)
		pre[i][t] = pre[pre[i][t-1]][t-1];
	rep(i,1,m+1){
		st[i][0] = i;
		rep(j,0,lg[n-1]+1){
			if((n-1)>>j&1)
			st[i][0]=pre[st[i][0]][j];
		}
	}
	rep(t,1,lg[m]+1){
		for(int j=1;j+(1<<t)-1<=m;j++)
			st[j][t] = max(st[j][t-1],st[j+(1<<(t-1))][t-1]);
	}
	while(q--){
		int l, r;
		cin>> l>> r;
		if(rmq(l,r)>=l)cout << "1";
		else cout << "0";
	}
	return 0;
}


#include<bits/stdc++.h>
#define o 1000005
#define re register int
#define ll long long
#define g0(a) memset(a,0,sizeof(a))
#define gc(a,b) memcpy(a,b,sizeof(a))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)
#define pa pair<int,int>
#define mpp make_pair
#define s1 first
#define s2 second
using namespace std;
inline int read()
{
	register int data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=(data<<1)+(data<<3)+(ch^48),ch=getchar();
	return data*w;
}
int n,m,q,p[o],pre[o],las[o],st[o],t[o],h[o],cnt;
struct node
{
	int to,next;
}w[o];
void add(int x,int y){w[++cnt]=(node){y,h[x]};h[x]=cnt;}
void dfs(int x,int d)
{
	st[d]=x;
	t[x]=(d-n+1>=0?st[d-n+1]:0);
	for(int i=h[x];i;i=w[i].next)dfs(w[i].to,d+1);
}
int main()
{
	n=read(),m=read(),q=read();
	FOR(i,1,n)p[i]=read();
	FOR(i,1,n)pre[p[i]]=(i-1?p[i-1]:p[n]);
	FOR(i,1,m)
	{
		int x=read();
		add(las[pre[x]],i);
		las[x]=i;
	}
	dfs(0,0);
	FOR(i,1,m)t[i]=max(t[i],t[i-1]);
	while(q--)
	{
		int l=read(),r=read();
		cout<<(t[r]>=l);
	}
	return 0;
}


#include<bits/stdc++.h>
#define o 1000005
#define re register int
#define ll long long
#define g0(a) memset(a,0,sizeof(a))
#define gc(a,b) memcpy(a,b,sizeof(a))
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(i,a,b) for(int i=a;i>=b;i--)
#define pa pair<int,int>
#define mpp make_pair
#define s1 first
#define s2 second
using namespace std;
inline int read()
{
	register int data=0,w=1;
	char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar();
	if(ch=='-')w=-1,ch=getchar();
	while(ch>='0'&&ch<='9')data=(data<<1)+(data<<3)+(ch^48),ch=getchar();
	return data*w;
}
int n,m,q,p[o],pre[o],las[o],st[o],t[o],h[o],cnt;
struct node
{
	int to,next;
}w[o];
void add(int x,int y){w[++cnt]=(node){y,h[x]};h[x]=cnt;}
void dfs(int x,int d)
{
	t[x]=(d-n+1>=0?st[d-n+1]:0);
	st[d]=x;
	for(int i=h[x];i;i=w[i].next)dfs(w[i].to,d+1);
}
int main()
{
	n=read(),m=read(),q=read();
	FOR(i,1,n)p[i]=read();
	FOR(i,1,n)pre[p[i]]=(i-1?p[i-1]:p[n]);
	FOR(i,1,m)
	{
		int x=read();
		add(las[pre[x]],i);
		las[x]=i;
	}
	dfs(0,0);
//	FOR(i,1,m)cout<<t[i]<<" ";
//	return 0;
	FOR(i,1,m)t[i]=max(t[i],t[i-1]);
	while(q--)
	{
		int l=read(),r=read();
		cout<<(t[r]>=l);
	}
	return 0;
}


#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <complex>
#include <ctime>
#include <queue>
using namespace std;

/*
��¼ÿ�����next Ȼ��ά��ǰ���n-1��pre
*/
const int N = 2e5 + 5;
int n, m, q;
int fol[N], pre[N], nex[N], rec[N], mx[N];
int a[N], b[N], rt[N];
struct Node{
	int l, r, w;
};

int main(){
	scanf("%d%d%d", &n, &m, &q);
	for(int i = 1; i <= n; ++i){
		scanf("%d", &a[i]);
		fol[a[i - 1]] = a[i];
	}
	fol[a[n]] = a[1];
	for(int i = 1; i <= m; ++i){
		scanf("%d", &b[i]);
	}
	for(int i = m; i >= 1; --i){
		nex[i] = rec[fol[b[i]]];
		rec[b[i]] = i;
	}
	for(int i = 1; i <= m; ++i){
		if(pre[i]){
			pre[nex[i]] = nex[pre[i]];
		}
		else{
			int k = i;
			for(int j = 1; j < n && k; ++j, k = nex[k]);
			if(k) pre[k] = i;
		}
		//printf("%d %d\n", i, pre[i]);
	}
	for(int i = 1; i <= m; ++i){
		mx[i] = max(mx[i - 1], pre[i]);
	}
	for(int i = 1, x, y; i <= q; ++i){
		scanf("%d%d", &x, &y);
		printf("%d", mx[y] >= x);
	}
	return 0;
}


#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <complex>
#include <ctime>
#include <queue>
using namespace std;

/*
��¼ÿ�����next Ȼ��ά��ǰ���n-1��pre
*/
const int N = 2e5 + 5;
int n, m, q;
int fro[N], pre[N][25], rec[N], mx[N];
int a[N], b[N], rt[N];

int main(){
	scanf("%d%d%d", &n, &m, &q);
	for(int i = 1; i <= n; ++i){
		scanf("%d", &a[i]);
		fro[a[i]] = a[i - 1];
	}
	fro[a[1]] = a[n];
	for(int i = 1; i <= m; ++i){
		scanf("%d", &b[i]);
		pre[i][0] = rec[fro[b[i]]], rec[b[i]] = i;
		for(int j = 1; j <= 20; ++j)
		    pre[i][j] = pre[pre[i][j - 1]][j - 1];
		int pos = i;
		for(int j = 20; j >= 0; --j)
		    if((1 << j) && (n - 1)) pos = pre[i][j];
		mx[i] = max(mx[i - 1], pos);
		//printf("%d\n", mx[i]);
	}
	for(int i = 1, x, y; i <= q; ++i){
		scanf("%d%d", &x, &y);
		printf("%d", mx[y] >= x);
	}
	return 0;
}


#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <complex>
#include <ctime>
#include <queue>
using namespace std;

/*
��¼ÿ�����next Ȼ��ά��ǰ���n-1��pre
*/
const int N = 2e5 + 5;
int n, m, q;
int fro[N], fol[N], pre[N], nex[N], rec[N], mx[N], bef[N];
int a[N], b[N], rt[N];
struct Node{
	int l, r, w;
};

int main(){
	scanf("%d%d%d", &n, &m, &q);
	for(int i = 1; i <= n; ++i){
		scanf("%d", &a[i]);
		fol[a[i - 1]] = a[i];
		fro[a[i]] = a[i - 1];
	}
	fol[a[n]] = a[1], fro[a[1]] = a[n];
	for(int i = 1; i <= m; ++i){
		scanf("%d", &b[i]);
	}
	for(int i = m; i >= 1; --i){
		nex[i] = rec[fol[b[i]]];
		rec[b[i]] = i;
	}
	memset(rec, 0, sizeof(rec));
	for(int i = 1; i <= m; ++i){
	    bef[i] = rec[fro[b[i]]];
		rec[b[i]] = i;
	}
	for(int i = 1; i <= m; ++i){
		if(pre[bef[i]]){
			pre[i] = nex[pre[bef[i]]];
		    continue;
		}
		int k = i;
		for(int j = 1; j < n && k; ++j, k = bef[k]);
		pre[i] = k;
		//printf("%d %d\n", i, pre[i]);
	}
	for(int i = 1; i <= m; ++i){
		mx[i] = max(mx[i - 1], pre[i]);
	}
	for(int i = 1, x, y; i <= q; ++i){
		scanf("%d%d", &x, &y);
		printf("%d", mx[y] >= x);
	}
	return 0;
}


#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <complex>
#include <ctime>
#include <queue>
using namespace std;

/*
��¼ÿ�����next Ȼ��ά��ǰ���n-1��pre
*/
const int N = 2e5 + 5;
int n, m, q;
int fol[N], pre[N], nex[N], rec[N];
int a[N], b[N], rt[N];
struct Node{
	int l, r, w;
};
struct Pr{
	Node node[N << 5]; int sz;
	void ins(int &cur, int l, int r, int x){
		if(!cur){node[++sz] = node[cur]; cur = sz;}
		++node[cur].w; if(l == r) return ;
		int mid = l + ((r - l) >> 1);
		if(x <= mid) ins(node[cur].l, l, mid, x);
		else ins(node[cur].r, mid + 1, r, x);
	}
	int qry(int c1, int c2, int l, int r, int x, int y){
		///printf("%d %d %d %d %d %d\n", l, r, x, y, node[c1].w, node[c2].w);
		if(x <= l && r <= y) return node[c2].w - node[c1].w;
		int mid = l + ((r - l) >> 1), res = 0;
		if(x <= mid) res += qry(node[c1].l, node[c2].l, l, mid, x, y);
		if(y > mid) res += qry(node[c1].r, node[c2].r, mid + 1, r, x, y);
		return res;
	}
}pr;

int main(){
	scanf("%d%d%d", &n, &m, &q);
	for(int i = 1; i <= n; ++i){
		scanf("%d", &a[i]);
		fol[a[i - 1]] = a[i];
	}
	fol[a[n]] = a[1];
	for(int i = 1; i <= m; ++i){
		scanf("%d", &b[i]);
	}
	for(int i = m; i >= 1; --i){
		nex[i] = rec[fol[b[i]]];
		rec[b[i]] = i;
	}
	for(int i = 1; i <= m; ++i){
		if(pre[i]){
			pre[nex[i]] = nex[pre[i]];
		}
		else{
			int k = i;
			for(int j = 1; j < n && k; ++j, k = nex[k]);
			if(k) pre[k] = i;
		}
		//printf("%d %d\n", i, pre[i]);
	}
	for(int i = 1; i <= m; ++i){
		rt[i] = rt[i - 1];
		if(pre[i]) pr.ins(rt[i], 1, m, pre[i]);
	}
	for(int i = 1, x, y; i <= q; ++i){
		scanf("%d%d", &x, &y);
		printf("%d", pr.qry(rt[x - 1], rt[y], 1, m, x, y) > 0);
	}
	return 0;
}


#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <complex>
#include <ctime>
#include <queue>
using namespace std;

/*
��¼ÿ�����next Ȼ��ά��ǰ���n-1��pre
*/
const int N = 2e5 + 5;
int n, m, q;
int fro[N], pre[N][25], rec[N], mx[N];
int a[N], b[N], rt[N];

int main(){
	scanf("%d%d%d", &n, &m, &q);
	for(int i = 1; i <= n; ++i){
		scanf("%d", &a[i]);
		fro[a[i]] = a[i - 1];
	}
	fro[a[1]] = a[n];
	for(int i = 1; i <= m; ++i){
		scanf("%d", &b[i]);
		pre[i][0] = rec[b[i]], rec[b[i]] = i;
		for(int j = 1; j <= 20; ++j)
		    pre[i][j] = pre[pre[i][j - 1]][j - 1];
		int pos = i;
		for(int j = 20; j >= 0; --j)
		    if((1 << j) && (n - 1)) pos = pre[i][j];
		mx[i] = max(mx[i - 1], pos);
	}
	for(int i = 1, x, y; i <= q; ++i){
		scanf("%d%d", &x, &y);
		printf("%d", mx[y] >= x);
	}
	return 0;
}


#include <cmath>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <complex>
#include <ctime>
#include <queue>
using namespace std;

/*
��¼ÿ�����next Ȼ��ά��ǰ���n-1��pre
*/
const int N = 2e5 + 5;
int n, m, q;
int fro[N], pre[N][25], rec[N], mx[N];
int a[N], b[N], rt[N];

int main(){
	scanf("%d%d%d", &n, &m, &q);
	for(int i = 1; i <= n; ++i){
		scanf("%d", &a[i]);
		fro[a[i]] = a[i - 1];
	}
	fro[a[1]] = a[n];
	for(int i = 1; i <= m; ++i){
		scanf("%d", &b[i]);
		pre[i][0] = rec[fro[b[i]]], rec[b[i]] = i;
		for(int j = 1; j <= 20; ++j)
		    pre[i][j] = pre[pre[i][j - 1]][j - 1];
		int pos = i;
		//printf("%d %d\n", pre[i][0], pre[i][1]);
		for(int j = 20; j >= 0; --j)
		    if((1 << j) & (n - 1)){
		    	//printf("pos = %d\n", j);
		    	pos = pre[pos][j];
		    }
		mx[i] = max(mx[i - 1], pos);
	}
	for(int i = 1, x, y; i <= q; ++i){
		scanf("%d%d", &x, &y);
		printf("%d", mx[y] >= x);
	}
	return 0;
}


#include<bits/stdc++.h>
#define inf 1000000009
using namespace std;
int res[200005], ara[200005], b[200005], nxt[200005], freq[200005], pp[200005], prv[200005];
bool f[200005], ans[200005];
int seg[200005*4];
typedef pair<int, int>pi;
map<pi, int>mp;
bool ase[200005];
void update(int n, int s, int e, int ind, int val)
{
    if(s==ind && e==ind)
    {
        seg[n]= val;
        return;
    }
    if(s>ind || e<ind)
        return;
    int mid=(s+e)>>1;
    update(n*2, s, mid, ind, val);
    update(n*2 +1, mid+1, e, ind, val);
    seg[n]= min(seg[n*2], seg[n*2 +1]);
    return;
}
int query(int n, int s, int e, int l, int r)
{
    if(s>=l && e<=r)
        return seg[n];
    if(s>r || e<l)
        return inf;
    int mid=(s+e)>>1;
    return min( query(n*2, s, mid, l, r), query(n*2 +1, mid+1, e, l, r) );
}
int main()
{
    int n, m, q, x, y;
    scanf("%d %d %d", &n, &m, &q);
    for(int i=1; i<=n;i++)scanf("%d", &ara[i]), nxt[ ara[i-1] ]= ara[i], ase[ ara[i] ]= 1;
    nxt[ ara[n] ]= ara[1];
    for(int i=1; i<=n; i++)
    {
        x= i+n-1;
        if(x>n)x-= n;
        prv[ ara[i] ]= ara[x];
    }
    for(int i=1; i<=m;i++)scanf("%d", &b[i]);
    for(int i=m; i>=1; i--)
    {
        if(!ase[ b[i] ])continue;
        if(n==1)f[i]= 1, pp[i]= i;
        else
        {
            freq[ b[i] ]= freq[ nxt[ b[i] ] ]+1;
            mp[ { b[i], freq[ b[i] ] } ]= i;
            if(freq[ b[i] ]>=n)f[i]=1, pp[i]= mp[ { prv[ b[i] ], freq[ b[i] ]-(n-1) } ];
        }
    }
    for(int i=1; i<=m; i++)
    {
        if(!f[i])update(1, 1, n, i, inf);
        else update(1, 1, n, i, pp[i]);
    }
    int p= 0;
    while(q--)
    {
        scanf("%d %d", &x, &y);
        x= query(1, 1, n, x, y);
        if(x<=y)ans[p]= 1;
        p++;
    }
    for(int i=0; i<p; i++)
        printf("%d", ans[i]);puts("");
    return 0;
}


#include<bits/stdc++.h>
#define inf 1000000009
using namespace std;
int res[200005], ara[200005], b[200005], nxt[200005], freq[200005], ind[200005];
bool f[200005], ans[200005];
int seg[200005*4];
void update(int n, int s, int e, int ind, int val)
{
    if(s==ind && e==ind)
    {
        seg[n]= val;
        return;
    }
    if(s>ind || e<ind)
        return;
    int mid=(s+e)>>1;
    update(n*2, s, mid, ind, val);
    update(n*2 +1, mid+1, e, ind, val);
    seg[n]= min(seg[n*2], seg[n*2 +1]);
    return;
}
int query(int n, int s, int e, int l, int r)
{
    if(s>=l && e<=r)
        return seg[n];
    if(s>r || e<l)
        return inf;
    int mid=(s+e)>>1;
    return min( query(n*2, s, mid, l, r), query(n*2 +1, mid+1, e, l, r) );
}
int main()
{
    int n, m, q, x, y;
    scanf("%d %d %d", &n, &m, &q);
    for(int i=1; i<=n;i++)scanf("%d", &ara[i]), nxt[ ara[i-1] ]= ara[i];
    nxt[ ara[n] ]= ara[1];
    for(int i=1; i<=m;i++)scanf("%d", &b[i]);
    for(int i=m; i>=1; i--)
    {
        freq[ b[i] ]= freq[ nxt[ b[i] ] ]+1;
        ind[ b[i] ]= i;
        if(freq[ b[i] ]>=n)f[i]= 1, ind[ b[i] ]= ind[ nxt[ b[i] ] ];
    }
    for(int i=1; i<=m; i++)
    {
        if(!f[i])update(1, 1, n, i, inf);
        else update(1, 1, n, i, ind[ b[i] ]);
    }
    int p= 0;
    while(q--)
    {
        scanf("%d %d", &x, &y);
        x= query(1, 1, n, x, y);
        if(x<=y)ans[p]= 1;
        p++;
    }
    for(int i=0; i<p; i++)
        printf("%d", ans[i]);puts("");
    return 0;
}


#include<bits/stdc++.h>
#define inf 1000000009
using namespace std;
int res[200005], ara[200005], b[200005], nxt[200005], freq[200005], ind[200005], pp[200005], prv[200005];
bool f[200005], ans[200005];
int seg[200005*4];
void update(int n, int s, int e, int ind, int val)
{
    if(s==ind && e==ind)
    {
        seg[n]= val;
        return;
    }
    if(s>ind || e<ind)
        return;
    int mid=(s+e)>>1;
    update(n*2, s, mid, ind, val);
    update(n*2 +1, mid+1, e, ind, val);
    seg[n]= min(seg[n*2], seg[n*2 +1]);
    return;
}
int query(int n, int s, int e, int l, int r)
{
    if(s>=l && e<=r)
        return seg[n];
    if(s>r || e<l)
        return inf;
    int mid=(s+e)>>1;
    return min( query(n*2, s, mid, l, r), query(n*2 +1, mid+1, e, l, r) );
}
int main()
{
    int n, m, q, x, y;
    scanf("%d %d %d", &n, &m, &q);
    for(int i=1; i<=n;i++)scanf("%d", &ara[i]), nxt[ ara[i-1] ]= ara[i];
    nxt[ ara[n] ]= ara[1];
    for(int i=1; i<=n; i++)
    {
        x= i+n-1;
        if(x>n)x-= n;
        prv[ ara[i] ]= ara[x];
    }
    for(int i=1; i<=m;i++)scanf("%d", &b[i]);
    for(int i=m; i>=1; i--)
    {
        freq[ b[i] ]= freq[ nxt[ b[i] ] ]+1;
        ind[ b[i] ]= i;
        if(freq[ b[i] ]>=n)f[i]= 1, pp[i]= ind[ prv[ b[i] ] ];
    }
    for(int i=1; i<=m; i++)
    {
        if(!f[i])update(1, 1, n, i, inf);
        else update(1, 1, n, i, pp[i]);
    }
    int p= 0;
    while(q--)
    {
        scanf("%d %d", &x, &y);
        x= query(1, 1, n, x, y);
        if(x<=y)ans[p]= 1;
        p++;
    }
    for(int i=0; i<p; i++)
        printf("%d", ans[i]);puts("");
    return 0;
}


#include<bits/stdc++.h>
#define inf 1000000009
using namespace std;
int res[200005], ara[200005], b[200005], nxt[200005], freq[200005], ind[200005], pp[200005], prev[200005];
bool f[200005], ans[200005];
int seg[200005*4];
void update(int n, int s, int e, int ind, int val)
{
    if(s==ind && e==ind)
    {
        seg[n]= val;
        return;
    }
    if(s>ind || e<ind)
        return;
    int mid=(s+e)>>1;
    update(n*2, s, mid, ind, val);
    update(n*2 +1, mid+1, e, ind, val);
    seg[n]= min(seg[n*2], seg[n*2 +1]);
    return;
}
int query(int n, int s, int e, int l, int r)
{
    if(s>=l && e<=r)
        return seg[n];
    if(s>r || e<l)
        return inf;
    int mid=(s+e)>>1;
    return min( query(n*2, s, mid, l, r), query(n*2 +1, mid+1, e, l, r) );
}
int main()
{
    int n, m, q, x, y;
    scanf("%d %d %d", &n, &m, &q);
    for(int i=1; i<=n;i++)scanf("%d", &ara[i]), nxt[ ara[i-1] ]= ara[i];
    nxt[ ara[n] ]= ara[1];
    for(int i=1; i<=n; i++)
    {
        x= i+n-1;
        if(x>n)x-= n;
        prev[ ara[i] ]= ara[x];
    }
    for(int i=1; i<=m;i++)scanf("%d", &b[i]);
    for(int i=m; i>=1; i--)
    {
        freq[ b[i] ]= freq[ nxt[ b[i] ] ]+1;
        ind[ b[i] ]= i;
        if(freq[ b[i] ]>=n)f[i]= 1, pp[i]= ind[ prev[ b[i] ] ];
    }
    for(int i=1; i<=m; i++)
    {
        if(!f[i])update(1, 1, n, i, inf);
        else update(1, 1, n, i, pp[i]);
    }
    int p= 0;
    while(q--)
    {
        scanf("%d %d", &x, &y);
        x= query(1, 1, n, x, y);
        if(x<=y)ans[p]= 1;
        p++;
    }
    for(int i=0; i<p; i++)
        printf("%d", ans[i]);puts("");
    return 0;
}


#include<bits/stdc++.h>
#define inf 1000000009
using namespace std;
int ara[200005], b[200005], nxt[200005], ind[200005], lev[200005], ans[200005];
char str[200005];
vector<int>vec[200005];
int seg[4*200005];
void update(int n, int s, int e, int ind, int val)
{
    if(s==ind && e==ind)
    {
        seg[n]= val;
        return;
    }
    if(s>ind || e<ind)
        return;
    int mid= (s+e)>>1;
    update(n*2, s, mid, ind, val);
    update(n*2 +1, mid+1, e, ind, val);
    seg[n]= min(seg[n*2], seg[n*2 +1]);
    return;
}
int query(int n, int s, int e, int l, int r)
{
    if(s>=l && e<=r)
        return seg[n];
    if(s>r|| e<l)
        return inf;
    int mid= (s+e)>>1;
    return min(query(n*2, s, mid, l, r), query(n*2 +1, mid+1, e, l, r));
}
void dfs(int x, int c, int n)
{
    lev[c]= x;
    if(c>=n)ans[x]= lev[c-n+1];
    for(int i=0; i<vec[x].size(); i++)
    {
        int y= vec[x][i];
        dfs(y, c+1, n);
    }return;
}
int main()
{
    int n, m, q, p= 0, x, y;
    scanf("%d %d %d", &n, &m, &q);
    for(int i=1; i<=n; i++)scanf("%d", &ara[i]);ara[n+1]= ara[1];
    for(int i=1; i<=n; i++)nxt[ ara[i] ]= ara[i+1];
    for(int i=1; i<=m; i++)scanf("%d", &b[i]);
    for(int i=m; i>=1; i--)
        vec[ ind[ nxt[ b[i] ] ] ].push_back(i), ind[ b[i] ]= i, ans[i]= inf;
    dfs(0, 0, n);
    for(int i=1; i<=m; i++)
        update(1, 1, m, i, ans[i]);
    while(q--)
    {
        scanf("%d %d", &x, &y);
        x= query(1, 1, m, x, y);
        if(x<=y)str[p++]= '1';
        else str[p++]= '0';
    }for(int i=0; i<p; i++)printf("%c", str[i]);puts("");
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define cg ch=getchar()
#define int long long

const int _=400002;
int number,m,num[_],p[_],Q,last_n[_],last_id[_],father[_][30],ans[_],lg[_];
struct Tree{int l,r,maxx;}tree[_*4+1];

int read(){
	int s=0,w=1;char cg;
	while(ch<'0'||ch>'9')w=(ch=='-')?-1:1,cg;
	while(ch>='0'&&ch<='9')s=s*10+ch-'0',cg;
	return s*w;
}

void Build(int k,int l,int r){
	tree[k].l=l;tree[k].r=r;
	if(l==r){
		tree[k].maxx=ans[l];return;
	}
	int mid=(l+r)>>1;
	Build(k*2,l,mid);Build(k*2+1,mid+1,r);
	tree[k].maxx=max(tree[k*2].maxx,tree[k*2+1].maxx);
}

int get_max(int k,int l,int r){
	if(l<=tree[k].l&&tree[k].r<=r)return tree[k].maxx;
	int maxx=-1e12-1,mid=(tree[k].l+tree[k].r)>>1;
	if(l<=mid)maxx=max(get_max(k*2,l,r),maxx);
	if(mid<r)maxx=max(get_max(k*2+1,l,r),maxx);
	return maxx;
}

signed main(){
	m=read();number=read();Q=read();
	for(int i=1;i<=m;i++)p[i]=read(),last_n[p[i]]=p[i-1];
	last_n[p[1]]=p[m];
	for(int i=1;i<=number;i++){
		num[i]=read();
		father[i][0]=last_id[last_n[num[i]]];last_id[num[i]]=i;
	}
	if(number<m){
		for(int i=1;i<=Q;i++)cout<<"0";
		return 0;
	}
	for(int i=2;i<=number;i++)lg[i]=lg[i/2]+1;
	for(int i=1;i<=number;i++)
		for(int j=1;j<=lg[m];j++)
			father[i][j]=father[father[i][j-1]][j-1];
    for(int i=1;i<=number;i++){
		int now=i;
		for(int j=lg[m];j>=0;j--){
			if((m-1)&(1<<j))
				now=father[now][j];
		}
		ans[i]=now;
	}
	Build(1,1,number);
	for(int i=1;i<=Q;i++){
		int l=read(),r=read();
		if(get_max(1,l,r)>=l)cout<<1;
		else cout<<0;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define cg ch=getchar()
#define int long long

const int _=400002;
int number,m,num[_],p[_],Q,last_n[_],last_id[_],father[_][30],ans[_],lg[_];
struct Tree{int l,r,maxx;}tree[_*4+1];

int read(){
	int s=0,w=1;char cg;
	while(ch<'0'||ch>'9')w=(ch=='-')?-1:1,cg;
	while(ch>='0'&&ch<='9')s=s*10+ch-'0',cg;
	return s*w;
}

void Build(int k,int l,int r){
	tree[k].l=l;tree[k].r=r;
	if(l==r){
		tree[k].maxx=ans[l];return;
	}
	int mid=(l+r)>>1;
	Build(k*2,l,mid);Build(k*2+1,mid+1,r);
	tree[k].maxx=max(tree[k*2].maxx,tree[k*2+1].maxx);
}

int get_max(int k,int l,int r){
	if(l<=tree[k].l&&tree[k].r<=r)return tree[k].maxx;
	int maxx=-1e12-1,mid=(tree[k].l+tree[k].r)>>1;
	if(l<=mid)maxx=max(get_max(k*2,l,r),maxx);
	if(mid<r)maxx=max(get_max(k*2+1,l,r),maxx);
	return maxx;
}

signed main(){
	m=read();number=read();Q=read();
	for(int i=1;i<=m;i++)p[i]=read(),last_n[p[i]]=p[i-1];
	last_n[p[1]]=p[m];
	for(int i=1;i<=number;i++){
		num[i]=read();
		father[i][0]=last_id[last_n[num[i]]];last_id[num[i]]=i;
	}
	if(number<m){
		for(int i=1;i<=Q;i++)cout<<"0";
		return 0;
	}
	for(int i=2;i<=number;i++)lg[i]=lg[i/2]+1;
	for(int i=1;i<=number;i++)
		for(int j=1;j<=lg[m];j++)
			father[i][j]=father[father[i][j-1]][j-1];
    for(int i=1;i<=number;i++){
		int now=i;
		for(int j=lg[m];j>=0;j--){
			if(i-(now-(1<<j))<=m-1)
				now=father[now][j],ans[i]=now;
		}
	}
	Build(1,1,number);
	for(int i=1;i<=Q;i++){
		int l=read(),r=read();
		if(get_max(1,l,r)>=l)cout<<1;
		else cout<<0;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define cg ch=getchar()
#define int long long

const int _=400002;
int number,m,num[_],p[_],Q,last_n[_],last_id[_],father[_][30],ans[_],lg[_];
struct Tree{int l,r,maxx;}tree[_*4+1];

int read(){
	int s=0,w=1;char cg;
	while(ch<'0'||ch>'9')w=(ch=='-')?-1:1,cg;
	while(ch>='0'&&ch<='9')s=s*10+ch-'0',cg;
	return s*w;
}

void Build(int k,int l,int r){
	tree[k].l=l;tree[k].r=r;
	if(l==r){
		tree[k].maxx=ans[l];return;
	}
	int mid=(l+r)>>1;
	Build(k*2,l,mid);Build(k*2+1,mid+1,r);
	tree[k].maxx=max(tree[k*2].maxx,tree[k*2+1].maxx);
}

int get_max(int k,int l,int r){
	if(l<=tree[k].l&&tree[k].r<=r)return tree[k].maxx;
	int maxx=-1e12-1,mid=(tree[k].l+tree[k].r)>>1;
	if(l<=mid)maxx=max(get_max(k*2,l,r),maxx);
	if(mid<r)maxx=max(get_max(k*2+1,l,r),maxx);
	return maxx;
}

signed main(){
	m=read();number=read();Q=read();
	for(int i=1;i<=m;i++)p[i]=read(),last_n[p[i]]=p[i-1];
	last_n[p[1]]=p[m];
	for(int i=1;i<=number;i++){
		num[i]=read();
		father[i][0]=last_id[last_n[num[i]]];last_id[num[i]]=i;
	}
	if(number<m){
		for(int i=1;i<=Q;i++)cout<<"0";
		return 0;
	}
	for(int i=2;i<=number;i++)lg[i]=lg[i/2]+1;
	for(int i=1;i<=number;i++)
		for(int j=1;j<=lg[m];j++)
			father[i][j]=father[father[i][j-1]][j-1];
    for(int i=1;i<=number;i++){
		int now=i;
		for(int j=lg[m];j>=0;j--){
			if(i-(now-(1<<j))<=m-1)
				now=father[i][j],ans[i]=now;
		}
	}
	Build(1,1,number);
	for(int i=1;i<=Q;i++){
		int l=read(),r=read();
		if(get_max(1,l,r)>=l)cout<<1;
		else cout<<0;
	}
	return 0;
}


#include<cmath>
#include<queue>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define IL inline
#define RG register
#define DB double
#define LL long long
using namespace std;

const int N=2e5+3;

queue<int> las[N];
int n,m,Q,p[N],a[N],lg[N],Ne[N],ans[N],f[N][21],ST[N][21];

IL int gi() {
	RG int x=0,p=1; RG char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') p=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	return x*p;
}

int main()
{
	RG int i,j,l,r;
	n=gi(),m=gi(),Q=gi();
	for(i=1;i<=n;++i) p[i]=gi(),Ne[p[i-1]]=p[i];
	for(i=1,Ne[p[n]]=p[1];i<=m;++i) a[i]=gi();
	for(i=1;i<=m;++i) {
		while(!las[a[i]].empty())
			f[las[a[i]].front()][0]=i,las[a[i]].pop();
		las[Ne[a[i]]].push(i);
	}
	for(i=1;i<=18;++i)
		for(j=1;j<=m;++j)
			f[j][i]=f[f[j][i-1]][i-1];
	for(i=1;i<=m;++i)
		for(j=18,ans[i]=i;~j;--j)
			if((n-1)&(1<<j)) ans[i]=f[ans[i]][j];
	for(i=0;i<=18;++i)
		for(j=1;j<=m;++j) ST[j][i]=0x3f3f3f3f;
	for(i=1;i<=m;++i) if(ans[i]) ST[i][0]=ans[i];
	for(i=1;i<=18;++i)
		for(j=1;j<=m;++j)
			ST[j][i]=min(ST[j][i-1],ST[j+(1<<i-1)][i-1]);
	for(i=1;i<=m;++i) lg[i]=log(i)/log(2);
	while(Q--) l=gi(),r=gi(),printf("%d",(min(ST[l][lg[r-l+1]],ST[r-(1<<lg[r-l+1])+1][lg[r-l+1]])<=r)?1:0);
	return 0;
}


#include<cmath>
#include<queue>
#include<string>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define IL inline
#define RG register
#define DB double
#define LL long long
using namespace std;

const int N=2e5+3;

queue<int> las[N];
int n,m,Q,p[N],a[N],lg[N],Ne[N],nex[N],ans[N],f[N][21],ST[N][21];

IL int gi() {
	RG int x=0,p=1; RG char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') p=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') x=x*10+(ch^48),ch=getchar();
	return x*p;
}

int main()
{
	RG int i,j,l,r;
	n=gi(),m=gi(),Q=gi();
	for(i=1;i<=n;++i) p[i]=gi(),Ne[p[i-1]]=p[i];
	for(i=1,Ne[p[n]]=p[1];i<=m;++i) a[i]=gi();
	for(i=1;i<=m;++i) {
		while(!las[a[i]].empty())
			nex[las[a[i]].front()]=i,las[a[i]].pop();
		las[Ne[a[i]]].push(i);
	}
//	for(i=1;i<=m;++i) printf("%d ",nex[i]);putchar('\n');
	for(i=1;i<=m;++i) f[i][0]=nex[i];
	for(i=1;i<=18;++i)
		for(j=1;j<=m;++j)
			f[j][i]=f[f[j][i-1]][i-1];
	for(i=1;i<=m;++i)
		for(j=18,ans[i]=i;~j;--j)
			if((n-1)&(1<<j)) ans[i]=f[ans[i]][j];
//	for(i=1;i<=m;++i) printf("%d ",ans[i]);putchar('\n');
	memset(ST,0x3f,sizeof(ST));
	for(i=1;i<=m;++i) if(ans[i]) ST[i][0]=ans[i];
//	for(i=1;i<=m;++i) printf("%d ",ST[i][0]);putchar('\n');
	for(i=1;i<=18;++i)
		for(j=1;j<=m;++j)
			ST[j][i]=min(ST[j][i-1],ST[j+(1<<i-1)][i-1]);
	for(i=1;i<=m;++i) lg[i]=log(i)/log(2);
//	for(i=1;i<=m;++i) printf("%d ",lg[i]);putchar('\n');
	while(Q--) l=gi(),r=gi(),printf("%d",(min(ST[l][lg[r-l+1]],ST[r-(1<<lg[r-l+1])+1][lg[r-l+1]])<=r)?1:0);
	return 0;
}


#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////

const int N = 2e5+10;

int ts[N], te[N], lcat = 0;
vector<int> g[N], ba[N];

void lcadfs(int s, int p = 0, int d = 0) {
	ts[s] = lcat++;
	ba[s].push_back(p);
	for(int i = 1; d - (1 << i) >= 0; ++i)
		ba[s].push_back(ba[ba[s][i-1]][i-1]);

	for(int v : g[s])
		if(v != p)
			lcadfs(v, s, d+1);
	te[s] = lcat++;
}

int n, m, q, p[N], a[N], ear[N], leaf[N], b[N];
set<pii> segs;
stack<int> lastids[N];

int jump_forward(int k) {
	int num = n-1;
	FOR(i, 0, 20) {
		if((1 << i) & num) {
			if(i < ba[k].size()) k = ba[k][i];
			else return 0;
		}
	}
	return k;
}

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    cin >> n >> m >> q;
    FOR(i, 1, n) cin >> p[i];
    b[p[1]] = p[n];
    FOR(i, 2, n) b[p[i]] = p[i-1];
    FOR(i, 1, m) cin >> a[i];

    FOR(i, 1, m) {
    	int bef = b[a[i]];
    	stack<int>& s = lastids[bef];
    	while(!s.empty()) {
    		g[i].push_back(s.top());
    		leaf[s.top()] = 1;
    		s.pop();
    	}
    	lastids[a[i]].push(i);
    }
    FOR(i, 1, m) if(!leaf[i]) lcadfs(i);
    FOR(i, 1, m) ear[i] = jump_forward(i);

    FOR(i, 1, m) {
    	if(ear[i]) {
	    	while(segs.size() && segs.rbegin()->second >= ear[i]) segs.erase(*segs.rbegin());
	    	segs.insert({i, ear[i]});
    	}
    }

    while(q--) {
    	int l, r;
    	cin >> l >> r;
    	auto itr = segs.lower_bound({l, 0});
    	cout << !(itr == segs.end() || itr->second > r);
    }
    cout << endl;

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting max to 0 instead of -INF/min to 0 instead of INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)
// - round announcements (WA)
// - multiset::erase (WA)


#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////

const int N = 2e5+10;
int n, m, q, p[N], a[N], last[N], forw[N], vis[N], ear[N];
map<int, int> conv;
set<pii> segs;

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    cin >> n >> m >> q;
    FOR(i, 1, n) {
    	cin >> p[i];
    	conv[p[i]] = i;
    }
    FOR(i, 1, m) {
    	cin >> a[i];
    	a[i] = conv[a[i]];
    }

    // FOR(i, 1, m) cout << a[i] << ' ';
    // cout << endl;

    FOR(i, 1, m) {
    	int bef = (((a[i]-1)+n-1) % n) + 1;
    	if(last[bef] && !forw[last[bef]]) forw[last[bef]] = i;
    	last[a[i]] = i;
    }

    // FOR(i, 1, m) cout << forw[i] << ' ';
    // cout << endl;

    FOR(i, 1, m) {
    	if(!vis[i]) {
    		bool good = true;
    		int id = i, bid = i;
			vis[i] = 1;
    		REP(j, n-1) {
    			id = forw[id];
    			vis[id] = 1;
    			if(id == 0) {
    				good = false;
    				break;
    			}
    		}
    		if(!good) continue;
    		while(!ear[bid] && id) {
    			ear[bid] = id;
    			id = forw[id];
    		}
    	}
    }

    // FOR(i, 1, m) cout << ear[i] << ' ';
    // cout << endl;

    FOR(i, 1, m) {
    	if(ear[i]) {
	    	while(segs.size() && segs.rbegin()->second >= ear[i]) {
	    		segs.erase(*segs.rbegin());
	    	}
	    	segs.insert({i, ear[i]});
    	}
    }

    // for(auto& p : segs) cout << p.first << ' ' << p.second << endl;
    // cout << endl;

    while(q--) {
    	int l, r;
    	cin >> l >> r;
    	auto itr = segs.lower_bound({l, 0});
    	if(itr == segs.end() || itr->second > r) cout << 0;
    	else cout << 1;
    }
    cout << endl;

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting max to 0 instead of -INF/min to 0 instead of INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)
// - round announcements (WA)
// - multiset::erase (WA)


#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////

const int N = 2e5+10;
int n, m, q, p[N], a[N], last[N], forw[N], vis[N], ear[N];
map<int, int> conv;
set<pii> segs;

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    cin >> n >> m >> q;
    FOR(i, 1, n) {
    	cin >> p[i];
    	conv[p[i]] = i;
    }
    FOR(i, 1, m) {
    	cin >> a[i];
    	a[i] = conv[a[i]];
    }

    // FOR(i, 1, m) cout << a[i] << ' ';
    // cout << endl;

    FOR(i, 1, m) {
    	int bef = (((a[i]-1)+n-1) % n) + 1;
    	if(last[bef] && !forw[last[bef]]) forw[last[bef]] = i;
    	last[a[i]] = i;
    }

    // FOR(i, 1, m) cout << forw[i] << ' ';
    // cout << endl;

    FOR(i, 1, m) {
    	if(!vis[i]) {
    		bool good = true;
    		// DEBUG(i);
    		int id = i, bid = i;
			vis[i] = 1;
    		REP(j, n-1) {
    			id = forw[id];
    			vis[id] = 1;
    			if(id == 0) {
    				good = false;
    				break;
    			}
    			// if(j == n-2) DEBUG(j);
    		}
    		if(!good) continue;
    		while(!ear[bid] && id) {
    			ear[bid] = id;
    			id = forw[id];
    			bid = forw[bid];
    		}
    	}
    }

    // FOR(i, 1, m) cout << ear[i] << ' ';
    // cout << endl;

    FOR(i, 1, m) {
    	if(ear[i]) {
	    	while(segs.size() && segs.rbegin()->second >= ear[i]) {
	    		segs.erase(*segs.rbegin());
	    	}
	    	segs.insert({i, ear[i]});
    	}
    }

    // for(auto& p : segs) cout << p.first << ' ' << p.second << endl;
    // cout << endl;

    while(q--) {
    	int l, r;
    	cin >> l >> r;
    	auto itr = segs.lower_bound({l, 0});
    	if(itr == segs.end() || itr->second > r) cout << 0;
    	else cout << 1;
    }
    cout << endl;

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting max to 0 instead of -INF/min to 0 instead of INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)
// - round announcements (WA)
// - multiset::erase (WA)


#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <functional>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
using namespace std;
// #define int long long
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = (((1<<30)-1)<<1)+1;
const int nINF = 1<<31;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, int> pci;

/////////////////////////////////////////////////////////////////////

const int N = 2e5+10;

int ts[N], te[N], lcat = 0;
vector<int> g[N], ba[N];

void lcadfs(int s, int p = 0, int d = 0) {
	ts[s] = lcat++;
	ba[s].push_back(p);
	for(int i = 1; d - (1 << i) >= 0; ++i)
		ba[s].push_back(ba[ba[s][i-1]][i-1]);

	for(int v : g[s])
		if(v != p)
			lcadfs(v, s, d+1);
	te[s] = lcat++;
}

int n, m, q, p[N], a[N], last[N], forw[N], vis[N], ear[N], d[N];
map<int, int> conv;
set<pii> segs;
stack<int> lastids[N];

int jump_forward(int k) {
	int num = n-1;
	FOR(i, 0, 20) {
		if((1 << i) & num) {
			if(i < ba[k].size()) k = ba[k][i];
			else return 0;
		}
	}
	return k;
}

signed main() {
    ios::sync_with_stdio(false);
    //cout << fixed << setprecision(7);
    cin >> n >> m >> q;
    FOR(i, 1, n) {
    	cin >> p[i];
    	conv[p[i]] = i;
    }
    FOR(i, 1, m) {
    	cin >> a[i];
    	a[i] = conv[a[i]];
    }

    // FOR(i, 1, m) cout << a[i] << ' ';
    // cout << endl;

    FOR(i, 1, m) {
    	int bef = (((a[i]-1)+n-1) % n) + 1;
    	stack<int>& s = lastids[bef];
    	while(!s.empty()) {
    		forw[s.top()] = i;
    		g[i].push_back(s.top());
    		++d[s.top()];
    		s.pop();
    	}
    	lastids[a[i]].push(i);
    }

    FOR(i, 1, m) if(d[i] == 0) lcadfs(i);

    // FOR(i, 1, m) cout << forw[i] << ' ';
    // cout << endl;

    FOR(i, 1, m) {
		ear[i] = jump_forward(i);
    }

    // FOR(i, 1, m) cout << ear[i] << ' ';
    // cout << endl;

    FOR(i, 1, m) {
    	if(ear[i]) {
	    	while(segs.size() && segs.rbegin()->second >= ear[i]) {
	    		segs.erase(*segs.rbegin());
	    	}
	    	segs.insert({i, ear[i]});
    	}
    }

    // for(auto& p : segs) cout << p.first << ' ' << p.second << endl;
    // cout << endl;

    while(q--) {
    	int l, r;
    	cin >> l >> r;
    	auto itr = segs.lower_bound({l, 0});
    	if(itr == segs.end() || itr->second > r) cout << 0;
    	else cout << 1;
    }
    cout << endl;

    return 0;
}

// Easy things to check:
// - LONG LONGS (WA)
// - const int N is correct (WA, RTE)
// - .size()-k underflow (WA, RTE, TLE)
// - small n edge cases (WA)

// Rare mistakes made in the past:
// - division by 0 (WA)
// - integer division (WA)
// - setprecision (WA)
// - INF not big enough using ll (WA)
// - setting max to 0 instead of -INF/min to 0 instead of INF (WA)
// - outputting debug (WA)
// - allocating too much memory (locRTE, MLE)
// - stack size (locRTE)
// - round announcements (WA)
// - multiset::erase (WA)


File Edit Options Buffers Tools C++ Help
{
  int n,m,q,now,x,y;
  scanf("%d%d%d",&n,&m,&q);
  for (int i=1;i<=n;++i)
    scanf("%d",&p[i]);
  p[n+1]=p[1];
  for (int i=1;i<=m;++i)
    scanf("%d",&a[i]);
  for (int i=m;i>=1;--i)
  {
    list[a[i]]=i;
    fast[i][0]=list[p[a[i]]+1];
  }
  for (int i=1;i<=log(m)/log(2);++i)
    for (int j=1;j<=m;++j)
      fast[j][i]=fast[fast[j][i-1]][i-1];
  for (int i=1;i<=m;++i)
  {
    now=i;
    for (int j=log(m)/log(2);j>=0;--j)
      if (((n-1)&j)==1)
        now=fast[now][j];
    RMQ[i][0]=now;
  }
  for (int i=1;i<=log(m)/log(2);++i)
    for (int j=1;j<=m;++j)
      RMQ[j][i]=max(RMQ[j][i-1],RMQ[j+(1<<(i-1))][i-1]);
  while (q--)
  {
    scanf("%d%d",&x,&y);
    if (rmq(x,y)<y-x)
      puts("0");
    else
      puts("1");

  }
  return 0;
}


#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
int p[100001],a[100001],list[100001],fast[100001][31],RMQ[100001][31];
long long rmq(int l,int r)
{
  int lowbit=log(r-l+1)/log(2);
  return max(RMQ[l][lowbit],RMQ[r-(1<<lowbit)+1][lowbit]);
}
int main()
{
  int n,m,q,now,x,y;
  scanf("%d%d%d",&n,&m,&q);
  for (int i=1;i<=n;++i)
    scanf("%d",&p[i]);
  p[n+1]=p[1];
  for (int i=1;i<=m;++i)
    scanf("%d",&a[i]);
  for (int i=m;i>=1;--i)
  {
    list[a[i]]=i;
    fast[i][0]=list[p[a[i]]+1];
  }
  for (int i=1;i<=log(m)/log(2);++i)
    for (int j=1;j<=m;++j)
      fast[j][i]=fast[fast[j][i-1]][i-1];
  for (int i=1;i<=m;++i)
  {
    now=i;
    for (int j=log(m)/log(2);j>=0;--j)
      if (((n-1)&j)==1)
	now=fast[now][j];
    RMQ[i][0]=now;
  }
  for (int i=1;i<=log(m)/log(2);++i)
    for (int j=1;j<=m;++j)
      RMQ[j][i]=max(RMQ[j][i-1],RMQ[j+(1<<(i-1))][i-1]);
  while (q--)
  {
    scanf("%d%d",&x,&y);
    if (rmq(x,y)<y-x)
      puts("0");
    else
      puts("1");

  }
  return 0;
}


#include<cstdio>
#include<set>
using namespace std;

set <int> s1[200050];
int nxt[200050], fa[200050], ed[200050], a[200050], b[200050];

int getend(int w, int n){
	while(n) w = fa[w], n--;
	return w;
}

int test(int l, int r){
	for(int i = l; i <= r; i++) if(ed[i] >= l && ed[i] <= r) return 1;
	return 0;
}

int main(){
	int n, m, q;
	scanf("%d %d %d", &n, &m, &q);
	for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for(int i = 1; i < n; i++) nxt[a[i]] = a[i+1];
	nxt[a[n]] = a[1];
	for(int i = 1; i <= m; i++) {
		scanf("%d", &b[i]);
		s1[b[i]].insert(i);
	}
	for(int i = 1; i <= m; i++) {
		int k = *s1[nxt[b[i]]].upper_bound(i);
		if(k > i && k <= m) fa[i] = k;
	}
	for(int i = 1; i <= m; i++) ed[i] = getend(i, n-1);
	for(int i = 1; i <= q; i++){
		int x, y;
		scanf("%d %d", &x, &y);
		printf("%d", test(x, y));
	}
}


#include <iostream>
#include <cstdio>
#include <cstring>
#define il inline
#define ri register
#define Size 200050
using namespace std;
int p[Size],q[Size],b[Size],
	go[Size][18],dp[Size][18];
il void read(int&);
il int query(int,int),query1(int,int),
	flog2(float);
int main(){
	int n,m,qq;read(n),read(m),read(qq);
	for(int i(1);i<=n;++i)read(p[i]),q[p[i]]=i;
	for(int i(1),x;i<=m;++i){read(x),b[x]=i;
		go[i][0]=b[p[(q[x]-2+n)%n+1]];
	}for(int i,j(1);j<18;++j)
		 for(i=1;i<=m;++i)go[i][j]=go[go[i][j-1]][j-1];
	for(int i(1);i<=m;++i)dp[i][0]=query(i,n-1);
	for(int i,j(1);j<18;++j)
		for(i=1;i+(1<<j)-1<=m;++i)
			dp[i][j]=max(dp[i][j-1],dp[i+(1<<j-1)][j-1]);
	for(int i(1),l,r;i<=qq;++i)
		read(l),read(r),putchar(query1(l,r)>=l?49:48);
	return 0;
}
il int flog2(float x){
	return ((unsigned&)x>>23)-127;
}
il int query1(int l,int r){int len(flog2(r-l+1));
	return max(dp[l][len],dp[r-(1<<len)+1][len]);
}
il int query(int p,int n){
	for(int i(17);~i;--i)
		if(n>>i&1)p=go[p][i];
	return p;
}
il void read(int&x){
	x^=x;ri char c;while(c=getchar(),c<'0'||c>'9');
	while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
}


#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
int p[100001],a[100001],list[100001],fast[100001][31],RMQ[100001][31],p2[100001];
long long rmq(int l,int r)
{
  int lowbit=log(r-l+1)/log(2);
  return min(RMQ[l][lowbit],RMQ[r-(1<<lowbit)+1][lowbit]);
}
int main()
{
  int n,m,q,now,x,y;
  scanf("%d%d%d",&n,&m,&q);
  for (int i=1;i<=n;++i)
  {
    scanf("%d",&p[i]);
    p2[p[i]]=i;
	}
  for (int i=1;i<=m;++i)
    scanf("%d",&a[i]);
  p[n+1]=p[1];
  for (int i=m;i>=1;--i)
  {
    list[a[i]]=i;
    fast[i][0]=list[p[p2[a[i]]+1]];
  }
  for (int i=1;i<=log(m)/log(2);++i)
    for (int j=1;j<=m;++j)
      fast[j][i]=fast[fast[j][i-1]][i-1];
  for (int i=1;i<=m;++i)
  {
    now=i;
    for (int j=log(m)/log(2);j>=0;--j)
   		if ((n-1)&(1<<j))
			now=fast[now][j];
    RMQ[i][0]=now;
    if (now==0)
    	RMQ[i][0]=1e9;
  }
  for (int i=1;i<=log(m)/log(2);++i)
    for (int j=1;j<=m;++j)
      RMQ[j][i]=min(RMQ[j][i-1],RMQ[j+(1<<(i-1))][i-1]);
  while (q--)
  {
    scanf("%d%d",&x,&y);
    if (rmq(x,y)>y)
    	printf("0");
    else
    	printf("1");
  }
  return 0;
}


#include<bits/stdc++.h>
#define il inline
#define Ri register int
#define go(i,a,b) for(Ri i=a;i<=b;++i)
#define yes(i,a,b) for(Ri i=a;i>=b;--i)
#define e(i,u) for(Ri i=b[u];i;i=a[i].nt)
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define db double
#define inf 2147483647
using namespace std;
il int read()
{
    Ri x=0,y=1;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')y=-1;c=getchar();}
    while(c>='0'&&c<='9'){x=(x<<1)+(x<<3)+c-'0';c=getchar();}
    return x*y;
}
const int N=200005;
int n,m,q,f[N][18],g[N][18],as[N],mi[N][18],nxt[N],a[N];
vector<int>b[N];
int main()
{
    n=read(),m=read(),q=read();
    Ri fi,lst,cur;fi=lst=read();
    go(i,2,n){cur=read();nxt[lst]=cur;lst=cur;}
    nxt[cur]=fi;
    go(i,1,m)
    {
	a[i]=read();
	go(j,0,(int)b[a[i]].size()-1){f[b[a[i]][j]][0]=i;}
	b[a[i]].clear();b[nxt[a[i]]].push_back(i);
    }
    yes(i,m,1)
	go(j,1,17)
        {
	    f[i][j]=f[f[i][j-1]][j-1];
	    if(!f[i][j])f[i][j]=m+1;
	}
    yes(i,m,1)
    {
	g[i][0]=i+1;
	go(j,1,17)g[i][j]=g[g[i][j-1]][j-1];
    }
    go(i,1,m)
    {
	as[i]=i;
	go(j,0,17)if((n-1)>>j&1)as[i]=f[as[i]][j];
	if(!as[i])as[i]=m+1;
    }as[m+1]=m+1;
    go(i,1,m)mi[i][0]=min(as[i],as[i+1]);
    yes(i,m,1)
	go(j,1,17)
        {
	    if(!mi[i][j-1] && !mi[g[i][j-1]][j-1])mi[i][j]=m+1;
	    else if(!mi[i][j-1])mi[i][j]=mi[g[i][j-1]][j-1];
	    else if(!mi[g[i][j-1]][j-1])mi[i][j]=mi[i][j-1];
	    else mi[i][j]=min(mi[i][j-1],mi[g[i][j-1]][j-1]);
	}
    while(q--)
    {
	Ri l=read(),r=read(),minx=as[l];
	yes(i,17,0)if(g[l][i]<=r)minx=min(minx,mi[l][i]?mi[l][i]:m+1),l=g[l][i];
	if(minx>r)printf("0");
	else printf("1");
    }
    return 0;
}


// -*- coding: utf-8 -*-
// @Date    : 2019-04-28 16:55:39

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& v)
{
	for(auto i : v)
		os << i << " ";
	return os;
}

template<typename T>
ostream& operator << (ostream& os, const set<T>& v)
{
	for(auto i : v)
		os << i << " ";
	return os;
}

const int N = 2e5 + 233;
int dp[N][20], lst[N], nxt[N], ans[N], a[N], b[N];

// #define local
int main()
{
#ifdef local
	freopen("data.in", "r", stdin);
	freopen("ans.out", "w", stdout);
#endif
	int n, m, t;
	scanf("%d%d%d", &n, &m, &t);
	for(int i = 1; i <= n; ++i)
		scanf("%d", a+i);
	for(int i = 1; i <= n; ++i)
	{
		nxt[a[i-1]] = a[i];
		lst[i] = m+1;
	}
	nxt[a[n]] = a[1];
	for(int i = 1; i <= m; ++i)
		scanf("%d", b+i);
	for(int i = 0; i < 20; ++i)
		dp[m+1][i] = m+1;
	ans[m+1] = m+1;

	for(int i = m; i; --i)
	{
		dp[i][0] = lst[nxt[b[i]]];
		lst[b[i]] = i;
		for(int j = 1; j < 20; ++j)
			dp[i][j] = dp[dp[i][j-1]][j-1];
		int cnt = n-1;
		int p = i;
		for(int j = 19; j+1; --j)
			if(cnt >= (1<<j))
			{
				cnt -= (1<<j);
				p = dp[p][j];
			}
		ans[i] = min(ans[i+1], p);
	}
	while(t--)
	{
		int l, r;
		scanf("%d%d", &l, &r);
		if(ans[l] <= r)
			printf("1");
		else
			printf("0");
	}
	return 0;
}


#include<cstdio>
#include<cmath>
#include<iostream>
using namespace std;
int p[800001],a[800001],list[800001],fast[800001][31],RMQ[800001][31],p2[800001];
long long rmq(int l,int r)
{
  int lowbit=log(r-l+1)/log(2);
  return min(RMQ[l][lowbit],RMQ[r-(1<<lowbit)+1][lowbit]);
}
int main()
{
  int n,m,q,now,x,y;
  scanf("%d%d%d",&n,&m,&q);
  for (int i=1;i<=n;++i)
  {
    scanf("%d",&p[i]);
    p2[p[i]]=i;
	}
  for (int i=1;i<=m;++i)
    scanf("%d",&a[i]);
  p[n+1]=p[1];
  for (int i=m;i>=1;--i)
  {
    list[a[i]]=i;
    fast[i][0]=list[p[p2[a[i]]+1]];
  }
  for (int i=1;i<=log(m)/log(2);++i)
    for (int j=1;j<=m;++j)
      fast[j][i]=fast[fast[j][i-1]][i-1];
  for (int i=1;i<=m;++i)
  {
    now=i;
    for (int j=log(m)/log(2);j>=0;--j)
   		if ((n-1)&(1<<j))
			now=fast[now][j];
    RMQ[i][0]=now;
    if (now==0)
    	RMQ[i][0]=1e9;
  }
  for (int i=1;i<=log(m)/log(2);++i)
    for (int j=1;j<=m;++j)
      RMQ[j][i]=min(RMQ[j][i-1],RMQ[j+(1<<(i-1))][i-1]);
  while (q--)
  {
    scanf("%d%d",&x,&y);
    if (rmq(x,y)>y)
    	printf("0");
    else
    	printf("1");
  }
  return 0;
}


#include <cstdio>
#include <iostream>
#include <cstring>
#include <cmath>
#include <queue>
#include <utility>
#include <algorithm>
#include <vector>
#define rg register
#define il inline
#define ll long long
using namespace std;
inline int read(){
	rg char c=getchar();
	rg int x=0,f=1;
	while(c<'0'||c>'9'){
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+(c^48);
		c=getchar();
	}
	return x*f;
}

const int Inf=0x3f3f3f3f;
const int N=2e5+5;
struct Edge{
	int to,nxt;
}edge[N];
int cnt,head[N];
int n,m,q,l,r;
int p[N],a[N];
int dep[N],anc[N];
int pre[N],lst[N];
int s[N],val[N],k[N];

il void add_edge(int u,int v){
	edge[++cnt].to=v;
	edge[cnt].nxt=head[u];
	head[u]=cnt;
}
il void dfs(int u){
    anc[dep[u]]=u;
	if(dep[u]>=n)
		val[u]=anc[dep[u]-n+1];
	else
		val[u]=m+1;
    for(rg int i=head[u];i;i=edge[i].nxt){
    	int v=edge[i].to;
        dep[v]=dep[u]+1;
        dfs(v);
    }
}

int main(){
	n=read();
	m=read();
	q=read();
	for(rg int i(1);i<=n;++i){
		p[i]=read();
		k[p[i]]=p[i-1];
	}
	k[p[1]]=p[n];
	for(rg int i(1);i<=m;++i){
		a[i]=read();
		pre[i]=lst[a[i]];
		lst[a[i]]=i;
        for(rg int j(lst[k[a[i]]]);j&&(s[j]==0);j=pre[j])
			s[j]=i;
	}
	for(rg int i(1);i<=m;++i)
		if(!s[i])
			s[i]=m+1;
	for(rg int i(1);i<=m;++i){
		add_edge(s[i],i);
		dfs(m+1);
	}
	for(rg int i(m-1);i;--i)
		val[i]=min(val[i],val[i+1]);
	while(q--){
		l=read();
		r=read();
		printf("%d\n",(val[l]<=r));
	}
	return 0;
}


#include<bits/stdc++.h>
#define IL inline
#define _ 200005
#define ll long long
using namespace std ;

IL int gi(){
	int data=0,fu=1; char ch=0;
	while(ch!='-'&&(ch<'0'||ch>'9'))ch=getchar(); if(ch=='-')fu=-1,ch=getchar();
	while('0'<=ch&&ch<='9')data=(data<<1)+(data<<3)+(ch^48),ch=getchar();return data*fu;
}

#define inf 1000000007
int n,m,Q,P[_],Pos[_],A[_],pos[_],f[_][22],mn[_<<2];
IL void PushUp(int o){mn[o]=min(mn[o<<1],mn[o<<1|1]); return; }
void Build(int o,int l,int r){
	if(l==r)return mn[o]=inf,void(); int mid=(l+r)>>1;
	Build(o<<1,l,mid);Build(o<<1|1,mid+1,r); PushUp(o);
}
void Insert(int o,int l,int r,int ps,int v){
	if(l==r)return mn[o]=min(mn[o],v),void();
	int mid=(l+r)>>1;
	ps<=mid?Insert(o<<1,l,mid,ps,v):Insert(o<<1|1,mid+1,r,ps,v);
	PushUp(o);
}
int Query(int o,int l,int r,int ql,int qr){
	if(ql<=l&&r<=qr)return mn[o]; int mid=(l+r)>>1,ret=inf;
	if(ql<=mid)ret=min(ret,Query(o<<1,l,mid,ql,qr));
	if(qr >mid)ret=min(ret,Query(o<<1|1,mid+1,r,ql,qr)); return ret;
}
int main(){
	n=gi(); m=gi(); Q=gi();
	for(int i=1;i<=n;++i)P[i]=gi();P[n+1]=P[1];
	for(int i=1;i<=n;++i)Pos[P[i]]=i,pos[i]=inf;
	for(int i=1;i<=m;++i)A[i]=gi();
	Build(1,1,m);
	for(int i=0;i<=m;++i)for(int e=0;e<=18;++e)f[i][e]=inf;
	for(int i=m;i>=1;--i){
		f[i][0]=pos[P[Pos[A[i]]+1]];
		for(int e=1;e<=18;++e)if(f[i][e-1]!=inf)f[i][e]=f[f[i][e-1]][e-1]; pos[A[i]]=i;
		int p=i;
		for(int e=18;e>=0&&p<=m;--e)if((n-1)&(1<<e))p=f[p][e];
		Insert(1,1,m,i,p);
	}
	while(Q--){
		int l=gi(),r=gi();
		putchar(Query(1,1,m,l,r)<=r?'1':'0');
	}
	puts(""); return 0;
}