結果

問題 No.2611 Count 01
ユーザー 蜜蜂
提出日時 2024-01-05 17:47:40
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 2,498 bytes
コンパイル時間 2,122 ms
コンパイル使用メモリ 180,792 KB
実行使用メモリ 30,160 KB
最終ジャッジ日時 2024-09-28 03:27:13
合計ジャッジ時間 11,171 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other WA * 20
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function 'S op(S, S)':
main.cpp:45:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   45 |   auto [al_count0,al_count1,al_count01]=a.left;
      |        ^
main.cpp:46:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   46 |   auto [ar_count0,ar_count1,ar_count01]=a.right;
      |        ^
main.cpp:47:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   47 |   auto [bl_count0,bl_count1,bl_count01]=b.left;
      |        ^
main.cpp:48:8: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17' [-Wc++17-extensions]
   48 |   auto [br_count0,br_count1,br_count01]=b.right;
      |        ^

ソースコード

diff #
プレゼンテーションモードにする

//g++ 1.cpp -std=c++17 -O2 -I .
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/segtree>
#include <atcoder/modint>
using namespace atcoder;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vld = vector<ld>;
using vvld = vector<vld>;
using vst = vector<string>;
using vvst = vector<vst>;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define pq_big(T) priority_queue<T,vector<T>,less<T>>
#define pq_small(T) priority_queue<T,vector<T>,greater<T>>
#define all(a) a.begin(),a.end()
#define rep(i,start,end) for(ll i=start;i<(ll)(end);i++)
#define per(i,start,end) for(ll i=start;i>=(ll)(end);i--)
#define uniq(a) sort(all(a));a.erase(unique(all(a)),a.end())
using mint = modint998244353;
struct S{
int len,zero,one;
mint score;
tuple<mint,mint,mint> left,right; // , count(0),count(1),count(0)*count(1)
};
S op(S a,S b){
S res;
res.len=a.len+b.len;
res.zero=a.zero+b.zero;
res.one=a.one+b.one;
auto [al_count0,al_count1,al_count01]=a.left;
auto [ar_count0,ar_count1,ar_count01]=a.right;
auto [bl_count0,bl_count1,bl_count01]=b.left;
auto [br_count0,br_count1,br_count01]=b.right;
res.score=a.score+b.score+a.len*bl_count01+b.len*ar_count01+ar_count0*bl_count1+ar_count1*bl_count0;
res.left ={al_count0+bl_count0+a.zero*b.len,al_count1+bl_count1+a.one*b.len,al_count01+bl_count01+a.one*bl_count0+a.zero*bl_count1+b.len*a.zero*a
      .one};
res.right={br_count0+ar_count0+b.zero*a.len,br_count1+ar_count1+b.one*a.len,br_count01+ar_count01+b.one*ar_count0+b.zero*ar_count1+a.len*b.zero*b
      .one};
return res;
}
S e(){
S res{0,0,0,0,{0,0,0},{0,0,0}};
return res;
}
S zero(){
return {1,1,0,0,{1,0,0},{1,0,0}};
}
S one(){
return {1,0,1,0,{0,1,0},{0,1,0}};
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n,q;
cin>>n>>q;
string s;
cin>>s;
vector<S> init(n);
rep(i,0,n){
if(s[i]=='0')init[i]=zero();
else init[i]=one();
}
segtree<S,op,e> seg(init);
while(q--){
int t;
cin>>t;
if(t==1){
int i;
cin>>i;
i--;
if(s[i]=='0'){
seg.set(i,one());
s[i]='1';
}
else{
seg.set(i,zero());
s[i]='0';
}
}
else{
int l,r;
cin>>l>>r;
l--;
string str=s.substr(l,r-l);
cout<<seg.prod(l,r).score.val()<<"\n";
}
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0