結果

問題 No.1619 Coccinellidae
ユーザー nok0nok0
提出日時 2021-07-06 21:08:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 1,132 bytes
コンパイル時間 2,626 ms
コンパイル使用メモリ 203,028 KB
実行使用メモリ 4,808 KB
最終ジャッジ日時 2023-09-24 15:05:01
合計ジャッジ時間 4,946 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 15 ms
4,504 KB
testcase_02 AC 19 ms
4,756 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 20 ms
4,796 KB
testcase_05 AC 12 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 12 ms
4,376 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 11 ms
4,376 KB
testcase_11 AC 15 ms
4,384 KB
testcase_12 AC 2 ms
4,376 KB
testcase_13 AC 19 ms
4,808 KB
testcase_14 AC 19 ms
4,764 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0