#define _USE_MATH_DEFINES #include <cassert> #include <cstdio> #include <cstring> #include <iostream> #include <string> #include <sstream> #include <vector> #include <queue> #include <stack> #include <list> #include <set> #include <map> #include <unordered_set> #include <unordered_map> #include <algorithm> #include <complex> #include <cmath> #include <numeric> #include <bitset> #include <functional> using namespace std; #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__) template <typename Arg1> void __f(const char* name, Arg1&& arg1){ cerr << name << ": " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args){ const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << ": " << arg1 << " |"; __f(comma + 1, args...); } typedef long long int64; typedef pair<int, int> ii; const int INF = 1 << 29; const int MOD = 1e9 + 7; const int N = 1e5 + 10; const int K = 20; int v[N], w[N]; struct Node { int a, b; Node *left, *right; int cnt[K], c; void update(int C) { for (int k = 0; k < K; ++k) { if (C & (1 << k)) { cnt[k] = b - a - cnt[k]; } } c ^= C; } void pushup() { for (int k = 0; k < K; ++k) { cnt[k] = left->cnt[k] + right->cnt[k]; } } void pushdown() { if (c) { left->update(c); right->update(c); c = 0; } } }; Node pool[N << 1], *last; Node* build(int a, int b) { Node* cur = last++; cur->a = a; cur->b = b; if (a + 1 == b) { for (int k = 0; k < K; ++k) { if (w[a] & (1 << k)) { cur->cnt[k] = 1; } else { cur->cnt[k] = 0; } } cur->c = 0; return cur; } cur->left = build(a, (a + b) / 2); cur->right = build((a + b) / 2, b); cur->pushup(); return cur; } void insert(Node* cur, int A, int B, int C) { if (A >= B) return; if (cur->a >= A && cur->b <= B) { cur->update(C); return; } cur->pushdown(); if ((cur->a + cur->b) / 2 > A) insert(cur->left, A, B, C); if ((cur->a + cur->b) / 2 < B) insert(cur->right, A, B, C); cur->pushup(); } int64 query(Node* cur, int A, int B) { if (A >= B) return 0; if (cur->a >= A && cur->b <= B) { int64 ret = 0; for (int k = 0; k < K; ++k) { ret += (int64)cur->cnt[k] * (1 << k); } return ret; } cur->pushdown(); int64 ret = 0; if ((cur->a + cur->b) / 2 > A) ret += query(cur->left, A, B); if ((cur->a + cur->b) / 2 < B) ret += query(cur->right, A, B); return ret; } int main() { int n, m, p; scanf("%d%d%d", &n, &m, &p); for (int i = 0; i < n; ++i) scanf("%d", &v[i]); int sum = 0; for (int i = 0; i < p; ++i) { sum ^= v[i]; } w[0] = sum; for (int i = p; i < n; ++i) { sum ^= v[i - p] ^ v[i]; w[i - p + 1] = sum; } last = pool; n = n - p + 1; Node* root = build(0, n); while (m--) { int t; scanf("%d", &t); if (t == 1) { int i, x; scanf("%d%d", &i, &x); --i; int L = max(i - p + 1, 0), R = min(i + 1, n); insert(root, L, R, x); } else { // for (int i = 0; i < n; ++i) { // int64 ret = query(root, i, i + 1); // trace(i, ret); // } int L, R; scanf("%d%d", &L, &R); --L; R = min(R, n); // trace(L, R); int64 ret = query(root, L, R); printf("%lld\n", ret); } } return 0; }