結果

問題 No.2611 Count 01
ユーザー 蜜蜂蜜蜂
提出日時 2024-01-07 11:07:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 216 ms / 6,000 ms
コード長 2,465 bytes
コンパイル時間 1,536 ms
コンパイル使用メモリ 179,800 KB
実行使用メモリ 30,028 KB
最終ジャッジ日時 2024-01-19 19:06:58
合計ジャッジ時間 7,335 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 186 ms
30,028 KB
testcase_04 AC 189 ms
30,028 KB
testcase_05 AC 192 ms
30,028 KB
testcase_06 AC 187 ms
30,028 KB
testcase_07 AC 204 ms
30,028 KB
testcase_08 AC 192 ms
30,028 KB
testcase_09 AC 205 ms
30,028 KB
testcase_10 AC 194 ms
30,028 KB
testcase_11 AC 196 ms
30,028 KB
testcase_12 AC 191 ms
30,028 KB
testcase_13 AC 197 ms
30,028 KB
testcase_14 AC 191 ms
30,028 KB
testcase_15 AC 197 ms
30,028 KB
testcase_16 AC 200 ms
30,028 KB
testcase_17 AC 207 ms
30,028 KB
testcase_18 AC 206 ms
30,028 KB
testcase_19 AC 199 ms
30,028 KB
testcase_20 AC 216 ms
30,028 KB
testcase_21 AC 190 ms
30,028 KB
testcase_22 AC 191 ms
30,028 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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{
  mint 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--;
      cout<<seg.prod(l,r).score.val()<<"\n";
    }
  }
}
0