結果
| 問題 | No.879 Range Mod 2 Query |
| コンテスト | |
| ユーザー |
risujiroh
|
| 提出日時 | 2019-09-06 22:53:46 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,268 bytes |
| 記録 | |
| コンパイル時間 | 1,769 ms |
| コンパイル使用メモリ | 175,052 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-24 22:17:00 |
| 合計ジャッジ時間 | 7,288 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 WA * 13 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
int main() {
cin.tie(nullptr); ios::sync_with_stdio(false);
int n, q; cin >> n >> q;
V<lint> a(n); for (auto&& e : a) cin >> e;
constexpr int B = 512;
V<lint> sum((n + B - 1) / B);
V<lint> oc((n + B - 1) / B);
V<lint> ec((n + B - 1) / B);
V<> b((n + B - 1) / B);
V<lint> laz((n + B - 1) / B);
auto push = [&](int k) -> void {
for (int i = k * B; i < min((k + 1) * B, n); ++i) {
if (b[k] == 1) a[i] &= 1;
if (b[k] == 2) a[i] = ~a[i] & 1;
a[i] += laz[k];
}
b[k] = laz[k] = 0;
};
auto build = [&](int k) -> void {
for (int i = k * B; i < min((k + 1) * B, n); ++i) {
sum[k] += a[i];
oc[k] += a[i] & 1;
ec[k] += ~a[i] & 1;
}
};
auto act = [&](int l, int r, lint x) -> void {
if (l % B) {
push(l / B);
while (l < r and l % B) {
if (x == -1) a[l] &= 1;
else a[l] += x;
++l;
}
build((l - 1) / B);
}
if (r % B) {
push(r / B);
while (l < r and r % B) {
--r;
if (x == -1) a[r] &= 1;
else a[r] += x;
}
build(r / B);
}
while (l < r) {
if (x == -1) {
sum[l / B] = oc[l / B];
b[l / B] = 1;
laz[l / B] = 0;
} else {
sum[l / B] += (oc[l / B] + ec[l / B]) * x;
if (x & 1) swap(oc[l / B], ec[l / B]);
}
l += B;
}
};
auto acc = [&](int l, int r) -> lint {
lint res = 0;
if (l % B) {
push(l / B);
while (l < r and l % B) {
res += a[l];
++l;
}
build((l - 1) / B);
}
if (r % B) {
push(r / B);
while (l < r and r % B) {
--r;
res += a[r];
}
build(r / B);
}
while (l < r) {
res += sum[l / B];
l += B;
}
return res;
};
for (int k = 0; k < (n + B - 1) / B; ++k) {
build(k);
}
while (q--) {
int tp; cin >> tp;
int l, r; cin >> l >> r, --l;
if (tp == 1) {
act(l, r, -1);
} else if (tp == 2) {
int x; cin >> x;
act(l, r, x);
} else {
cout << acc(l, r) << '\n';
}
}
}
risujiroh