提出 #71688193


ソースコード 拡げる

#include <bits/stdc++.h>
using namespace std;
const int maxn=5e5+5;
int a[maxn];
class BIT //树状数组
{
public:
    long long tr[maxn];
    int n;
    void init(int x) //清空并初始化
    {
        for (int i = 1; i <= x; i++)
            tr[i] = 0;
        n = x;
    }

    int lowbit(int x)
    {
        return x & -x;
    }

    void add(int x, long long d) //将第x个数+k
    {
        for (int i = x; i <= n; i += lowbit(i))
            tr[i] += d;
    }

    long long sum(int x) //求前x个数的和
    {
        long long ans = 0;
        for (int i = x; i; i -= lowbit(i))
            ans += tr[i];
        return ans;
    }
} tr;
int loc[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>a[i];
        loc[a[i]]=i;
    }
    tr.n=n;
    long long ans=0;
    for (int i=1;i<=n;i++)
    {
        long long l=tr.sum(loc[i]);
        long long r=i-l;
        l++;
        ans+=l*r;
        tr.add(loc[i],1);
    }
    cout<<ans;
}

提出情報

提出日時
問題 F - Starry Landscape Photo
ユーザ Alliy666
言語 C++23 (GCC 15.2.0)
得点 500
コード長 1129 Byte
結果 AC
実行時間 38 ms
メモリ 11500 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 500 / 500
結果
AC × 3
AC × 42
セット名 テストケース
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
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3496 KiB
00_sample_01.txt AC 1 ms 3532 KiB
00_sample_02.txt AC 1 ms 3548 KiB
01_random_03.txt AC 38 ms 11268 KiB
01_random_04.txt AC 36 ms 11500 KiB
01_random_05.txt AC 36 ms 11348 KiB
01_random_06.txt AC 37 ms 11408 KiB
01_random_07.txt AC 36 ms 11416 KiB
01_random_08.txt AC 37 ms 11340 KiB
01_random_09.txt AC 36 ms 11436 KiB
01_random_10.txt AC 37 ms 11340 KiB
01_random_11.txt AC 5 ms 4740 KiB
01_random_12.txt AC 36 ms 11268 KiB
01_random_13.txt AC 30 ms 10440 KiB
01_random_14.txt AC 26 ms 11340 KiB
01_random_15.txt AC 26 ms 11356 KiB
01_random_16.txt AC 26 ms 11392 KiB
01_random_17.txt AC 27 ms 11424 KiB
01_random_18.txt AC 27 ms 11332 KiB
01_random_19.txt AC 27 ms 11500 KiB
01_random_20.txt AC 27 ms 11340 KiB
01_random_21.txt AC 27 ms 11472 KiB
01_random_22.txt AC 28 ms 11332 KiB
01_random_23.txt AC 19 ms 9176 KiB
01_random_24.txt AC 8 ms 5840 KiB
01_random_25.txt AC 26 ms 11416 KiB
01_random_26.txt AC 9 ms 5892 KiB
01_random_27.txt AC 20 ms 9384 KiB
01_random_28.txt AC 6 ms 5084 KiB
01_random_29.txt AC 1 ms 3532 KiB
01_random_30.txt AC 1 ms 3628 KiB
01_random_31.txt AC 1 ms 3628 KiB
01_random_32.txt AC 1 ms 3424 KiB
01_random_33.txt AC 1 ms 3460 KiB
01_random_34.txt AC 1 ms 3428 KiB
01_random_35.txt AC 1 ms 3568 KiB
01_random_36.txt AC 1 ms 3540 KiB
01_random_37.txt AC 1 ms 3540 KiB
01_random_38.txt AC 22 ms 11348 KiB
01_random_39.txt AC 22 ms 11416 KiB
01_random_40.txt AC 22 ms 11340 KiB
01_random_41.txt AC 21 ms 11268 KiB