結果

問題 No.1110 好きな歌
ユーザー CELICACELICA
提出日時 2020-07-17 19:41:28
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 700 ms / 5,000 ms
コード長 1,423 bytes
コンパイル時間 2,202 ms
コンパイル使用メモリ 173,340 KB
実行使用メモリ 42,224 KB
最終ジャッジ日時 2023-08-19 19:41:12
合計ジャッジ時間 20,337 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,388 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
testcase_14 AC 2 ms
4,376 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 3 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 3 ms
4,384 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 332 ms
26,540 KB
testcase_25 AC 416 ms
31,024 KB
testcase_26 AC 207 ms
17,612 KB
testcase_27 AC 423 ms
30,884 KB
testcase_28 AC 199 ms
19,160 KB
testcase_29 AC 554 ms
35,252 KB
testcase_30 AC 167 ms
19,144 KB
testcase_31 AC 105 ms
12,952 KB
testcase_32 AC 589 ms
39,052 KB
testcase_33 AC 178 ms
21,836 KB
testcase_34 AC 312 ms
28,120 KB
testcase_35 AC 483 ms
42,216 KB
testcase_36 AC 32 ms
7,564 KB
testcase_37 AC 135 ms
13,916 KB
testcase_38 AC 525 ms
34,728 KB
testcase_39 AC 361 ms
26,836 KB
testcase_40 AC 336 ms
33,920 KB
testcase_41 AC 22 ms
5,808 KB
testcase_42 AC 448 ms
38,264 KB
testcase_43 AC 507 ms
34,928 KB
testcase_44 AC 534 ms
42,168 KB
testcase_45 AC 621 ms
42,104 KB
testcase_46 AC 604 ms
42,224 KB
testcase_47 AC 670 ms
42,116 KB
testcase_48 AC 604 ms
42,220 KB
testcase_49 AC 420 ms
42,112 KB
testcase_50 AC 598 ms
42,108 KB
testcase_51 AC 589 ms
42,216 KB
testcase_52 AC 646 ms
42,220 KB
testcase_53 AC 700 ms
42,108 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

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

    ll n, d;
    scanf("%lld%lld", &n, &d);

    if (n < 2)
    {
        printf("0\n");
        return 0;
    }

    map<ll, ll> m;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i)
    {
        ll ai;
        scanf("%lld", &ai);
        a[i] = ai;
        ++m[ai];
    }

    map<ll, ll> mconv;
    for (const auto& im : m)
    {
        if (im.first <= d)
        {
            mconv[im.first] = 0;
            continue;
        }
        auto iml = m.upper_bound(im.first - d);
        if (iml != m.begin())
            mconv[im.first] = (--iml)->first;
    }

    map<ll, ll> mc;
    ll prev{ m.begin()->first };
    for (const auto& im : m)
    {
        mc[im.first] = 0;
        if (im.first == m.begin()->first)
            continue;
        else if (im.first <= d)
        {
            prev = im.first;
            continue;
        }

        mc[im.first] = mc[prev];
        auto iml = m.upper_bound(mconv[prev]);
        auto imr = m.upper_bound(mconv[im.first]);
        for (auto imt = iml;
            imt != imr;
            ++imt)
        {
            mc[im.first] += imt->second;
        }
        
        prev = im.first;
    }

    ll res;
    for (int i = 0; i < n; ++i)
    {
        res = mc[a[i]];
        printf("%lld\n", res);
    }

    return 0;
}
0