結果
問題 | No.2762 Counting and Deleting |
ユーザー |
👑 |
提出日時 | 2024-05-08 00:54:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,646 bytes |
コンパイル時間 | 4,637 ms |
コンパイル使用メモリ | 272,832 KB |
最終ジャッジ日時 | 2025-02-21 11:37:45 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | WA * 2 |
other | AC * 3 WA * 12 |
ソースコード
#include<bits/stdc++.h>#include<atcoder/all>#define rep(i,n) for(int i=0;i<n;i++)using namespace std;using mint = atcoder::modint998244353;// https://youtu.be/ylWYSurx10A?t=2352template<typename T>struct Matrix : vector<vector<T>> {int h, w;Matrix(int h = 0, int w = 0, T val=0): vector<vector<T>>(h, vector<T>(w, val)), h(h), w(w) {}Matrix operator*=(const Matrix& M){assert(w == M.h);Matrix r(h, M.w);rep(i,h) rep(k,w) rep(j, M.w){r[i][j] += (*this)[i][k] * M[k][j];}swap(*this, r);return *this;}Matrix operator*(const Matrix& M) const {return (Matrix(*this) *= M);}};using S = Matrix<mint>;S unit(3, 3);S zero(3, 3);S one(3, 3);void setting(){unit[0] = {1, 0, 0};unit[1] = {0, 1, 0};unit[2] = {0, 0, 1};zero[0] = {1, 1, 0};zero[1] = {0, 1, 0};zero[2] = {0, 0, 1};one[0] = {1, 0, 0};one[1] = {1, 1, 1};one[2] = {0, 0, 1};}S op(S a, S b){return a * b;}S e(){return unit;}int main(){setting();int n, q;cin >> n >> q;string s;cin >> s;vector<S> init(n);rep(i, n){if(s[i] == '0') init[(n - 1) - i] = zero;if(s[i] == '1') init[(n - 1) - i] = one;}atcoder::segtree<S, op, e> seg(init);set<int> rest;rep(i, n) rest.insert(i);rep(i, q){int t, l, r;cin >> t >> l >> r;l--; r--;if(t == 1){/*while(true){auto it = rest.lower_bound(l);if(it == rest.end()) break;if(*it > r) break;seg.set((n - 1) - *it, unit);rest.erase(it);}*/}if(t == 2){auto res = seg.prod((n - 1) - r, (n - 1) - l + 1);mint ans = res[0][2] + res[1][2];cout << ans.val() << "\n";}}return 0;}