結果
| 問題 | No.1619 Coccinellidae | 
| コンテスト | |
| ユーザー |  nok0 | 
| 提出日時 | 2021-07-06 21:08:48 | 
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 21 ms / 2,000 ms | 
| コード長 | 1,132 bytes | 
| コンパイル時間 | 2,224 ms | 
| コンパイル使用メモリ | 196,268 KB | 
| 最終ジャッジ日時 | 2025-01-22 17:52:42 | 
| ジャッジサーバーID (参考情報) | judge2 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 16 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
template <typename T>
struct BIT {
private:
	int n, p;
	std::vector<T> d;
public:
	BIT(int n) : n(n), d(n + 1) {
		p = 1;
		while(p < n) p *= 2;
	}
	void add(int i, T x = 1) {
		for(i++; i <= n; i += i & -i) d[i] += x;
	}
	//return sum[0,i)
	T sum(int i) {
		T res = 0;
		for(; i; i -= i & -i) res += d[i];
		return res;
	}
	//return sum[l,r)
	T sum(int l, int r) { return sum(r) - sum(l); }
	//return min(x) which satisfies (v0 + v1 + ... + vx >= w)
	int lower_bound(T w) {
		if(w <= 0) return 0;
		T x = 0;
		for(int i = p; i; i /= 2) {
			if(i + x <= n && d[i + x] < w) {
				w -= d[i + x];
				x += i;
			}
		}
		return x;
	}
};
int main() {
	int n;
	long long m, k;
	cin >> n >> m >> k;
	BIT<int> BT(n);
	for(int i = 0; i < n; i++) BT.add(i, 1);
	vector<long long> a(n), res(n);
	iota(a.begin(), a.end(), 0ll);
	a[n - 1] += m - (long long)n * (n - 1) / 2;
	for(int i = 0; i < n; i++) {
		long long d = min(k, (long long)n - 1 - i);
		k -= d;
		int pl = BT.lower_bound(++d);
		BT.add(pl, -1);
		res[pl] = a[i];
	}
	for(const auto &v : res) cout << v << '\n';
	return 0;
}
            
            
            
        