提出 #69529102


ソースコード 拡げる

#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif

template <class T, class U = T> bool chmin(T& x, U&& y) { return y < x and (x = std::forward<U>(y), true); }

template <class T, class U = T> bool chmax(T& x, U&& y) { return x < y and (x = std::forward<U>(y), true); }

template <class T> void mkuni(std::vector<T>& v) {
    std::ranges::sort(v);
    auto result = std::ranges::unique(v);
    v.erase(result.begin(), result.end());
}

template <class T> int lwb(const std::vector<T>& v, const T& x) {
    return std::distance(v.begin(), std::ranges::lower_bound(v, x));
}

using namespace std;

using ll = long long;

void solve() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        A[i]--;
    }

    vector<vector<int>> pos(N);
    for (int i = 0; i < N; i++) {
        pos[A[i]].emplace_back(i);
    }
    ll ans = 1;
    for (auto& v : pos) {
        v.emplace_back(N);
        for (int i = 0, p = 0; i + 1 < int(v.size()); i++) {
            int cur = v[i], nxt = v[i + 1];
            if (nxt == cur + 1) {
                continue;
            }
            p++;
            ans += p * (nxt - cur - 1);
        }
    }

    cout << ans << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    solve();
    return 0;
}

提出情報

提出日時
問題 A - Range Replace
ユーザ rniya
言語 C++ 23 (gcc 12.2)
得点 400
コード長 1464 Byte
結果 AC
実行時間 220 ms
メモリ 65660 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 400 / 400
結果
AC × 2
AC × 35
セット名 テストケース
Sample 00_sample_00.txt, 00_sample_01.txt
All 00_sample_00.txt, 00_sample_01.txt, 01_random_00.txt, 01_random_01.txt, 01_random_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, 02_max_00.txt, 02_max_01.txt, 02_max_02.txt, 02_max_03.txt, 02_max_04.txt, 02_max_05.txt, 02_max_06.txt, 02_max_07.txt, 02_max_08.txt, 02_max_09.txt, 02_max_10.txt, 02_max_11.txt, 02_max_12.txt, 02_max_13.txt, 02_max_14.txt, 03_min_00.txt, 03_min_01.txt, 03_min_02.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3344 KiB
00_sample_01.txt AC 1 ms 3404 KiB
01_random_00.txt AC 68 ms 27024 KiB
01_random_01.txt AC 94 ms 35148 KiB
01_random_02.txt AC 89 ms 34628 KiB
01_random_03.txt AC 141 ms 46244 KiB
01_random_04.txt AC 161 ms 50340 KiB
01_random_05.txt AC 57 ms 24092 KiB
01_random_06.txt AC 72 ms 27372 KiB
01_random_07.txt AC 28 ms 14304 KiB
01_random_08.txt AC 21 ms 11152 KiB
01_random_09.txt AC 7 ms 5656 KiB
01_random_10.txt AC 184 ms 54648 KiB
01_random_11.txt AC 63 ms 26612 KiB
01_random_12.txt AC 12 ms 8232 KiB
01_random_13.txt AC 204 ms 59964 KiB
01_random_14.txt AC 14 ms 8656 KiB
02_max_00.txt AC 100 ms 61636 KiB
02_max_01.txt AC 75 ms 65328 KiB
02_max_02.txt AC 75 ms 65452 KiB
02_max_03.txt AC 96 ms 65660 KiB
02_max_04.txt AC 91 ms 65424 KiB
02_max_05.txt AC 92 ms 65452 KiB
02_max_06.txt AC 220 ms 61848 KiB
02_max_07.txt AC 214 ms 61868 KiB
02_max_08.txt AC 218 ms 61892 KiB
02_max_09.txt AC 206 ms 61892 KiB
02_max_10.txt AC 210 ms 61876 KiB
02_max_11.txt AC 204 ms 61896 KiB
02_max_12.txt AC 210 ms 61788 KiB
02_max_13.txt AC 213 ms 61816 KiB
02_max_14.txt AC 210 ms 61876 KiB
03_min_00.txt AC 1 ms 3380 KiB
03_min_01.txt AC 1 ms 3416 KiB
03_min_02.txt AC 1 ms 3380 KiB