#include <bits/stdc++.h>
using namespace std;
int h[200005];
const int MAX = 10000;
int block;
struct Query {
  int L, R, index, result;
  int tot;
};
bool compare(Query x, Query y) {
  if (x.L / block != y.L / block) return x.L / block < y.L / block;
  return x.R < y.R;
}
bool compare1(Query x, Query y) { return x.index < y.index; }
void queryResults(int a[], int n, Query q[], int m) {
  block = (int)sqrt(n);
  set<int> s;
  sort(q, q + m, compare);
  int currL = 0, currR = 0;
  int curr_Diff_elements = 0;
  int freq[MAX] = {0};
  int sum = 0;
  for (int i = 0; i < m; i++) {
    int L = q[i].L, R = q[i].R;
    while (currL < L) {
      freq[a[currL]]--;
      if (freq[a[currL]] == 0) {
        curr_Diff_elements--;
        sum -= h[a[currL]];
      }
      currL++;
    }
    while (currL > L) {
      freq[a[currL - 1]]++;
      if (freq[a[currL - 1]] == 1) {
        curr_Diff_elements++;
        sum += h[a[currL]];
      }
      currL--;
    }
    while (currR <= R) {
      freq[a[currR]]++;
      if (freq[a[currR]] == 1) {
        curr_Diff_elements++;
        sum += h[a[currR]];
      }
      currR++;
    }
    while (currR > R + 1) {
      freq[a[currR - 1]]--;
      if (freq[a[currR - 1]] == 0) {
        curr_Diff_elements--;
        sum -= h[a[currR - 1]];
      }
      currR--;
    }
    q[i].result = curr_Diff_elements;
    q[i].tot = sum;
  }
}
void printResults(Query q[], int m) {
  sort(q, q + m, compare1);
  for (int i = 0; i < m; i++) {
    int sum = 0;
    if (q[i].tot == (q[i].R - q[i].L + 1)) {
      cout << 1 << "\n";
    } else {
      cout << 0 << "\n";
    }
  }
}
int main() {
  int n, m, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= k; i++) {
    cin >> h[i];
  }
  cin >> m;
  Query q[m];
  for (int i = 0; i < m; i++) {
    int l, r;
    cin >> l >> r;
    l--;
    r--;
    q[i].L = l;
    q[i].R = r;
    q[i].index = i;
    q[i].result = 0;
    q[i].tot = 0;
  }
  queryResults(a, n, q, m);
  printResults(q, m);
  return 0;
}
