結果
| 問題 | No.1435 Mmm...... | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2021-03-19 22:38:31 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 877 ms / 2,000 ms | 
| コード長 | 2,975 bytes | 
| コンパイル時間 | 3,925 ms | 
| コンパイル使用メモリ | 202,244 KB | 
| 最終ジャッジ日時 | 2025-01-19 18:56:47 | 
| ジャッジサーバーID (参考情報) | judge4 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 4 | 
| other | AC * 24 | 
ソースコード
#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;
}
            
            
            
        