提出 #71691531


ソースコード 拡げる

// Problem: F - Starry Landscape Photo
// Contest: AtCoder - AtCoder Beginner Contest 436
// URL: https://atcoder.jp/contests/abc436/tasks/abc436_f
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize(2)
/*i32 : -2e9~2e9
i64: -9e18~9e18
u64: 0~1.8e19*/
using i64 = long long;
using u64 = unsigned long long;
#define dbg(A) cout << #A << "==" << A << '\n';
#define all(A) A.begin(), A.end()
#define int long long

const int MAXN = 5E5 + 5, MOD = 1E9 + 7, INF = 1E18;

int n, m, t, ar[MAXN], ans, cnt, k;
int tree[MAXN];
auto add = [](int i, int v) {
    for (; i <= n; i += i & -i) tree[i] += v;
};
auto qry = [](int i, int res = 0) {
    for (; i >= 1; i -= i & -i) res += tree[i];
    return res;
};

void solve() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> ar[i];
    vector<int> pos(n + 1);
    for (int i = 1; i <= n; i++) pos[ar[i]] = i;
    for (int i = 1; i <= n; i++) {
        int mn = qry(pos[i] - 1), mx = i - mn;
        ans += (mn + 1) * mx;
        add(pos[i], 1);
    }
    cout << ans << '\n';
}

signed main() {
    ios::sync_with_stdio(false), cin.tie(0);
    int times = 1;  // cin >> times;
    while (times--) solve();
    return 0;
}

提出情報

提出日時
問題 F - Starry Landscape Photo
ユーザ unaptx4869
言語 C++23 (GCC 15.2.0)
得点 500
コード長 1334 Byte
結果 AC
実行時間 45 ms
メモリ 15152 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 2 ms 3564 KiB
00_sample_01.txt AC 1 ms 3532 KiB
00_sample_02.txt AC 1 ms 3576 KiB
01_random_03.txt AC 44 ms 15068 KiB
01_random_04.txt AC 44 ms 15044 KiB
01_random_05.txt AC 45 ms 15000 KiB
01_random_06.txt AC 44 ms 15040 KiB
01_random_07.txt AC 45 ms 15152 KiB
01_random_08.txt AC 45 ms 15108 KiB
01_random_09.txt AC 45 ms 15152 KiB
01_random_10.txt AC 44 ms 15072 KiB
01_random_11.txt AC 6 ms 5252 KiB
01_random_12.txt AC 44 ms 14872 KiB
01_random_13.txt AC 38 ms 13660 KiB
01_random_14.txt AC 32 ms 15044 KiB
01_random_15.txt AC 32 ms 15152 KiB
01_random_16.txt AC 31 ms 15040 KiB
01_random_17.txt AC 32 ms 15068 KiB
01_random_18.txt AC 32 ms 15096 KiB
01_random_19.txt AC 32 ms 15068 KiB
01_random_20.txt AC 32 ms 14916 KiB
01_random_21.txt AC 32 ms 15000 KiB
01_random_22.txt AC 35 ms 15000 KiB
01_random_23.txt AC 23 ms 11588 KiB
01_random_24.txt AC 10 ms 6744 KiB
01_random_25.txt AC 31 ms 15024 KiB
01_random_26.txt AC 11 ms 7020 KiB
01_random_27.txt AC 25 ms 12128 KiB
01_random_28.txt AC 7 ms 5484 KiB
01_random_29.txt AC 1 ms 3576 KiB
01_random_30.txt AC 1 ms 3440 KiB
01_random_31.txt AC 1 ms 3588 KiB
01_random_32.txt AC 1 ms 3440 KiB
01_random_33.txt AC 1 ms 3440 KiB
01_random_34.txt AC 1 ms 3468 KiB
01_random_35.txt AC 1 ms 3576 KiB
01_random_36.txt AC 1 ms 3468 KiB
01_random_37.txt AC 1 ms 3576 KiB
01_random_38.txt AC 28 ms 15000 KiB
01_random_39.txt AC 28 ms 15068 KiB
01_random_40.txt AC 27 ms 15072 KiB
01_random_41.txt AC 27 ms 15036 KiB