跳到正文

题解

P3536 [POI2012]BON-Vouchers

Alex_Wei约 2 分钟
原文
文章信息与版本

文章信息

发布
2021年12月19日
收录
2026年9月26日
更新
2026年11月11日
篇幅
约 2 分钟
获赞
8
题目
P3536

版本

  1. v1当前

P3536 [POI2012]BON-Vouchers

POI 合集。

注意到对于一个固定的 xx,我们只关心前 max⁡bix\dfrac {\max b_i}x 个需求为 xx 的顾客,便可断言接下来需求为 xx 的顾客不可能拿到代金券,这一点显然。

因此,若当前需求为 xx 的顾客数量 cx>max⁡bixc_x>\dfrac{\max b_i}x,那么可以跳过剩下来所有这样的顾客。直接暴力模拟,时间复杂度是调和级数求和产生的 O(bln⁡b)\mathcal{O}(b\ln b),可以接受。

C++
const int N = 1e6 + 5;
int n, m, cnt, buc[N];
ll tot, ans[N], cur[N];
int main(){
	cin >> m;
	for(int i = 1; i <= m; i++) buc[read()] = 1;
	n = read();
	for(int i = 1; i <= n; i++) {
		int k = read();
		if(cur[k] * k >= N) {tot += k; continue;}
		int rest = k;
		while(rest) {
			int p = (++cur[k]) * k;
			if(p >= N) break;
			if(buc[p] == 1) ans[++cnt] = tot + k - rest + 1;
			if(buc[p] >= 0) buc[p] = -1, rest--;
		} tot += k;
	} cout << cnt << endl;
	for(int i = 1; i <= cnt; i++) print(ans[i]), pc('\n');
	return 0;
}
原文
存档评论2 条抓取于