#include <bits/stdc++.h>
using namespace std;
int line[250001];
int Tree[1000001];
int N, K, M;
int l, r, x;
int segment(int root, int left, int right) {
  if (left == right) {
    if (line[left] == K) {
      Tree[root] = 1;
    } else {
      Tree[root] = 0;
    }
  } else {
    int mid = (left + right) / 2;
    Tree[root] =
        segment(root * 2, left, mid) + segment(root * 2 + 1, mid + 1, right);
  }
  return Tree[root];
}
int find(int start, int end, int root, int left, int right) {
  if (start <= left && right <= end) {
    return Tree[root];
  }
  if (start > right || end < left) {
    return 0;
  }
  int mid = (left + right) / 2;
  return find(start, end, root * 2, left, mid) +
         find(start, end, root * 2 + 1, mid + 1, right);
}
int reseg(int start, int end, int root, int left, int right) {
  if (start > right || end < left) {
    return 0;
  }
  if (left == right) {
    if (line[left] == K) {
      Tree[root] = 1;
    } else {
      Tree[root] = 0;
    }
    return Tree[root];
  }
  int mid = (left + right) / 2;
  Tree[root] = reseg(start, end, root * 2, left, mid) +
               reseg(start, end, root * 2 + 1, mid + 1, right);
  return Tree[root];
}
int main() {
  scanf("%d %d", &N, &K);
  for (int i = 1; i <= N; i++) {
    scanf("%d", &line[i]);
  }
  segment(1, 1, N);
  scanf("%d", &M);
  for (int i = 0; i < M; i++) {
    int choice;
    scanf("%d", &choice);
    if (choice == 1) {
      scanf("%d %d %d", &l, &r, &x);
      for (int k = l; k <= r; k++) {
        line[k] = line[k] | x;
      }
      reseg(l, r, 1, 1, N);
    } else {
      scanf("%d %d", &l, &r);
      int result = find(l, r, 1, 1, N);
      printf("%d\n", result);
    }
  }
  return 0;
}
