結果
| 問題 |
No.879 Range Mod 2 Query
|
| コンテスト | |
| ユーザー |
kwm_t
|
| 提出日時 | 2023-05-04 00:40:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 136 ms / 3,000 ms |
| コード長 | 2,077 bytes |
| コンパイル時間 | 3,805 ms |
| コンパイル使用メモリ | 258,512 KB |
| 最終ジャッジ日時 | 2025-02-12 16:44:00 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 21 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
//using mint = modint1000000007;
//const int mod = 1000000007;
//using mint = modint998244353;
//const int mod = 998244353;
//const int INF = 1e9;
//const long long LINF = 1e18;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i,l,r)for(int i=(l);i<(r);++i)
#define rrep(i, n) for (int i = (n-1); i >= 0; --i)
#define rrep2(i,l,r)for(int i=(r-1);i>=(l);--i)
#define all(x) (x).begin(),(x).end()
#define allR(x) (x).rbegin(),(x).rend()
#define endl "\n"
#define P pair<int,int>
template<typename A, typename B> inline bool chmax(A & a, const B & b) { if (a < b) { a = b; return true; } return false; }
template<typename A, typename B> inline bool chmin(A & a, const B & b) { if (a > b) { a = b; return true; } return false; }
struct S {
int ev, od;
long long sum;
S() {}
S(int a, int b, long long c) :ev(a), od(b), sum(c) {}
};
struct F {
long long suml;
int flg;
long long sumr;
};
S op(S sl, S sr) { return S{ sl.ev + sr.ev, sl.od + sr.od ,sl.sum + sr.sum }; }
S e() { return S{ 0, 0, 0 }; }
S mapping(F f, S x) {
if (1 == f.suml % 2)swap(x.ev, x.od);
x = { x.ev,x.od,x.sum + f.suml *(x.ev + x.od) };
if (f.flg)x.sum = x.od;
if (1 == f.sumr % 2)swap(x.ev, x.od);
x = { x.ev,x.od,x.sum + f.sumr *(x.ev + x.od) };
return x;
}
F composition(F f, F g) {
if (0 == f.flg) {
g.sumr += f.suml + f.sumr;
return g;
}
else {
f.suml += g.suml + g.sumr;
return f;
}
}
F id() { return F{ 0, 0 }; }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q; cin >> n >> q;
vector<S>a(n);
rep(i, n) {
int a_; cin >> a_;
a[i] = { 1 - a_ % 2,a_ % 2,a_ };
}
lazy_segtree<S, op, e, F, mapping, composition, id> seg(a);
while (q--) {
int t; cin >> t;
if (1 == t) {
int l, r; cin >> l >> r;
l--;
seg.apply(l, r, { 0,1,0 });
}
else if (2 == t) {
int l, r, x; cin >> l >> r >> x;
l--;
seg.apply(l, r, { x,0,0 });
}
else {
int l, r; cin >> l >> r;
l--;
cout << seg.prod(l, r).sum << endl;
}
}
return 0;
}
kwm_t