結果

問題 No.1031 いたずら好きなお姉ちゃん
ユーザー MisterMister
提出日時 2020-05-02 01:48:19
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 36 ms / 3,500 ms
コード長 1,623 bytes
コンパイル時間 974 ms
コンパイル使用メモリ 85,576 KB
実行使用メモリ 13,400 KB
最終ジャッジ日時 2023-08-26 20:14:23
合計ジャッジ時間 7,750 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 3 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 3 ms
4,384 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 3 ms
4,376 KB
testcase_11 AC 28 ms
10,908 KB
testcase_12 AC 28 ms
10,704 KB
testcase_13 AC 33 ms
12,544 KB
testcase_14 AC 29 ms
11,220 KB
testcase_15 AC 31 ms
12,076 KB
testcase_16 AC 26 ms
10,760 KB
testcase_17 AC 31 ms
12,064 KB
testcase_18 AC 29 ms
11,544 KB
testcase_19 AC 32 ms
12,224 KB
testcase_20 AC 33 ms
12,600 KB
testcase_21 AC 29 ms
11,528 KB
testcase_22 AC 27 ms
10,636 KB
testcase_23 AC 28 ms
10,956 KB
testcase_24 AC 33 ms
12,068 KB
testcase_25 AC 35 ms
12,300 KB
testcase_26 AC 29 ms
11,692 KB
testcase_27 AC 29 ms
11,272 KB
testcase_28 AC 33 ms
12,468 KB
testcase_29 AC 33 ms
12,568 KB
testcase_30 AC 33 ms
12,612 KB
testcase_31 AC 34 ms
12,516 KB
testcase_32 AC 33 ms
12,560 KB
testcase_33 AC 35 ms
12,608 KB
testcase_34 AC 33 ms
13,400 KB
testcase_35 AC 34 ms
12,932 KB
testcase_36 AC 34 ms
12,800 KB
testcase_37 AC 36 ms
12,928 KB
testcase_38 AC 35 ms
12,652 KB
testcase_39 AC 34 ms
12,544 KB
testcase_40 AC 35 ms
12,748 KB
testcase_41 AC 34 ms
12,728 KB
testcase_42 AC 35 ms
12,420 KB
testcase_43 AC 33 ms
12,556 KB
testcase_44 AC 32 ms
12,436 KB
testcase_45 AC 31 ms
12,080 KB
testcase_46 AC 34 ms
12,996 KB
testcase_47 AC 32 ms
12,664 KB
testcase_48 AC 34 ms
12,924 KB
testcase_49 AC 33 ms
12,844 KB
testcase_50 AC 33 ms
12,720 KB
testcase_51 AC 35 ms
12,848 KB
testcase_52 AC 34 ms
12,888 KB
testcase_53 AC 36 ms
13,016 KB
testcase_54 AC 1 ms
4,376 KB
testcase_55 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>

template <class T>
std::vector<T> vec(int len, T elem) { return std::vector<T>(len, elem); }

using lint = long long;

void solve() {
    int n;
    std::cin >> n;

    std::vector<int> xs(n);
    for (auto& x : xs) std::cin >> x;

    lint ans = 0;
    for (int q = 0; q < 2; ++q) {
        std::vector<int> to(n + 1, n), lim(n + 1, n);
        std::vector<std::pair<int, int>> ps;

        for (int i = 0; i < n; ++i) {
            while (!ps.empty() && ps.back().first < xs[i]) {
                to[ps.back().second] = i;
                ps.pop_back();
            }
            ps.emplace_back(xs[i], i);
        }
        ps.clear();

        for (int i = 0; i < n; ++i) {
            while (!ps.empty() && ps.back().first > xs[i]) {
                lim[ps.back().second] = i;
                ps.pop_back();
            }
            ps.emplace_back(xs[i], i);
        }

        auto tab = vec(20, vec(n + 1, n));
        tab[0] = to;
        for (int k = 1; k < 20; ++k) {
            for (int i = 0; i <= n; ++i) {
                tab[k][i] = tab[k - 1][tab[k - 1][i]];
            }
        }

        for (int i = 0; i < n; ++i) {
            int v = i;
            for (int k = 19; k >= 0; --k) {
                if (tab[k][v] < lim[i]) {
                    ans += (1 << k);
                    v = tab[k][v];
                }
            }
        }

        std::reverse(xs.begin(), xs.end());
    }

    std::cout << ans << std::endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0