結果

問題 No.1079 まお
ユーザー knshnbknshnb
提出日時 2020-06-13 17:30:00
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,524 bytes
コンパイル時間 2,310 ms
コンパイル使用メモリ 210,696 KB
実行使用メモリ 7,408 KB
最終ジャッジ日時 2023-09-07 22:10:18
合計ジャッジ時間 9,221 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 39 ms
4,380 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 AC 68 ms
4,376 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
 **/

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;
            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) continue;
                mi = std::min(mi, a[i]);
                while (j <= M && 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