結果

問題 No.1435 Mmm......
ユーザー maguroflymagurofly
提出日時 2021-03-19 23:36:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,628 bytes
コンパイル時間 950 ms
コンパイル使用メモリ 101,244 KB
実行使用メモリ 20,352 KB
最終ジャッジ日時 2024-04-29 19:33:55
合計ジャッジ時間 33,754 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 1,073 ms
18,816 KB
testcase_07 AC 1,341 ms
19,200 KB
testcase_08 AC 1,618 ms
19,904 KB
testcase_09 AC 1,420 ms
19,584 KB
testcase_10 AC 1,195 ms
19,036 KB
testcase_11 AC 1,184 ms
18,944 KB
testcase_12 AC 1,119 ms
18,816 KB
testcase_13 AC 1,082 ms
18,728 KB
testcase_14 AC 755 ms
11,764 KB
testcase_15 AC 1,641 ms
20,096 KB
testcase_16 AC 1,333 ms
19,272 KB
testcase_17 AC 921 ms
11,904 KB
testcase_18 AC 1,655 ms
20,204 KB
testcase_19 AC 1,147 ms
18,816 KB
testcase_20 AC 1,511 ms
19,716 KB
testcase_21 WA -
testcase_22 TLE -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, l, r) for (auto i = (l); i < (r); i++)
#define chmin(dest, src) if ((dest) > (src)) dest = (src)
#define chmax(dest, src) if ((dest) < (src)) dest = (src)
#include <iostream>
#include <vector>
#include <algorithm>
#include <atcoder/segtree>
using namespace std;
using namespace atcoder;
using ll = long long;
const ll INF = 1001001001001;

// a'[i] = N * a[i] + i
// a[i] = a'[i] / N

using S1 = pair<ll, ll>;
S1 op1(S1 x, S1 y) {
    vector<ll> xs{x.first, x.second, y.first, y.second};
    sort(xs.begin(), xs.end());
    unique(xs.begin(), xs.end());
    return {xs[0], xs[1]};
}
S1 e1() {
    return {INF, INF};
}

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

int main() {
    ll N; cin >> N;
    vector<S1> a1(N);
    vector<S2> a2(N);
    rep(i, 0, N) {
        int x; cin >> x;
        int y = x * N + i;
        a1[i] = {y, y};
        a2[i] = x;
    }
    segtree<S1, op1, e1> seg1(a1);
    segtree<S2, op2, e2> seg2(a2);
    
    ll ans = 0;
    rep(l, 0, N - 1) {
        ll ac = l + 2, wa = N + 1;
        while (ac + 1 < wa) {
            ll wj = (ac + wa) / 2;
            S1 x = seg1.prod(l, wj);
            ll m1 = x.first / N, m2 = x.second / N;
            S2 M = seg2.prod(l, wj);
            if (M <= m1 + m2) {
                ac = wj;
            } else {
                wa = wj;
            }
        }
        ll r = ac;
        S1 y = seg1.prod(l, r);
        ll m1 = y.first / N, m2 = y.second / N;
        S2 M = seg2.prod(l, r);
        if (M <= m1 + m2) {
          ans += r - l - 1;
        }
    }
    cout << ans << endl;
    return 0;
}
0