結果
| 問題 |
No.879 Range Mod 2 Query
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-11-14 14:54:17 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,611 bytes |
| コンパイル時間 | 3,613 ms |
| コンパイル使用メモリ | 257,004 KB |
| 実行使用メモリ | 13,780 KB |
| 最終ジャッジ日時 | 2024-11-14 14:54:25 |
| 合計ジャッジ時間 | 7,100 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 3 WA * 18 |
ソースコード
#ifndef LOCAL
#include <bits/stdc++.h>
using namespace std;
#define debug(...) (void(0))
#else
#include "algo/debug.h"
#endif
#include <atcoder/lazysegtree>
using ll = long long;
struct S {
int odd, even;
ll sum, size;
};
S op(S a, S b) {
return S{
a.odd + b.odd,
a.even + b.even,
a.sum + b.sum,
a.size + b.size};
}
S e() {
return S{0, 0, 0, 0};
}
struct F {
ll val;
bool type1;
};
F id() {
return F{0, 0};
}
S mapping(F f, S x) {
if(f.type1) {
x.sum = x.odd;
}
if(f.val % 2 == 0) {
x.sum += f.val * x.size;
}else {
swap(x.even, x.odd);
x.sum += f.val * x.size;
}
return x;
}
F composition(F f, F g) {
if(f.type1) {
g.val = 0;
g.type1 = 1;
}else {
g.val += f.val;
}
return g;
}
void solve() {
int N, Q; cin >> N >> Q;
vector<S> A(N);
for(int i = 0; i < N; i++) {
int a; cin >> a;
A[i] = S{a & 1, (a + 1) & 1, a, 1};
}
atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(A);
while(Q--) {
int t; cin >> t;
int l, r; cin >> l >> r;
if(t == 1) {
l--;
seg.apply(l, r, F{0, 1});
}else if(t == 2) {
l--;
int x; cin >> x;
seg.apply(l, r, F{x, 0});
}else {
l--;
cout << seg.prod(l, r).sum << endl;
}
}
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int tt = 1;
// std::cin >> tt;
while (tt--) {
solve();
}
}