結果

問題 No.1435 Mmm......
ユーザー srjywrdnprktsrjywrdnprkt
提出日時 2023-07-28 13:08:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 724 ms / 2,000 ms
コード長 1,154 bytes
コンパイル時間 2,660 ms
コンパイル使用メモリ 203,584 KB
実行使用メモリ 11,904 KB
最終ジャッジ日時 2024-04-15 21:50:13
合計ジャッジ時間 13,784 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 328 ms
11,008 KB
testcase_07 AC 409 ms
11,392 KB
testcase_08 AC 480 ms
11,520 KB
testcase_09 AC 442 ms
11,392 KB
testcase_10 AC 378 ms
11,008 KB
testcase_11 AC 371 ms
11,264 KB
testcase_12 AC 340 ms
11,012 KB
testcase_13 AC 333 ms
11,008 KB
testcase_14 AC 241 ms
7,552 KB
testcase_15 AC 502 ms
11,648 KB
testcase_16 AC 410 ms
11,296 KB
testcase_17 AC 274 ms
7,680 KB
testcase_18 AC 511 ms
11,768 KB
testcase_19 AC 362 ms
11,200 KB
testcase_20 AC 456 ms
11,520 KB
testcase_21 AC 724 ms
11,720 KB
testcase_22 AC 666 ms
11,652 KB
testcase_23 AC 552 ms
11,896 KB
testcase_24 AC 552 ms
11,812 KB
testcase_25 AC 550 ms
11,776 KB
testcase_26 AC 555 ms
11,668 KB
testcase_27 AC 550 ms
11,904 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/segtree>

using namespace std;
using namespace atcoder;
using ll = long long;

const int INF = 1e9+1;

struct S{
    int m1;
    int m2;
};

S op1(S a, S b){
    if(a.m1 < b.m1){
        if(a.m2 < b.m1){
            return a;
        }else{
            return {a.m1, b.m1};
        }
    }else{
        if(b.m2 < a.m1){
            return b;
        }else{
            return {b.m1, a.m1};
        }
    }
}

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

    cout << ans << endl;

    return 0;
}
0