mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 18:08:47 +00:00
parent
1ae0ce09c3
commit
fb4eafdc6e
124
LibreOJ/3043/3043.cpp
Normal file
124
LibreOJ/3043/3043.cpp
Normal file
@ -0,0 +1,124 @@
|
||||
#include <iostream>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 1e5 + 5;
|
||||
const int mod = 998244353;
|
||||
|
||||
int n, m, delta = 1, sum, ans;
|
||||
|
||||
struct node {
|
||||
int l, r, f, s, tag_f_add, tag_f_mul, tag_s_mul;
|
||||
|
||||
node(const int &_l = 0, const int &_r = 0)
|
||||
: l(_l), r(_r), f(0), s(0), tag_f_add(0), tag_f_mul(1), tag_s_mul(1) {}
|
||||
} tr[N << 2];
|
||||
|
||||
void build(int u, int l, int r) {
|
||||
tr[u] = node(l, r);
|
||||
|
||||
if (l == r) return;
|
||||
|
||||
int mid = l + r >> 1;
|
||||
|
||||
build(u << 1, l, mid);
|
||||
build(u << 1 | 1, mid + 1, r);
|
||||
}
|
||||
|
||||
void push_f_add(int u, int v) {
|
||||
tr[u].tag_f_add = (static_cast<long long>(tr[u].tag_f_add) + v) % mod;
|
||||
tr[u].f = (static_cast<long long>(tr[u].f) + v) % mod;
|
||||
}
|
||||
|
||||
void push_f_mul(int u, int v) {
|
||||
tr[u].f = static_cast<long long>(tr[u].f) * v % mod;
|
||||
tr[u].tag_f_mul = static_cast<long long>(tr[u].tag_f_mul) * v % mod;
|
||||
tr[u].tag_f_add = static_cast<long long>(tr[u].tag_f_add) * v % mod;
|
||||
}
|
||||
|
||||
void push_s_mul(int u, int v) {
|
||||
tr[u].s = static_cast<long long>(tr[u].s) * v % mod;
|
||||
tr[u].tag_s_mul = static_cast<long long>(tr[u].tag_s_mul) * v % mod;
|
||||
}
|
||||
|
||||
void pushdown(int u) {
|
||||
if (tr[u].tag_f_mul != 1) {
|
||||
push_f_mul(u << 1, tr[u].tag_f_mul);
|
||||
push_f_mul(u << 1 | 1, tr[u].tag_f_mul);
|
||||
tr[u].tag_f_mul = 1;
|
||||
}
|
||||
|
||||
if (tr[u].tag_s_mul != 1) {
|
||||
push_s_mul(u << 1, tr[u].tag_s_mul);
|
||||
push_s_mul(u << 1 | 1, tr[u].tag_s_mul);
|
||||
tr[u].tag_s_mul = 1;
|
||||
}
|
||||
|
||||
if (tr[u].tag_f_add != 0) {
|
||||
push_f_add(u << 1, tr[u].tag_f_add);
|
||||
push_f_add(u << 1 | 1, tr[u].tag_f_add);
|
||||
tr[u].tag_f_add = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void modify(int u, int l, int r) {
|
||||
if (l <= tr[u].l && tr[u].r <= r) {
|
||||
ans = (((static_cast<long long>(ans) - tr[u].s) % mod) + mod) % mod;
|
||||
tr[u].s = (static_cast<long long>(tr[u].s) + delta) % mod;
|
||||
tr[u].tag_s_mul = (static_cast<long long>(tr[u].tag_s_mul) * 2) % mod;
|
||||
push_f_add(u, delta);
|
||||
sum = (static_cast<long long>(sum) + tr[u].s) % mod;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (tr[u].l > r || tr[u].r < l) {
|
||||
ans = (((static_cast<long long>(ans) - tr[u].s) % mod) + mod) % mod;
|
||||
tr[u].s = (static_cast<long long>(tr[u].s) + tr[u].f) % mod;
|
||||
tr[u].tag_s_mul = (static_cast<long long>(tr[u].tag_s_mul) * 2) % mod;
|
||||
push_f_mul(u, 2);
|
||||
sum = (static_cast<long long>(sum) + tr[u].s) % mod;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
pushdown(u);
|
||||
|
||||
ans = (((static_cast<long long>(ans) - tr[u].s) % mod) + mod) % mod;
|
||||
sum = (static_cast<long long>(sum) + tr[u].s) % mod;
|
||||
|
||||
modify(u << 1, l, r);
|
||||
modify(u << 1 | 1, l, r);
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> m;
|
||||
|
||||
build(1, 1, n);
|
||||
|
||||
while (m--) {
|
||||
int op;
|
||||
|
||||
cin >> op;
|
||||
|
||||
if (op == 1) {
|
||||
int l, r;
|
||||
|
||||
cin >> l >> r;
|
||||
|
||||
sum = 0;
|
||||
modify(1, l, r);
|
||||
ans = (2ll * ans + sum) % mod;
|
||||
delta = 2ll * delta % mod;
|
||||
} else { // op == 2
|
||||
cout << ans << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
LibreOJ/3043/data/segment1.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment1.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment1.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment10.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment10.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment10.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment2.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment2.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment2.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment3.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment3.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment3.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment4.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment4.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment4.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment5.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment5.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment5.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment6.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment6.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment6.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment7.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment7.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment7.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment8.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment8.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment8.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment9.ans
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment9.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
LibreOJ/3043/data/segment9.in
(Stored with Git LFS)
Normal file
BIN
LibreOJ/3043/data/segment9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user