提出 #74677042


ソースコード 拡げる

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
long long n, k, a[500005], t[500005];
long long lowbit(long long x) { return x & -x; }
void update(long long x, long long v)
{
    while (x <= n)
    {
        t[x] += v;
        x += lowbit(x);
    }
}
long long query(long long x)
{
    long long res = 0;
    while (x)
    {
        res += t[x];
        x -= lowbit(x);
    }
    return res;
}
long long x, inv, ans, a1[500005], a2[500005], f[500005];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> k;
    for (long long i = 1; i <= n; i++)
        cin >> a[i];
    for (long long l = 1; l <= n; l++)
    {
        while (x < l)
        {
            x++;
            inv += query(n) - query(a[x]);
            update(a[x], 1);
        }
        while (x < n && inv < k)
        {
            x++;
            inv += query(n) - query(a[x]);
            update(a[x], 1);
        }
        if (inv >= k)
            a1[l] = x;
        else
            a1[l] = n + 1;
        f[l] = inv;
        inv -= query(a[l] - 1);
        update(a[l], -1);
    }
    x = 0, inv = 0;
    memset(t, 0, sizeof(t));
    for (long long l = 1; l <= n; l++)
    {
        while (x < l)
        {
            x++;
            inv += query(n) - query(a[x]);
            update(a[x], 1);
        }
        while (x < n && inv < k + 1)
        {
            x++;
            inv += query(n) - query(a[x]);
            update(a[x], 1);
        }
        if (inv >= k + 1)
            a2[l] = x;
        else
            a2[l] = n + 1;
        inv -= query(a[l] - 1);
        update(a[l], -1);
    }
    for (long long l = 1; l <= n; l++)
    {
        if (f[l] == k)
            ans += a2[l] - a1[l];
    }
    cout << ans << endl;
    return 0;
}

提出情報

提出日時
問題 F - Interval Inversion Count
ユーザ xzy404
言語 C++23 (GCC 15.2.0)
得点 500
コード長 1865 Byte
結果 AC
実行時間 95 ms
メモリ 23284 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 55
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt, 01_random_53.txt, 01_random_54.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 3 ms 7532 KiB
00_sample_01.txt AC 2 ms 7556 KiB
00_sample_02.txt AC 2 ms 7424 KiB
01_random_03.txt AC 49 ms 17284 KiB
01_random_04.txt AC 52 ms 17724 KiB
01_random_05.txt AC 27 ms 12928 KiB
01_random_06.txt AC 24 ms 12720 KiB
01_random_07.txt AC 39 ms 15484 KiB
01_random_08.txt AC 27 ms 13280 KiB
01_random_09.txt AC 30 ms 13716 KiB
01_random_10.txt AC 95 ms 22888 KiB
01_random_11.txt AC 94 ms 23084 KiB
01_random_12.txt AC 92 ms 23036 KiB
01_random_13.txt AC 89 ms 23028 KiB
01_random_14.txt AC 87 ms 23084 KiB
01_random_15.txt AC 91 ms 23112 KiB
01_random_16.txt AC 93 ms 23036 KiB
01_random_17.txt AC 90 ms 23040 KiB
01_random_18.txt AC 87 ms 23144 KiB
01_random_19.txt AC 93 ms 23028 KiB
01_random_20.txt AC 88 ms 23148 KiB
01_random_21.txt AC 91 ms 23100 KiB
01_random_22.txt AC 87 ms 23148 KiB
01_random_23.txt AC 93 ms 23028 KiB
01_random_24.txt AC 40 ms 23284 KiB
01_random_25.txt AC 46 ms 23172 KiB
01_random_26.txt AC 47 ms 23212 KiB
01_random_27.txt AC 42 ms 23120 KiB
01_random_28.txt AC 46 ms 23112 KiB
01_random_29.txt AC 47 ms 23284 KiB
01_random_30.txt AC 39 ms 23172 KiB
01_random_31.txt AC 72 ms 23084 KiB
01_random_32.txt AC 73 ms 23212 KiB
01_random_33.txt AC 73 ms 23084 KiB
01_random_34.txt AC 74 ms 23112 KiB
01_random_35.txt AC 74 ms 22992 KiB
01_random_36.txt AC 2 ms 7528 KiB
01_random_37.txt AC 41 ms 23040 KiB
01_random_38.txt AC 41 ms 23112 KiB
01_random_39.txt AC 40 ms 23112 KiB
01_random_40.txt AC 40 ms 23036 KiB
01_random_41.txt AC 41 ms 23028 KiB
01_random_42.txt AC 40 ms 23100 KiB
01_random_43.txt AC 40 ms 23148 KiB
01_random_44.txt AC 40 ms 23040 KiB
01_random_45.txt AC 41 ms 23176 KiB
01_random_46.txt AC 41 ms 23144 KiB
01_random_47.txt AC 41 ms 23028 KiB
01_random_48.txt AC 41 ms 23112 KiB
01_random_49.txt AC 41 ms 23172 KiB
01_random_50.txt AC 35 ms 20340 KiB
01_random_51.txt AC 35 ms 20400 KiB
01_random_52.txt AC 34 ms 20084 KiB
01_random_53.txt AC 34 ms 20348 KiB
01_random_54.txt AC 39 ms 21236 KiB