結果

問題 No.1435 Mmm......
ユーザー siro53siro53
提出日時 2021-03-19 22:38:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 685 ms / 2,000 ms
コード長 2,975 bytes
コンパイル時間 2,318 ms
コンパイル使用メモリ 205,920 KB
実行使用メモリ 10,756 KB
最終ジャッジ日時 2023-08-12 03:18:08
合計ジャッジ時間 13,070 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 312 ms
10,156 KB
testcase_07 AC 381 ms
10,468 KB
testcase_08 AC 449 ms
10,620 KB
testcase_09 AC 413 ms
10,680 KB
testcase_10 AC 348 ms
10,512 KB
testcase_11 AC 347 ms
10,476 KB
testcase_12 AC 327 ms
10,276 KB
testcase_13 AC 310 ms
10,164 KB
testcase_14 AC 226 ms
6,872 KB
testcase_15 AC 476 ms
10,612 KB
testcase_16 AC 386 ms
10,472 KB
testcase_17 AC 261 ms
7,004 KB
testcase_18 AC 481 ms
10,732 KB
testcase_19 AC 331 ms
10,284 KB
testcase_20 AC 425 ms
10,656 KB
testcase_21 AC 685 ms
10,704 KB
testcase_22 AC 651 ms
10,612 KB
testcase_23 AC 484 ms
10,756 KB
testcase_24 AC 491 ms
10,628 KB
testcase_25 AC 492 ms
10,676 KB
testcase_26 AC 495 ms
10,680 KB
testcase_27 AC 488 ms
10,684 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#line 1 "/home/siro53/kyo-pro/compro_library/template/template.cpp"
#include <bits/stdc++.h>
using namespace std;
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
#ifndef DEBUG
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << '(' << p.first << ',' << p.second << ')';
    return os;
}
template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
    os << '{';
    for(int i = 0; i < (int)v.size(); i++) {
        if(i) { os << ','; }
        os << v[i];
    }
    os << '}';
    return os;
}
void debugg() { cerr << endl; }
template <class T, class... Args>
void debugg(const T &x, const Args &... args) {
    cerr << " " << x;
    debugg(args...);
}
#define debug(...)                                                             \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]: ", debugg(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(15);
    }
} __Setup;

using ll = long long;
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define FOR(i, a, b) for(int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------
#line 2 "c.cpp"

#include <atcoder/segtree>

using P = pair<int, int>;
P e1() {return P(INF, INF);}
P op1(P a, P b) {
    int mn1, mn2;
    if(a.first <= b.first) {
        mn1 = a.first;
        mn2 = min({a.second, b.first, b.second});
    }else{
        mn1 = b.first;
        mn2 = min({b.second, a.first, a.second});
    }
    return P(mn1, mn2);
}

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

using segtree_min2 = atcoder::segtree<P, op1, e1>;
using segtree_max = atcoder::segtree<int, op2, e2>;

int N;
int a[200000];

int main(){
    cin >> N;
    REP(i, N) cin >> a[i];

    segtree_min2 seg_min2(N);
    segtree_max seg_max(N);
    REP(i, N) {
        seg_min2.set(i, P(a[i], INF));
        seg_max.set(i, a[i]);
    }

    auto check = [&](int l, int r) -> bool {
        if(r > N) return false;
        auto [m1, m2] = seg_min2.prod(l, r);
        int M = seg_max.prod(l, r);
        // debug(l, r, m1, m2, M);
        return (m1 + m2 >= M);
    };

    ll ans = 0;

    REP(l, N-1) {
        int ok = l+1, ng = N;
        while(ng-ok > 1) {
            int mid = (ok + ng) / 2;
            (check(l, mid+1) ? ok : ng) = mid;
        }
        // debug(l, ok);
        ans += ok-l;
    }

    cout << ans << endl;
}
0