#include #include #include using namespace std; #pragma warning (disable: 4996) const int BACKET = 300; long long N, Q, A[1 << 18], T[1 << 18], L[1 << 18], R[1 << 18], X[1 << 18], ans[1 << 18]; long long S[1 << 18], Z1[1 << 18], Z2[1 << 18], ZADD[1 << 18], used[1 << 18]; void ranged(int l, int r) { vector C; for (int i = l; i < r; i++) { C.push_back(L[i]); C.push_back(R[i]); } sort(C.begin(), C.end()); C.erase(unique(C.begin(), C.end()), C.end()); for (int i = 0; i < C.size(); i++) { S[i] = 0; Z1[i] = 0; Z2[i] = 0; ZADD[i] = 0; used[i] = 0; } for (int i = 0; i < C.size() - 1; i++) { for (int j = C[i]; j < C[i + 1]; j++) { S[i] += A[j]; if (A[j] % 2 == 0) Z1[i]++; else Z2[i]++; } } for (int i = l; i < r; i++) { if (T[i] == 2) { int pos1 = lower_bound(C.begin(), C.end(), L[i]) - C.begin(); int pos2 = lower_bound(C.begin(), C.end(), R[i]) - C.begin(); for (int j = pos1; j < pos2; j++) { ZADD[j] += X[i]; } } if (T[i] == 1) { int pos1 = lower_bound(C.begin(), C.end(), L[i]) - C.begin(); int pos2 = lower_bound(C.begin(), C.end(), R[i]) - C.begin(); for (int j = pos1; j < pos2; j++) { if (used[j] == 0) { if (ZADD[j] % 2 == 0) used[j] = 1; else used[j] = 2; } if (used[j] == 1) { if (ZADD[j] % 2 == 0) used[j] = 1; else used[j] = 2; } if (used[j] == 2) { if (ZADD[j] % 2 == 0) used[j] = 2; else used[j] = 1; } if (ZADD[j] % 2 == 1) swap(Z1[j], Z2[j]); ZADD[j] = 0; } } if (T[i] == 3) { int pos1 = lower_bound(C.begin(), C.end(), L[i]) - C.begin(); int pos2 = lower_bound(C.begin(), C.end(), R[i]) - C.begin(); for (int j = pos1; j < pos2; j++) { if (used[j] == 0) ans[i] += S[j] + 1LL * (C[j + 1] - C[j]) * ZADD[j]; else ans[i] += Z2[j] + (C[j + 1] - C[j]) * ZADD[j]; } } } for (int i = 0; i < C.size() - 1; i++) { for (int j = C[i]; j < C[i + 1]; j++) { if (used[i] == 0) A[j] += ZADD[i]; if (used[i] == 1) { if (A[j] % 2 == 0) A[j] = 0LL + ZADD[i]; else A[j] = 1LL + ZADD[i]; } if (used[i] == 2) { if (A[j] % 2 == 0) A[j] = 1LL + ZADD[i]; else A[j] = 0LL + ZADD[i]; } } } } int main() { scanf("%lld%lld", &N, &Q); for (int i = 1; i <= N; i++) scanf("%lld", &A[i]); for (int i = 1; i <= Q; i++) { scanf("%lld%lld%lld", &T[i], &L[i], &R[i]); R[i]++; if (T[i] == 2) scanf("%lld", &X[i]); } for (int i = 1; i <= Q; i += BACKET) { int cl = i, cr = i + BACKET; cr = min(cr, (int)Q + 1); ranged(cl, cr); } for (int i = 1; i <= Q; i++) { if (T[i] == 3) printf("%lld\n", ans[i]); } return 0; }