結果
問題 | No.2762 Counting and Deleting |
ユーザー | kwm_t |
提出日時 | 2024-05-19 13:28:06 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,658 ms / 4,000 ms |
コード長 | 4,669 bytes |
コンパイル時間 | 7,104 ms |
コンパイル使用メモリ | 332,340 KB |
実行使用メモリ | 45,036 KB |
最終ジャッジ日時 | 2024-12-20 16:59:37 |
合計ジャッジ時間 | 22,261 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,816 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | AC | 2 ms
6,816 KB |
testcase_05 | AC | 2 ms
6,816 KB |
testcase_06 | AC | 2 ms
6,816 KB |
testcase_07 | AC | 1,438 ms
44,940 KB |
testcase_08 | AC | 1,443 ms
45,036 KB |
testcase_09 | AC | 1,474 ms
44,932 KB |
testcase_10 | AC | 1,534 ms
44,964 KB |
testcase_11 | AC | 1,658 ms
44,768 KB |
testcase_12 | AC | 1,625 ms
44,936 KB |
testcase_13 | AC | 1,650 ms
44,944 KB |
testcase_14 | AC | 1,618 ms
44,984 KB |
testcase_15 | AC | 1,137 ms
44,908 KB |
testcase_16 | AC | 1,144 ms
44,920 KB |
ソースコード
#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> struct Matrix { int row, column; std::vector<std::vector<T>>mat; Matrix(int r = 0, int c = 0, T val = 0) :row(r), column(c) { mat = std::vector<std::vector<T>>(row, std::vector<T>(column, val)); } std::vector<T>& operator[](const int i) { return mat[i]; } Matrix& operator+=(const Matrix & other) { assert(row == other.row && column == other.column); for (int i = 0; i < row; ++i) { for (int j = 0; j < column; ++j) { mat[i][j] += other.mat[i][j]; } } return *this; } Matrix& operator-=(const Matrix & other) { assert(row == other.row && column == other.column); for (int i = 0; i < row; ++i) { for (int j = 0; j < column; ++j) { mat[i][j] -= other.mat[i][j]; } } return *this; } Matrix& operator*=(const Matrix & other) { assert(column == other.row); Matrix ret(row, other.column); for (int i = 0; i < row; ++i) { for (int k = 0; k < column; ++k) { for (int j = 0; j < other.column; ++j) { ret.mat[i][j] += mat[i][k] * other.mat[k][j]; } } } return *this = ret; } Matrix& operator*=(T k) { for (int i = 0; i < row; ++i) { for (int j = 0; j < column; ++j) { mat[i][j] *= k; } } return *this; } Matrix operator+(const Matrix other)const { return Matrix(*this) += other; } Matrix operator-(const Matrix other)const { return Matrix(*this) -= other; } Matrix operator*(const Matrix other)const { return Matrix(*this) *= other; } Matrix operator*(const T k)const { return Matrix(*this) *= k; } std::vector<T> operator*(const std::vector<T> other) const { assert(column == (int)other.size()); std::vector<T> ret(row); for (int i = 0; i < row; ++i) { for (int j = 0; j < column; ++j) { ret[i] += mat[i][j] * other[j]; } } return ret; } Matrix pow(long long n) const { assert(row == column); if (n == 0) { Matrix e(row, column); for (int i = 0; i < row; ++i) e.mat[i][i] = 1; return e; } Matrix ret = pow(n >> 1); ret *= ret; if (n & 1) ret *= *this; return ret; } Matrix debug() { for (int i = 0; i < row; ++i) { for (int j = 0; j < column; ++j) std::cout << mat[i][j] << " "; std::cout << std::endl; } } mint det() { auto copyMat = mat; mint res = 1; for (int i = 0; i < row; ++i) { for (int j = i; j < row; ++j) { if (0 == copyMat[j][i])continue; if (i != j) { std::swap(copyMat[i], copyMat[j]); res *= -1; } } if (0 == copyMat[i][i])return 0; res *= copyMat[i][i]; mint inv = mint(1) / copyMat[i][i]; for (int j = 0; j < column; ++j) { copyMat[i][j] *= inv; } for (int j = i + 1; j < row; ++j) { mint c = copyMat[j][i]; for (int k = i; k < column; ++k) { copyMat[j][k] -= c * copyMat[i][k]; } } } return res; } }; Matrix<mint> op(Matrix<mint> a, Matrix<mint> b) { return b * a; } Matrix<mint> e() { auto e = Matrix<mint>(3, 3); rep(i, 3)e[i][i] = 1; return e; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); auto unit = Matrix<mint>(3, 3); unit[0] = { 1, 0, 0 }; unit[1] = { 0, 1, 0 }; unit[2] = { 0, 0, 1 }; auto zero = Matrix<mint>(3, 3); zero[0] = { 1, 1, 0 }; zero[1] = { 0, 1, 0 }; zero[2] = { 0, 0, 1 }; auto one = Matrix<mint>(3, 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>>init(n); rep(i, n) { if ('0' == s[i])init[i] = zero; else init[i] = one; } segtree<Matrix<mint>, 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; }