結果
| 問題 | No.1171 Runs in Subsequences |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-11-21 14:46:23 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 94 ms / 2,000 ms |
| + 938µs | |
| コード長 | 4,859 bytes |
| 記録 | |
| コンパイル時間 | 2,761 ms |
| コンパイル使用メモリ | 366,044 KB |
| 実行使用メモリ | 10,260 KB |
| 最終ジャッジ日時 | 2026-11-21 14:46:32 |
| 合計ジャッジ時間 | 5,142 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 18 |
ソースコード
/*
#include<kyopro/master>
void self::main(){
auto a=sinen_alphabet();
zip(a);
ll N=a.size();
auto g=a.pos_groups(a.max()+1);
use_ml1000000007
ml iv2=ml(2).inv();
vec<ml>s(N);
fo(i,N)s[i]=iv2.pow(i);
zeta(s);
ml ans=0;
fo(i,N)ans+=ml(2).pow(N+i-1)*(s[N-1]-s[i]);
FenwickTree<ml>fw(N);
fo(x,g.size()){
fe(g[x],i)fw.add(i,iv2.pow(i));
fe(g[x],i)ans-=ml(2).pow(N+i-1)*fw.sum(i+1,N);
fe(g[x],i)fw.add(i,-iv2.pow(i));
}
pp(ans+ml(2).pow(N)-1);
}
*/
#include<bits/stdc++.h>
#include<atcoder/modint>
using namespace std;
namespace self{void main();void sub();void pp(auto&&...a);void ppe(auto&&...a);}
int main(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);self::main();}
#define eb emplace_back
#define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a)
#define use_ml1000000007 using ml=atcoder::modint1000000007;
namespace self{
auto&operator<<(ostream&o,const atcoder::modint1000000007&x){return o<<(int)x.val();}
using ll=long long;
template<class T>constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};}
void lin(auto&...a){(cin>>...>>a);}
auto encode_alphabet(char c){return c-'a';}
template<class A,class B=A>struct pair{
A a;B b;
pair()=default;
pair(A a,B b):a(a),b(b){}
auto operator<=>(const pair&)const=default;
};
template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;
}
namespace self{
template<class T>class FenwickTree{
public:
ll n_;
vector<T>data_;
FenwickTree(ll n):n_(n),data_(n){}
void add(ll i,T x){
assert(0<=i&&i<n_);
i++;
while(i<=n_){
data_[i-1]+=x;
i+=i&-i;
}
}
T sum(ll l,ll r)const{
assert(0<=l&&l<=r&&r<=n_);
T res=0;
while(r>0)res+=data_[r-1],r-=r&-r;
while(l>0)res-=data_[l-1],l-=l&-l;
return res;
}
};
}
namespace self{
template<class V>concept vectorial=is_base_of_v<vector<typename remove_cvref_t<V>::value_type>,remove_cvref_t<V>>;
template<class V>constexpr int depth=0;
template<vectorial V>constexpr int depth<V> =depth<typename V::value_type>+1;
template<class T>struct core_t_helper{using type=T;};
template<class T>using core_t=core_t_helper<T>::type;
template<class V>struct vec;
template<int D,class T>struct hvec_helper{using type=vec<typename hvec_helper<D-1,T>::type>;};
template<class T>struct hvec_helper<0,T>{using type=T;};
template<int D,class T>using hvec=hvec_helper<D,T>::type;
template<class V>struct vec:vector<V>{
using C=core_t<V>;
using vector<V>::vector;
ll size()const{return vector<V>::size();}
auto&emplace_back(auto&&...a){vector<V>::emplace_back(std::forward<decltype(a)>(a)...);return*this;}
template<class F>void for_each_core(F&&f)const{fe(*this,e){if constexpr(vectorial<V>){ }else f(e);}}
template<class T=C>auto fold(auto&&f)const{
pair<T,bool>res{};
for_each_core([&](const C&e){
if(res.b)f(res.a,e);
else res={e,1};
});
return res;
}
auto max()const{return fold([](auto&a,auto b){if(a<b)a=b;}).a;}
auto min()const{return fold([](auto&a,auto b){if(b<a)a=b;}).a;}
template<class F=less<>>vec stable_sort(F f={})const{vec v=*this;ranges::stable_sort(v,f);return v;}
template<class F=less<>>auto sort_from(F f={})const{
vec<ll>o(size());
std::iota(o.begin(),o.end(),0);
return o.stable_sort([&](ll i,ll j){return f((*this)[i],(*this)[j]);});
}
auto pos_groups(C M)const{
assert(min()>=0);
vec<vec<ll>>res(M);
fo(i,size())res[(*this)[i]].eb(i);
return res;
}
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
template<class F,class...A>auto zip_by(F f,A&...a){
auto v=(a^...);
auto o=v.sort_from(f);
vec<ll>z(v.size());
decltype(v)u;
fe(o,i){
if(u.empty()||f(u.back(),v[i]))u.push_back(v[i]);
z[i]=u.size()-1;
}
ll i=0;
([&](auto&x){fe(x,e)e=z[i++];}(a),...);
return u;
}
auto zip(auto&...a){return zip_by(less<>{},a...);}
template<vectorial V>void zeta(V&&v){if constexpr(depth<remove_cvref_t<V>>>1){ }fo(i,v.size()-1)v[i+1]+=v[i];}
auto sin(){string s;lin(s);return s;}
template<class T=ll>auto sinen_alphabet(){vec<T>r;fe(sin(),e)r.eb(encode_alphabet(e));return r;}
}
void self::pp(auto&&...a){const char*c="";((cout<<c<<a,c=" "),...);cout<<'\n';}
void self::main(){
auto a=sinen_alphabet();
zip(a);
ll N=a.size();
auto g=a.pos_groups(a.max()+1);
use_ml1000000007
ml iv2=ml(2).inv();
vec<ml>s(N);
fo(i,N)s[i]=iv2.pow(i);
zeta(s);
ml ans=0;
fo(i,N)ans+=ml(2).pow(N+i-1)*(s[N-1]-s[i]);
FenwickTree<ml>fw(N);
fo(x,g.size()){
fe(g[x],i)fw.add(i,iv2.pow(i));
fe(g[x],i)ans-=ml(2).pow(N+i-1)*fw.sum(i+1,N);
fe(g[x],i)fw.add(i,-iv2.pow(i));
}
pp(ans+ml(2).pow(N)-1);
}