結果
| 問題 | No.992 最長増加部分列の数え上げ |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-27 12:11:22 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 85 ms / 2,000 ms |
| + 466µs | |
| コード長 | 6,479 bytes |
| 記録 | |
| コンパイル時間 | 2,605 ms |
| コンパイル使用メモリ | 357,624 KB |
| 実行使用メモリ | 18,560 KB |
| 最終ジャッジ日時 | 2026-10-27 12:11:35 |
| 合計ジャッジ時間 | 11,715 ms |
|
ジャッジサーバーID (参考情報) |
judge5_0 / judge4_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 45 |
ソースコード
/*
#include<kyopro/master>
void self::main(){
LL(N);
VL(N,a);
a.emplace_front(-oo);
ll M=zip(a).size();
use_ml1000000007
struct node{
using S=pair<ll,ml>;
static S op(S a,S b){
S res{};
if(a.a>b.a)res=a;
else if(a.a<b.a)res=b;
else res={a.a,a.b+b.b};
return res;
}
static S e(){return{};}
};
SegTreeMonoidAlias<node>s(M);
s.set(0,{1,1});
fo(i,1,N+1){
auto[l,c]=s.prod(0,a[i]);
auto x=node::op(s.get(a[i]),{l+1,c});
s.set(a[i],x);
}
pp(s.all_prod().b);
}
*/
#include<bits/stdc++.h>
#include<atcoder/modint>
using namespace std;
namespace self{void main();void sub();template<ostream&o>void pp(auto&&...a);void epp(auto&&...a);}
int main(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);self::main();}
#define RD(T,...) T __VA_ARGS__;lin(__VA_ARGS__)
#define LL(...) RD(ll,__VA_ARGS__)
#define RDVL(T,n,...) vec<T>__VA_ARGS__;fe(refs(__VA_ARGS__),e)e.get().resizes(n);lin(__VA_ARGS__)
#define VL(n,...) RDVL(ll,n,__VA_ARGS__)
#define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define of(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(1,__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;
constexpr auto refs(auto&...a){return array{ref(a)...};}
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};}
template<class T>constexpr auto for_range(T s,T a,T b,T c=1){return array{a-s,b,(1-s*2)*c};}
void lin(auto&...a){(cin>>...>>a);}
constexpr ll clz(ll x){return __builtin_clzll(x);}
constexpr ll ctz(ll x){return __builtin_ctzll(x);}
constexpr ll msb(ll x){return x?63-clz(x):-1;}
constexpr ll size2(auto x){return msb(x|1)+1;}
constexpr ll size10(auto x){x|=1;ll r=0;while(x>0)x/=10,++r;return r;}
template<class T>constexpr ll maxsize10(){return size10(numeric_limits<T>::max());}
template<class T=ll>T pow2(ll n){return T(1)<<n;}
template<class T=ll>T gemin_pow2(T x){if(x<=1)return 1;return pow2<T>(size2(x-1));}
constexpr ll log2_floor(auto x){return size2(x)-1;}
auto min(auto...a){return min(initializer_list<common_type_t<decltype(a)...>>{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<bool is_negative=false>struct infinity{
template<integral T>static constexpr T ones(size_t n){return n?ones<T>(n-1)*10+1:0;}
template<integral T>constexpr operator T()const{return ones<T>(maxsize10<T>())*(1-is_negative*2);}
constexpr auto operator-()const{return infinity<!is_negative>();}
};
constexpr infinity oo;
template<class F=less<>>decltype(auto)sort(auto&&a,F f={}){ranges::sort(a,f);return a;}
decltype(auto)unique(auto&&a){sort(a).erase(ranges::unique(a).begin(),a.end());return a;}
template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;
template<class I>class Iterator{
private:
I it_,begin_,end_;
public:
Iterator(I it,I begin,I end):it_(it),begin_(begin),end_(end){}
ll dist()const{return it_-begin_;}
};
}
namespace self{
template<class V>istream&operator>>(istream&i,vector<V>&v){fe(v,e)i>>e;return i;}
template<class V>constexpr int depth=0;
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>{
static constexpr int D=depth<V>+1;
using C=core_t<V>;
using vector<V>::vector;
void resizes(const auto&...a){if constexpr(sizeof...(a)==D)*this=make(a...,C{});else{ }}
static auto make(ll n,const auto&...a){
if constexpr(sizeof...(a)==1)return vec<C>(n,array{a...}[0]);
else { }
}
ll size()const{return vector<V>::size();}
auto&emplace_front(auto&&...a){this->emplace(this->begin(),std::forward<decltype(a)>(a)...);return*this;}
auto first_true(const V&x,auto&&f)const{
auto b=this->begin(),e=this->end();
auto p=partition_point(b,e,[&x,&f](const V&v){return !f(x,v);});
return Iterator{p,b,e};
}
auto first_ge(const V&x)const{return first_true(x,[](auto&x,auto&e){return x<=e;});}
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
auto zip(auto&...a){auto v=(a^...);unique(v);([&](auto&u){fe(u,e)e=v.first_ge(e).dist();}(a),...);return v;}
}
namespace self{
template<class S,S op(S,S),S e()>class SegTree{
public:
ll n_,leaf_size_;
vector<S>d_;
explicit SegTree(ll n):SegTree(vector<S>(n,e())){}
explicit SegTree(const vector<S>&v):n_(v.size()){
leaf_size_=gemin_pow2(n_);
d_=vector<S>(leaf_size_*2,e());
fo(i,n_)d_[i+leaf_size_]=v[i];
of(i,leaf_size_,1)pull(i);
}
void pull(ll k){d_[k]=op(d_[k*2],d_[k*2+1]);}
void set(ll p,S x){
assert(0<=p&&p<n_);
p+=leaf_size_;
d_[p]=x;
p>>=1;
for(;p>0;p>>=1)pull(p);
}
S get(ll p)const{assert(0<=p&&p<n_);return d_[p+leaf_size_];}
void for_each_canonical_cover(ll j,ll k,auto&&g)const{
while(j<k){
ll t=min(ctz(j),log2_floor(k-j));
g(j>>t);
j+=1<<t;
}
}
S prod(ll l,ll r)const{
assert(0<=l&&l<=r&&r<=n_);
if(l==r)return e();
l+=leaf_size_,r+=leaf_size_;
S cum=e();
for_each_canonical_cover(l,r,[&](ll k){cum=op(cum,d_[k]);});
return cum;
}
S all_prod()const{return d_[1];}
};
}
namespace self{
template<class M>using SegTreeMonoidAlias=SegTree<typename M::S,M::op,M::e>;
}
template<ostream&o=cout>void self::pp(auto&&...a){const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}
void self::main(){
LL(N);
VL(N,a);
a.emplace_front(-oo);
ll M=zip(a).size();
use_ml1000000007
struct node{
using S=pair<ll,ml>;
static S op(S a,S b){
S res{};
if(a.a>b.a)res=a;
else if(a.a<b.a)res=b;
else res={a.a,a.b+b.b};
return res;
}
static S e(){return{};}
};
SegTreeMonoidAlias<node>s(M);
s.set(0,{1,1});
fo(i,1,N+1){
auto[l,c]=s.prod(0,a[i]);
auto x=node::op(s.get(a[i]),{l+1,c});
s.set(a[i],x);
}
pp(s.all_prod().b);
}