結果

問題 No.1619 Coccinellidae
ユーザー nok0nok0
提出日時 2021-07-06 20:46:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,096 bytes
コンパイル時間 2,046 ms
コンパイル使用メモリ 199,980 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-24 15:05:16
合計ジャッジ時間 5,231 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

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, m, k;
	cin >> n >> m >> k;
	BIT<int> BT(n);
	for(int i = 0; i < n; i++) BT.add(i, 1);

	vector<int> a(n), res(n);
	iota(a.begin(), a.end(), 0);
	a[n - 1] += m - (long long)n * (n - 1) / 2;

	for(int i = 0; i < n; i++) {
		int d = min(k, 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