結果

問題 No.1435 Mmm......
ユーザー maguroflymagurofly
提出日時 2021-03-19 23:35:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,625 bytes
コンパイル時間 1,090 ms
コンパイル使用メモリ 101,120 KB
実行使用メモリ 20,352 KB
最終ジャッジ日時 2024-04-29 19:32:30
合計ジャッジ時間 38,117 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1,194 ms
18,644 KB
testcase_07 AC 1,492 ms
19,328 KB
testcase_08 AC 1,776 ms
19,896 KB
testcase_09 AC 1,613 ms
19,584 KB
testcase_10 AC 1,371 ms
19,124 KB
testcase_11 AC 1,350 ms
18,816 KB
testcase_12 AC 1,237 ms
18,788 KB
testcase_13 AC 1,209 ms
18,688 KB
testcase_14 AC 870 ms
11,708 KB
testcase_15 AC 1,862 ms
20,096 KB
testcase_16 AC 1,507 ms
19,408 KB
testcase_17 AC 1,003 ms
12,032 KB
testcase_18 AC 1,874 ms
20,164 KB
testcase_19 AC 1,327 ms
18,876 KB
testcase_20 AC 1,699 ms
19,636 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 = 1001001001;

// 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