結果

問題 No.3269 Leq-K Partition
コンテスト
ユーザー apricity
提出日時 2025-08-07 21:27:27
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 495 ms / 6,000 ms
+ 729µs
コード長 1,297 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,359 ms
コンパイル使用メモリ 185,092 KB
実行使用メモリ 9,868 KB
最終ジャッジ日時 2026-10-24 10:49:43
合計ジャッジ時間 13,322 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 29
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i]; a[i]--;
    }


    auto calc = [&] (int k) {
        vector<bool> vis(n);
        int pre = 0;
        int res = 0;
        int distinct = k;
        for (int i = 0; i < n; i++) {
            if (not vis[a[i]]) {
                if (distinct == k) {
                    res++;
                    for (int j = pre; j < i; j++) vis[a[j]] = false;
                    distinct = 1;
                    pre = i;
                }
                else {
                    distinct++;
                }
                vis[a[i]] = true;
            }
        }
        return res;
    };

    vector<int> ans(n+1);
    int B = max(1, (int)sqrt(n * log2(n)));
    for (int i = 1; i < B; i++) ans[i] = calc(i);
    int q = (n+B-1)/B;
    for (int f = 1; f <= q; f++) {
        int ok = n;
        int ng = B-1;
        while (ok - ng > 1) {
            int mid = (ok + ng) / 2;
            if (calc(mid) <= f) ok = mid;
            else ng = mid;
        }
        for (int i = ok; i <= n and ans[i] == 0; i++) ans[i] = f;
    }
    for (int i = 1; i <= n; i++) cout << ans[i] << "\n";
}
0