結果

問題 No.1435 Mmm......
ユーザー HaaHaa
提出日時 2021-03-19 23:07:43
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,863 bytes
コンパイル時間 1,723 ms
コンパイル使用メモリ 179,784 KB
実行使用メモリ 38,784 KB
最終ジャッジ日時 2024-04-29 18:40:57
合計ジャッジ時間 20,200 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 848 ms
32,896 KB
testcase_07 AC 1,005 ms
33,152 KB
testcase_08 AC 1,154 ms
33,408 KB
testcase_09 AC 1,073 ms
33,280 KB
testcase_10 AC 963 ms
33,024 KB
testcase_11 AC 930 ms
33,024 KB
testcase_12 AC 870 ms
32,896 KB
testcase_13 AC 846 ms
32,768 KB
testcase_14 AC 592 ms
18,304 KB
testcase_15 AC 1,206 ms
33,408 KB
testcase_16 AC 1,038 ms
33,152 KB
testcase_17 AC 698 ms
18,432 KB
testcase_18 AC 1,207 ms
33,408 KB
testcase_19 AC 931 ms
33,024 KB
testcase_20 AC 1,116 ms
33,152 KB
testcase_21 TLE -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) v.begin(),v.end()
constexpr ll MOD=998244353;
constexpr ll INF=2e18;

template<typename X>
struct Segtree{
    using F=function<X(X,X)>;
    int n; F f; X ex;
    vector<X> dat;
    Segtree(int n_, F f, X ex)
        :f(f), ex(ex){
        n=1;
        while(n_>n){n*=2;}
        dat.assign(2*n,ex);
    }
    void set(int i, X x){
        dat[i+n-1]=x;
    }
    void build(){
        for(int k=n-2;k>=0;k--) 
            dat[k]=f(dat[2*k+1],dat[2*k+2]);
    }
    void update(int i, X x){
        i+=n-1;
        dat[i]=x;
        while(i>0){
            i=(i-1)/2;
            dat[i]=f(dat[i*2+1],dat[i*2+2]);
        }
    }
    X query(int a, int b){
        return query_sub(a,b,0,0,n);
    }
    X query_sub(int a, int b, int k, int l, int r){
        if(r<=a||b<=l)
            return ex;
        else if(a<=l&&r<=b)
            return dat[k];
        else{
            X vl=query_sub(a,b,k*2+1,l,(l+r)/2);
            X vr=query_sub(a,b,k*2+2,(l+r)/2,r);
            return f(vl,vr);
        }
    }
};

VI f(VI a, VI b){
    VI ret(3);
    ret[0]=max(a[0],b[0]);
    VI c={a[1],a[2],b[1],b[2]};
    sort(ALL(c));
    ret[1]=c[0];
    ret[2]=c[1];
    return ret;
}

int main(){
    int n; cin >> n;
    VI a(n); REP(i,n) cin >> a[i];
    VI e={0,INF,INF};
    Segtree<VI> seg(n,f,e);
    REP(i,n)
        seg.set(i,{a[i],a[i],INF});
    seg.build();
    int l=0, r=1;
    ll ans=0;
    REP(i,n){
        ans+=r-i;
        for(int j=r+1;j<n;j++){
            VI ret=seg.query(i,j+1);
            if(ret[0]>ret[1]+ret[2]){
                r=j-1;
                break;
            }
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}
0