結果

問題 No.1031 いたずら好きなお姉ちゃん
ユーザー knshnbknshnb
提出日時 2020-04-17 23:43:39
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 54 ms / 3,500 ms
コード長 1,989 bytes
コンパイル時間 2,185 ms
コンパイル使用メモリ 199,572 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-14 15:43:34
合計ジャッジ時間 6,017 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 4 ms
6,940 KB
testcase_04 AC 3 ms
6,940 KB
testcase_05 AC 4 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 3 ms
6,940 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 4 ms
6,944 KB
testcase_11 AC 40 ms
6,944 KB
testcase_12 AC 40 ms
6,940 KB
testcase_13 AC 48 ms
6,940 KB
testcase_14 AC 42 ms
6,944 KB
testcase_15 AC 45 ms
6,944 KB
testcase_16 AC 39 ms
6,944 KB
testcase_17 AC 45 ms
6,940 KB
testcase_18 AC 44 ms
6,944 KB
testcase_19 AC 46 ms
6,944 KB
testcase_20 AC 49 ms
6,940 KB
testcase_21 AC 45 ms
6,944 KB
testcase_22 AC 39 ms
6,940 KB
testcase_23 AC 41 ms
6,940 KB
testcase_24 AC 46 ms
6,944 KB
testcase_25 AC 47 ms
6,944 KB
testcase_26 AC 44 ms
6,940 KB
testcase_27 AC 42 ms
6,940 KB
testcase_28 AC 48 ms
6,940 KB
testcase_29 AC 49 ms
6,940 KB
testcase_30 AC 48 ms
6,944 KB
testcase_31 AC 48 ms
6,940 KB
testcase_32 AC 48 ms
6,944 KB
testcase_33 AC 49 ms
6,940 KB
testcase_34 AC 52 ms
6,944 KB
testcase_35 AC 50 ms
6,944 KB
testcase_36 AC 48 ms
6,944 KB
testcase_37 AC 50 ms
6,940 KB
testcase_38 AC 48 ms
6,940 KB
testcase_39 AC 46 ms
6,940 KB
testcase_40 AC 47 ms
6,944 KB
testcase_41 AC 48 ms
6,944 KB
testcase_42 AC 49 ms
6,940 KB
testcase_43 AC 45 ms
6,940 KB
testcase_44 AC 44 ms
6,940 KB
testcase_45 AC 43 ms
6,944 KB
testcase_46 AC 48 ms
6,940 KB
testcase_47 AC 50 ms
6,944 KB
testcase_48 AC 50 ms
6,940 KB
testcase_49 AC 50 ms
6,940 KB
testcase_50 AC 50 ms
6,940 KB
testcase_51 AC 54 ms
6,940 KB
testcase_52 AC 53 ms
6,944 KB
testcase_53 AC 53 ms
6,944 KB
testcase_54 AC 2 ms
6,944 KB
testcase_55 AC 2 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>  // clang-format off
using Int = long long;
#define REP_(i, a_, b_, a, b, ...) for (Int i = (a), lim##i = (b); i < lim##i; i++)
#define REP(i, ...) REP_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
struct SetupIO { SetupIO() { std::cin.tie(nullptr), std::ios::sync_with_stdio(false), std::cout << std::fixed << std::setprecision(13); } } setup_io;
#ifndef _MY_DEBUG
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Fri Apr 17 22:55:02 JST 2020
 **/

template <class T> inline bool chmin(T& a, const T& b) {
    if (a <= b) return false;
    a = b;
    return true;
}
template <class T> inline bool chmax(T& a, const T& b) {
    if (a >= b) return false;
    a = b;
    return true;
}

const Int INF = 1e9;
signed main() {
    Int n;
    std::cin >> n;
    std::vector<Int> a(n);
    REP(i, n) std::cin >> a[i];
    auto dfs = [&](auto f, Int s, Int t) -> Int {
        if (t - s <= 1) return 0;
        Int mid = (s + t) / 2;
        Int ret = f(f, s, mid) + f(f, mid, t);
        REP(_, 2) {
            std::vector<Int> mis(t - mid + 1, INF), mas(t - mid + 1, -INF), num(t - mid + 1);
            Int ma = -INF;
            REP(i, t - mid) {
                mis[i + 1] = std::min(mis[i], a[mid + i]);
                mas[i + 1] = std::max(mas[i], a[mid + i]);
                num[i + 1] = num[i] + chmax(ma, a[mid + i]);
            }
            Int cur_mi = INF, cur_ma = -INF;
            for (Int i = mid - 1; i >= s; i--) {
                chmax(cur_ma, a[i]);
                if (!chmin(cur_mi, a[i])) continue;
                Int it1 = std::lower_bound(mas.begin(), mas.end(), cur_ma) - mas.begin();
                Int it2 = std::lower_bound(mis.begin(), mis.end(), cur_mi, std::greater<Int>()) - mis.begin();
                ret += std::max(0LL, num[it2 - 1] - num[it1 - 1]);
            }
            REP(i, s, t) a[i] = -a[i];
        }
        return ret;
    };
    std::cout << dfs(dfs, 0, n) << std::endl;
}
0