結果
| 問題 |
No.2762 Counting and Deleting
|
| コンテスト | |
| ユーザー |
Yudai0606Nazo
|
| 提出日時 | 2024-05-18 08:39:52 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2,269 ms / 4,000 ms |
| コード長 | 2,201 bytes |
| コンパイル時間 | 4,720 ms |
| コンパイル使用メモリ | 270,604 KB |
| 最終ジャッジ日時 | 2025-02-21 15:41:47 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 15 |
ソースコード
#include <bits/stdc++.h>
#include <cassert>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;
//using mint = modint1000000007;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repu(i, s, t) for (int i = (int)(s); i < (int)(t); i++)
#define repd(i, s, t) for (int i = (int)(s)-1; i >= (int)(t); i--)
#define all(v) v.begin(), v.end()
template<typename T> bool chmax(T &a, const T b) { if(a >= b) return false; a = b; return true; }
template<typename T> bool chmin(T &a, const T b) { if(a <= b) return false; a = b; return true; }
template<typename T> istream& operator>>(istream &in, vector<T> &a) { for(T &x: a) in >> x; return in; }
template<typename T> ostream& operator<<(ostream &out, const vector<T> &a) { for(const T &x: a) out << x << ' '; return out; }
const int di[] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
const int dj[] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
struct S {
bool zero_ex, one_ex;
vector<vector<mint>> val;
S() : zero_ex(false), one_ex(false), val(2, vector<mint>(3)) {}
S(bool x) : zero_ex(!x), one_ex(x), val(2, vector<mint>(3)) {
val[int(x)] = {1, 1, 1};
}
};
S op(S l, S r) {
S res;
rep(i, 2) rep(j, 3) res.val[i][j] = l.val[i][j] + l.val[i][0] * r.val[0][j] + l.val[i][1] * r.val[1][j];
if(!l.zero_ex) res.val[0] = r.val[0];
if(!l.one_ex) res.val[1] = r.val[1];
if(r.zero_ex) rep(i, 2) res.val[i][0] -= l.val[i][0];
if(r.one_ex) rep(i, 2) res.val[i][1] -= l.val[i][1];
res.zero_ex = l.zero_ex || r.zero_ex;
res.one_ex = l.one_ex || r.one_ex;
return res;
}
S e() { return S(); }
using F = bool;
S mapping(F l, S r) {
if(l) return e();
return r;
}
F composition(F l, F r) { return l || r; }
F id() { return false; }
int main() {
int n, q;
string s;
cin >> n >> q >> s;
lazy_segtree<S, op, e, F, mapping, composition, id> lst(n);
rep(i, n) lst.set(i, S(s[i]-'0'));
while(q--) {
int t, l, r;
cin >> t >> l >> r;
l--;
if(t == 1) {
lst.apply(l, r, true);
} else {
cout << lst.prod(l, r).val[1][2].val() << '\n';
}
}
return 0;
}
Yudai0606Nazo