#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const int MaxN = 1e5 + 10; const int MOD = 1e9 + 7; const int INF = 1e9; const int MaxLen = 31; struct SQRT3 { int n, K, a[MaxN], b[MaxN], c[MaxN]; inline void relax(int &a, int b) { if (a > b) { a = b; } } void build(int _a[], int _n) { n = _n; for (int i = 0; i < MaxN; ++i) { a[i] = b[i] = c[i] = INF; } K = max((int)powl(n, 1.0 / 3.0), 10); for (int i = 0; i < _n; ++i) { a[i] = _a[i]; b[i / K] = min(b[i / K], a[i]); c[i / K / K] = min(c[i / K / K], a[i]); } } void update(int position, int value) { relax(a[position], value); relax(b[position / K], value); relax(c[position / K / K], value); } int get(int leftBound, int rightBound) { int leftBound2 = leftBound / K, rightBound2 = rightBound / K; int leftBound3 = leftBound2 / K, rightBound3 = rightBound2 / K; int ans = INF; if (leftBound2 == rightBound2) { for (int i = leftBound; i <= rightBound; ++i) { relax(ans, a[i]); } } else if (leftBound3 == rightBound3) { for (int i = leftBound; i < leftBound2 * K + K; ++i) { relax(ans, a[i]); } for (int i = rightBound2 * K; i <= rightBound; ++i) { relax(ans, a[i]); } for (int i = leftBound2 + 1; i < rightBound2; ++i) { relax(ans, b[i]); } } else { for (int i = leftBound; i < leftBound2 * K + K; ++i) { relax(ans, a[i]); } for (int i = rightBound2 * K; i <= rightBound; ++i) { relax(ans, a[i]); } for (int i = leftBound2 + 1; i < leftBound3 * K + K; ++i) { relax(ans, b[i]); } for (int i = rightBound3 * K; i < rightBound2; ++i) { relax(ans, b[i]); } for (int i = leftBound3 + 1; i < rightBound3; ++i) { relax(ans, c[i]); } } return ans; } } mysqrt; int a[MaxN], n, q; int dsu[MaxLen][MaxN]; int f[MaxN]; int get(int who[], int v) { if (who[v] == v) { return v; } return who[v] = get(who, who[v]); } bool IS(int mask, int bit) { return (mask >> bit) & 1; } void update(int l, int r, int x) { for (int bit = 0; bit < MaxLen; ++bit) { if (!IS(x, bit)) { while (true) { int w = get(dsu[bit], l); if (w > r) { break; } a[w] ^= 1 << bit; mysqrt.update(w, a[w]); dsu[bit][w] = w + 1; } } } } int main() { // freopen("input04.txt", "r", stdin); // freopen("output04.txt", "w", stdout); scanf("%d%d", &n, &q); for (int i = 0; i < n; ++i) { scanf("%d", &a[i]); } for (int i = 0; i < MaxLen; ++i) { for (int j = n; j < MaxN; ++j) { dsu[i][j] = j; } } for (int i = n - 1; i >= 0; --i) { for (int j = 0; j < MaxLen; ++j) { if (IS(a[i], j)) { dsu[j][i] = i; } else { dsu[j][i] = i + 1; } } } mysqrt.build(a, n); for (int it = 0; it < q; ++it) { int type, l, r, x; scanf("%d%d%d", &type, &l, &r); l--; r--; if (type == 1) { scanf("%d", &x); update(l, r, x); // for (int i = l; i <= r; ++i) { // a[i] &= x; // } } else { printf("%d\n", mysqrt.get(l, r)); // printf("%d\n", *min_element(a + l, a + r + 1)); } } return 0; }