結果
| 問題 |
No.1435 Mmm......
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-09-10 16:17:39 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 107 ms / 2,000 ms |
| コード長 | 4,215 bytes |
| コンパイル時間 | 3,472 ms |
| コンパイル使用メモリ | 293,096 KB |
| 実行使用メモリ | 14,976 KB |
| 最終ジャッジ日時 | 2025-09-10 16:17:46 |
| 合計ジャッジ時間 | 6,527 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 24 |
ソースコード
#include<bits/stdc++.h>
#if __has_include(<atcoder/all>)
#endif
using namespace std;
#define LL(...) ll __VA_ARGS__;lin(__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 fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a)
#define defpp template<ostream&o=cout>void pp(const auto&...a){[[maybe_unused]]const char*c="";((o<<c<<a,c=" "),...);o<<'\n';}void epp(const auto&...a){pp<cerr>(a...);}
#define entry defpp void main();void main2();}int main(){my::io();my::main();}namespace my{
namespace my{
void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);}
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};}
void lin(auto&...a){(cin>>...>>a);}
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());}
bool amax(auto&a,const auto&b){return a<b?a=b,1:0;}
auto max(auto...a){return max(initializer_list<common_type_t<decltype(a)...>>{a...});}
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{static constexpr T v=ones<T>(maxsize10<T>())*(1-is_negative*2);return v;}
};
constexpr infinity oo;
template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;
}
namespace my{
template<class T,class F=less<>>struct multiset:std::multiset<T,F>{
multiset()=default;
ll size()const{return std::multiset<T,F>::size();}
void erase_unique(const T&x){if(auto p=this->find(x);p!=this->end())this->erase(p);}
T front()const{assert(size());return*this->begin();}
T back()const{assert(size());return*prev(this->end());}
};
}
namespace my{
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 { }
}
template<class F=less<>>auto sort(F f={})const{vec v=*this;ranges::sort(v,f);return v;}
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
auto pack_vec(const auto&...a){return vec<common_type_t<decltype(a)...>>{a...};}
}
namespace my{
void sort(auto&...a){auto v=pack_vec(a...).sort();ll i=0;((a=v[i++]),...);}
}
namespace my{
struct shakutori{
static auto maximal_interval_enumerate(ll n,auto del_l,auto add_r,auto check_r){
vec<int>res(n);
for(ll l=0,r=0;l<n;l<r?del_l(l++,r),0:(l++,r++)){
for(;r<n&&check_r(l,r);add_r(l,r++));
res[l]=r;
}
return res;
}
};
}
namespace my{entry
void main(){
LL(N);
VL(N,a);
multiset<ll>st;
auto del_l=[&](ll l,ll r){st.erase_unique(a[l]);}; // 今見ている区間が[l,r)で,lを消す時の処理
auto add_r=[&](ll l,ll r){st.emplace(a[r]);}; // 今見ている区間が[l,r)で,rを加える時の処理
auto check=[&](ll l,ll r){ // 今見ている区間が[l,r)で,rを加えても真になるか判定
if(r-l==0)return true;
ll M=st.back(),m0=st.front(),m1=(r-l>=2?*next(st.begin()):oo);
ll t=a[r];
amax(M,t);
sort(m0,m1,t);
return M<=m0+m1;
};
auto v=shakutori::maximal_interval_enumerate(N,del_l,add_r,check);
ll ans=0;
fo(l,N)ans+=max(v[l]-l-1,0);
pp(ans);
}}