結果

問題 No.1654 Binary Compression
ユーザー chocorusk
提出日時 2021-08-08 10:18:53
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 1,774 ms / 2,000 ms
コード長 3,732 bytes
コンパイル時間 3,654 ms
コンパイル使用メモリ 198,444 KB
最終ジャッジ日時 2025-01-23 16:57:04
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 50
権限があれば一括ダウンロードができます

ソースコード

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

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#include <atcoder/all>
#define popcount __builtin_popcount
using namespace std;
using namespace atcoder;
typedef long long ll;
typedef pair<int, int> P;
template<typename Monoid, typename OperatorMonoid=Monoid>
struct LazySegmentTree{
using F=function<Monoid(Monoid, Monoid)>;
using G=function<Monoid(Monoid, OperatorMonoid, int)>;
using H=function<OperatorMonoid(OperatorMonoid, OperatorMonoid)>;
int sz;
vector<Monoid> data;
vector<OperatorMonoid> lazy;
const F f;
const G g;
const H h;
const Monoid e1;
const OperatorMonoid e0;
LazySegmentTree(int n, const F f, const G g, const H h, const Monoid &e1, const OperatorMonoid &e0): f(f), g(g), h(h), e1(e1), e0(e0){
sz=1;
while(sz<n) sz<<=1;
data.resize(2*sz-1, e1);
lazy.resize(2*sz-1, e0);
}
void build(vector<Monoid> v){
for(int i=0; i<v.size(); i++) data[i+sz-1]=v[i];
for(int i=sz-2; i>=0; i--) data[i]=f(data[2*i+1], data[2*i+2]);
}
void eval(int k, int l, int r){
if(lazy[k]!=e0){
data[k]=g(data[k], lazy[k], r-l);
if(k<sz-1){
lazy[2*k+1]=h(lazy[2*k+1], lazy[k]);
lazy[2*k+2]=h(lazy[2*k+2], lazy[k]);
}
}
lazy[k]=e0;
}
void update(int a, int b, const OperatorMonoid &x, int k, int l, int r){
eval(k, l, r);
if(r<=a || b<=l) return;
if(a<=l && r<=b){
lazy[k]=h(lazy[k], x);
eval(k, l, r);
}else{
update(a, b, x, 2*k+1, l, (l+r)/2);
update(a, b, x, 2*k+2, (l+r)/2, r);
data[k]=f(data[2*k+1], data[2*k+2]);
}
}
void update(int a, int b, const OperatorMonoid &x){
return update(a, b, x, 0, 0, sz);
}
Monoid find(int a, int b, int k, int l, int r){
eval(k, l, r);
if(b<=l || r<=a) return e1;
if(a<=l && r<=b) return data[k];
else return f(find(a, b, 2*k+1, l, (l+r)/2), find(a, b, 2*k+2, (l+r)/2, r));
}
Monoid find(int a, int b){
return find(a, b, 0, 0, sz);
}
Monoid operator[](const int &k){
return find(k, k+1);
}
};
using mint=static_modint<924844033>;
int main()
{
string s; cin>>s;
int n=s.size();
int l=0;
while(l<n && s[l]=='0') l++;
if(l==n){
cout<<n<<endl;
return 0;
}
int r=n-1;
while(r>=0 && s[r]=='0') r--;
mint c=mint(l+1)*mint(n-r);
s=s.substr(l, r-l+1);
n=s.size();
int lmx=0;
int i=0;
while(s[i]=='1') i++;
lmx=max(lmx, i);
while(i<n){
int c0=0, c1=0;
while(s[i]=='0') i++, c0++;
while(s[i]=='1') i++, c1++;
lmx=max(lmx, c0);
}
auto f=[&](mint a, mint b){
return a+b;
};
auto g=[&](mint a, pair<bool, mint> p, int len){
if(p.first) return a+p.second*len;
else return p.second*len;
};
auto h=[&](pair<bool, mint> p, pair<bool, mint> q){
if(q.first) return make_pair(p.first&q.first, p.second+q.second);
else return make_pair(0, q.second);
};
LazySegmentTree<mint, pair<bool, mint>> seg(lmx+1, f, g, h, 0, make_pair(1, 0));
i=0;
while(s[i]=='1') i++;
seg.update(0, seg.sz, make_pair(1, i));
mint v=1;
while(i<n){
int c0=0, c1=0;
while(s[i]=='0') i++, c0++;
while(s[i]=='1') i++, c1++;
v+=seg.find(0, c0);
seg.update(0, c0, make_pair(0, 0));
seg.update(0, seg.sz, make_pair(1, c1*v));
}
mint ans=c*seg[lmx];
cout<<ans.val()<<endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0