結果
| 問題 |
No.2762 Counting and Deleting
|
| コンテスト | |
| ユーザー |
kwm_t
|
| 提出日時 | 2024-05-19 13:41:51 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 223 ms / 4,000 ms |
| コード長 | 2,570 bytes |
| コンパイル時間 | 6,060 ms |
| コンパイル使用メモリ | 319,068 KB |
| 実行使用メモリ | 12,856 KB |
| 最終ジャッジ日時 | 2024-12-20 16:59:47 |
| 合計ジャッジ時間 | 9,301 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 15 |
ソースコード
#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 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; }
template <typename T, int X = 1>
struct Matrix {
array<array<T, X>, X> v;
Matrix(int i = 0) {
if (1 == i) { for (int i = 0; i < X; ++i) { v[i][i] = 1; } }
}
std::array<T, X>& operator[](const int i) {
return v[i];
}
Matrix(const array<array<T, X>, X> &s) { v = s; }
Matrix operator*=(const Matrix & m) {
Matrix s(0);
for (int i = 0; i < X; ++i) {
for (int j = 0; j < X; ++j) {
for (int k = 0; k < X; ++k) {
s.v[i][j] += m.v[i][k] * v[k][j];
}
}
}
swap(s, *this);
return *this;
}
};
Matrix<mint, 3> op(Matrix<mint, 3> a, Matrix<mint, 3> b) {
Matrix<mint, 3> ret(0);
for (int i = 0; i < 3; ++i) {
for (int j = 0; j < 3; ++j) {
for (int k = 0; k < 3; ++k) {
ret.v[i][j] += b.v[i][k] * a.v[k][j];
}
}
}
return ret;
}
Matrix<mint, 3> e() {
return Matrix<mint, 3>(1);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
auto unit = Matrix<mint, 3>();
unit[0] = { 1, 0, 0 };
unit[1] = { 0, 1, 0 };
unit[2] = { 0, 0, 1 };
auto zero = Matrix<mint, 3>();
zero[0] = { 1, 1, 0 };
zero[1] = { 0, 1, 0 };
zero[2] = { 0, 0, 1 };
auto one = Matrix<mint, 3>();
one[0] = { 1, 0, 0 };
one[1] = { 1, 1, 1 };
one[2] = { 0, 0, 1 };
int n, q; cin >> n >> q;
string s; cin >> s;
vector<Matrix<mint, 3>>init(n);
rep(i, n) {
if ('0' == s[i])init[i] = zero;
else init[i] = one;
}
segtree<Matrix<mint, 3>, op, e>seg(init);
set<int>st;
rep(i, n)st.insert(i);
while (q--) {
int t, l, r; cin >> t >> l >> r;
l--;
if (1 == t) {
auto ite = st.lower_bound(l);
while (ite != st.end() && *ite < r) {
seg.set(*ite, unit);
ite = st.erase(ite);
}
}
else {
auto get = seg.prod(l, r);
mint ans = get[0][2] + get[1][2];
cout << ans.val() << endl;
}
}
return 0;
}
kwm_t