結果

問題 No.1435 Mmm......
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-07-28 12:44:16
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,236 bytes
コンパイル時間 2,578 ms
コンパイル使用メモリ 210,656 KB
実行使用メモリ 17,152 KB
最終ジャッジ日時 2024-04-15 21:29:00
合計ジャッジ時間 11,249 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 WA -
testcase_04 AC 1 ms
5,376 KB
testcase_05 WA -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

template<class S, S (*op)(S, S), S (*e)()>struct SegTree {
    vector<S> seg;
    int N = 1;

    SegTree (ll n) : SegTree(vector<S>(n, e())) {}
    SegTree (const vector<S> &v){
        ll n = v.size();
        while (N < n) N *= 2;
        seg.resize(N*2-1, e());
        for (ll i=0; i<n; i++) seg[i+N-1] = v[i];
        for (ll i=N-2; i>=0; i--){
            seg[i] = op(seg[i*2+1], seg[i*2+2]);
        }
    }

    void set(int loc, S val){
        loc += N-1;
        seg[loc] = val;
        while (loc != 0){
            loc = (loc-1)/2;
            seg[loc] = op(seg[loc*2+1], seg[loc*2+2]);
        }
    }

    //op(a[l], ..., a[r])
    S prod (int l, int r) const{
        return _prod(l, r, 0, 0, N-1);
    }

    S all_prod() const{
        return seg[0];
    }

    S _prod (int l, int r, int idx, int bitl, int bitr) const{
        if (r < bitl || l > bitr) return e();
        if (l <= bitl && bitr <= r) return seg[idx];

        ll bitm = (bitl+bitr)/2;
        return op(_prod(l, r, idx*2+1, bitl, bitm), _prod(l, r, idx*2+2, bitm+1, bitr));
    }

    S get (int i) const{
        return seg[i+N-1];
    }

    void show() const{
        for (int i=N-1; i<N*2-1; i++) cout << seg[i] << " ";
        cout << endl;
    }
};


const int INF = 1e9+1;

struct S{
    int m1;
    int m2;
};

S op1(S a, S b){
    vector<int> v(4);
    /*
    v[0] = a.m1, v[1] = a.m2, v[2] = b.m1, v[3] = b.m2;
    sort(v.begin(), v.end());
    */
    return a;
}

S e1(){
    return {INF, INF};
}

int op2(int a, int b){
    return max(a, b);
}

int e2(){
    return -INF;
}
 
int main(){
 
    int N, x, mx;
    cin >> N;
    S mi;
    vector<int> a(N);
    vector<S> b(N);
    ll ans=0;

    for (int i=0; i<N; i++){
        cin >> x;
        a[i] = x;
        b[i] = {x, INF};
    }
    SegTree<int, op2, e2> tmx(a);
    SegTree<S, op1, e1> tmi(b);

    for (int i=0; i<N-1; i++){
        int l=i+1, r=N, c;
        while(r-l>1){
            c = (l+r)/2;
            mi = tmi.prod(i, c);
            mx = tmx.prod(i, c);
            if (mx <= mi.m1 + mi.m2) l=c;
            else r=c;
        }
        ans += l-i;
    }

    cout << ans << endl;

    return 0;
}
0