結果
問題 | No.2762 Counting and Deleting |
ユーザー |
![]() |
提出日時 | 2024-05-17 23:37:27 |
言語 | C++17(gcc12) (gcc 12.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 329 ms / 4,000 ms |
コード長 | 2,352 bytes |
コンパイル時間 | 4,845 ms |
コンパイル使用メモリ | 270,632 KB |
実行使用メモリ | 10,204 KB |
最終ジャッジ日時 | 2024-12-20 15:33:12 |
合計ジャッジ時間 | 8,826 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 15 |
ソースコード
#include<bits/stdc++.h> using namespace std; //* ATCODER #include<atcoder/all> using namespace atcoder; typedef modint998244353 mint; //*/ /* BOOST MULTIPRECISION #include<boost/multiprecision/cpp_int.hpp> using namespace boost::multiprecision; //*/ typedef long long ll; #define rep(i, s, n) for (int i = (int)(s); i < (int)(n); i++) #define rrep(i, s, n) for (int i = (int)(n)-1; i >= (int)(s); i--) template <typename T> bool chmin(T &a, const T &b) { if (a <= b) return false; a = b; return true; } template <typename T> bool chmax(T &a, const T &b) { if (a >= b) return false; a = b; return true; } template <typename T> T max(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmax(ret, a[i]); return ret; } template <typename T> T min(vector<T> &a){ assert(!a.empty()); T ret = a[0]; for (int i=0; i<(int)a.size(); i++) chmin(ret, a[i]); return ret; } template <typename T> T sum(vector<T> &a){ T ret = 0; for (int i=0; i<(int)a.size(); i++) ret += a[i]; return ret; } struct S { mint a[3][3]; }; S e(){ S ret; rep(i,0,3){ rep(j,0,3){ if(i==j) ret.a[i][j] = 1; else ret.a[i][j] = 0; } } return ret; } S empt(){ S ret; rep(i,0,3){ rep(j,0,3){ ret.a[i][j] = 0; } } return ret; } S op(S a, S b){ S ret = empt(); rep(i,0,3){ rep(j,0,3){ rep(k,0,3){ ret.a[i][j] += a.a[i][k] * b.a[k][j]; } } } return ret; } ll opmax(ll a, ll b){ return std::max(a, b); } ll emax(){ return -(ll)8e18; } ll mapping(ll f, ll x){ return f+x; } ll composition(ll f, ll g){ return f+g; } ll id(){ return 0; } int main(){ S zero = e(); S one = e(); zero.a[0][1] = 1; zero.a[0][2] = 1; one.a[1][0] = 1; one.a[1][2] = 1; int n, q; cin >> n >> q; string s; cin >> s; segtree<S,op,e> seg(n); rep(i,0,n){ if(s[i]=='0')seg.set(i,zero); else seg.set(i,one); } auto f = [&](ll a){ return a<=0; }; lazy_segtree<ll,opmax,emax,ll,mapping,composition,id> laseg(vector<ll>(n,0)); while(q--){ int t; cin >> t; if (t == 1){ int l, r; cin >> l >> r; l--; laseg.apply(l,r,1); int piv=l; while(piv<r){ piv = laseg.max_right(piv,f); if (piv>=r)break; seg.set(piv,e()); laseg.apply(piv,-1e9); } }else{ int l, r; cin >> l >> r; l--; S ret = seg.prod(l,r); cout << (ret.a[1][2]).val() << '\n'; } } }