結果

問題 No.1079 まお
ユーザー knshnbknshnb
提出日時 2020-06-13 17:50:57
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 432 ms / 2,000 ms
コード長 1,813 bytes
コンパイル時間 2,511 ms
コンパイル使用メモリ 210,464 KB
実行使用メモリ 10,444 KB
最終ジャッジ日時 2023-09-07 22:27:19
合計ジャッジ時間 10,494 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 3 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 4 ms
4,380 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 4 ms
4,380 KB
testcase_10 AC 4 ms
4,384 KB
testcase_11 AC 4 ms
4,384 KB
testcase_12 AC 184 ms
6,684 KB
testcase_13 AC 215 ms
7,180 KB
testcase_14 AC 265 ms
7,480 KB
testcase_15 AC 315 ms
8,456 KB
testcase_16 AC 360 ms
9,796 KB
testcase_17 AC 381 ms
7,764 KB
testcase_18 AC 375 ms
7,020 KB
testcase_19 AC 369 ms
7,128 KB
testcase_20 AC 370 ms
7,872 KB
testcase_21 AC 366 ms
7,532 KB
testcase_22 AC 392 ms
10,444 KB
testcase_23 AC 388 ms
10,048 KB
testcase_24 AC 432 ms
9,704 KB
testcase_25 AC 376 ms
9,868 KB
testcase_26 AC 391 ms
9,868 KB
testcase_27 AC 42 ms
4,380 KB
testcase_28 AC 191 ms
6,976 KB
testcase_29 AC 250 ms
6,948 KB
testcase_30 AC 260 ms
7,024 KB
testcase_31 AC 52 ms
4,384 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 dump
#define dump(...)
#endif  // clang-format on

/**
 *    author:  knshnb
 *    created: Sat Jun 13 17:03:51 JST 2020
 **/

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

signed main() {
    Int n, K;
    std::cin >> n >> K;
    std::vector<Int> a(n);
    REP(i, n) std::cin >> a[i];
    auto daq = [&](auto self, Int L, Int R) -> Int {
        if (R - L == 1) return 2 * a[L] == K;
        Int ret = self(self, L, (L + R) / 2) + self(self, (L + R) / 2, R);
        REP(t, 2) {
            Int M = (L + R + t) / 2;
            Int j = M;
            Int mi = 1e18;
            bool ng = false;
            std::unordered_map<Int, std::pair<Int, Int>> mp;  // {cnt, sum of index}
            for (Int i = M - 1; i >= L; i--) {
                if (a[i] == mi) ng = true;
                if (chmin(mi, a[i])) ng = false;
                if (ng) continue;
                mi = std::min(mi, a[i]);
                while (j < R && a[j] > mi) {
                    mp[a[j]].first++;
                    mp[a[j]].second += j - M + 1;
                    j++;
                }
                ret += mp[K - a[i]].first * (M - i) + mp[K - a[i]].second;
            }
            std::reverse(a.begin() + L, a.begin() + R);
        }
        return ret;
    };
    std::cout << daq(daq, 0, n) << std::endl;
}
0