結果

問題 No.879 Range Mod 2 Query
ユーザー kwm_tkwm_t
提出日時 2023-05-04 00:40:47
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 3,000 ms
コード長 2,077 bytes
コンパイル時間 4,255 ms
コンパイル使用メモリ 270,120 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-05-01 17:36:10
合計ジャッジ時間 7,830 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 134 ms
11,648 KB
testcase_12 AC 89 ms
11,520 KB
testcase_13 AC 106 ms
11,648 KB
testcase_14 AC 93 ms
11,904 KB
testcase_15 AC 92 ms
7,808 KB
testcase_16 AC 128 ms
11,904 KB
testcase_17 AC 132 ms
11,904 KB
testcase_18 AC 139 ms
11,904 KB
testcase_19 AC 127 ms
11,904 KB
testcase_20 AC 125 ms
11,904 KB
testcase_21 AC 133 ms
11,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0