結果

問題 No.1435 Mmm......
ユーザー hir355hir355
提出日時 2021-03-19 22:36:58
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 632 ms / 2,000 ms
コード長 2,259 bytes
コンパイル時間 2,405 ms
コンパイル使用メモリ 207,068 KB
実行使用メモリ 17,008 KB
最終ジャッジ日時 2023-08-12 03:14:33
合計ジャッジ時間 12,770 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 288 ms
16,352 KB
testcase_07 AC 350 ms
16,460 KB
testcase_08 AC 419 ms
16,824 KB
testcase_09 AC 386 ms
16,588 KB
testcase_10 AC 334 ms
16,368 KB
testcase_11 AC 329 ms
16,392 KB
testcase_12 AC 301 ms
16,400 KB
testcase_13 AC 293 ms
16,276 KB
testcase_14 AC 210 ms
10,036 KB
testcase_15 AC 435 ms
16,856 KB
testcase_16 AC 360 ms
16,468 KB
testcase_17 AC 238 ms
10,084 KB
testcase_18 AC 453 ms
16,756 KB
testcase_19 AC 311 ms
16,460 KB
testcase_20 AC 402 ms
16,628 KB
testcase_21 AC 632 ms
16,760 KB
testcase_22 AC 607 ms
16,840 KB
testcase_23 AC 450 ms
16,956 KB
testcase_24 AC 451 ms
16,876 KB
testcase_25 AC 458 ms
17,008 KB
testcase_26 AC 456 ms
16,796 KB
testcase_27 AC 464 ms
16,788 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/segtree>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
const long long INF_LL = 2000000000000000000LL;
const int INF = 2000000000;
const long long MOD = 1000000007;
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// typedef float double;
// typedef priority_queue prique;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vi> matrix;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}

struct edge {
    int to;
    ll cost;
    edge(int t, ll c) { to = t, cost = c; }
};

typedef vector<vector<edge>> graph;

// using mint = modint998244353;

P op1(P x, P y){
    if(x.first < y.first){
        if(x.second < y.first){
            return {x.first, x.second};
        }else{
            return {x.first, y.first};
        }
    }else{
        if(y.second < x.first){
            return {y.first, y.second};
        }else{
            return {y.first, x.first};
        }
    }
}
P e1(){return {INF, INF};}

ll op2(ll x, ll y){return max(x, y);}
ll e2(){return 0;}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vl a(n);
    rep(i, n) cin >> a[i];
    segtree<P, op1, e1> seg1(n);
    segtree<ll, op2, e2> seg2(a);
    ll ans = 0;
    rep(i, n){
        seg1.set(i, {a[i], INF_LL});
    }
    rep(i, n){
        int l = i, r = n + 1;
        while(r - l > 1){
            int m = (l + r) / 2;
            P tmp = seg1.prod(i, m);
            if(tmp.first + tmp.second >= seg2.prod(i, m)){
                l = m;
            }else{
                r = m;
            }
        }
        ans += l - i - 1;
    }
    cout << ans << endl;
    return 0;
}
0