QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#864029#9588. 可重集合AInfinity_DreamTL 68ms341940kbC++141.8kb2025-01-20 08:59:452025-01-20 08:59:46

Judging History

你现在查看的是最新测评结果

  • [2025-01-20 08:59:46]
  • 评测
  • 测评结果:TL
  • 用时:68ms
  • 内存:341940kb
  • [2025-01-20 08:59:45]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int n, tot, head, tmpans, ans[5009], total[20009], opt[500009], cur;
int o, x, mx;

bitset <500009> dp;

struct Operation {
	int l, r, x;
} op[5009];

struct Op {
	int id, x;
};

queue <int> g[500009];

vector <Op> d[20009];

void add(int s, int t, int p, int l, int r, int c) {
	if (l <= s && t <= r) {
		d[p].push_back((Op) {l, c});
		return;
	}
	int mid = (s + t) / 2;
	if (l <= mid) add(s, mid, p * 2, l, r, c);
	if (r > mid) add(mid + 1, t, p * 2 + 1, l, r, c);
}

void insert(Op val) {
	int count = 0;
	for (int i = head + val.x; i >= val.x; --i) {
		if (!dp[i] && dp[i - val.x]) tmpans++, dp[i] = 1, count++, opt[++cur] = i;
	}
	head = head + val.x, total[val.id] = count;
}

void del(Op val) {
	for (int i = 1; i <= total[val.id]; ++i) {
		dp[opt[cur--]] = 0, tmpans--;
	}
	head = head - val.x;
}

void process(int s, int t, int p) {
	for (int i = 0; i < d[p].size(); ++i) insert(d[p][i]);
	if (s == t) {
		ans[s] = tmpans;
	}
	else {
		int mid = (s + t) / 2;
		process(s, mid, p * 2), process(mid + 1, t, p * 2 + 1);
	}
	for (int i = d[p].size() - 1; i >= 0; --i) {
		del(d[p][i]);
	}
}

int main() {
	scanf("%d", &n);
	dp[0] = 1;
	for (int i = 1; i <= n; ++i) {
		scanf("%d %d", &o, &x);
		mx = max(mx, x);
		if (o == 1) g[x].push(i);
		if (o == 2) {
			op[++tot] = (Operation) {g[x].front(), i - 1, x};
			g[x].pop();
		}
	}
	for (int i = 1; i <= mx; ++i)
		while (!g[i].empty()) {
			op[++tot] = (Operation) {g[i].front(), n, i};
			g[i].pop();
		}

	for (int i = 1; i <= tot; ++i) {
		add(1, n, 1, op[i].l, op[i].r, op[i].x);
	}

	process(1, n, 1);

	for (int i = 1; i <= n; ++i) {
		printf("%d\n", ans[i]);
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 65ms
memory: 341940kb

input:

4
1 100
1 999
1 10
2 100

output:

1
3
7
3

result:

ok 4 lines

Test #2:

score: 0
Accepted
time: 68ms
memory: 341116kb

input:

7
1 1
1 2
1 1
1 4
1 5
2 1
2 4

output:

1
3
4
8
13
12
7

result:

ok 7 lines

Test #3:

score: -100
Time Limit Exceeded

input:

5000
1 132200
2 132200
1 304115
1 119865
1 7246
1 23773
1 6583
2 6583
2 119865
1 13380
1 38501
2 7246
1 115933
2 115933
1 52649
1 48334
1 2824
1 9919
2 2824
1 9007
1 309
2 304115
1 41830
2 9919
1 153380
1 100177
1 2775
2 13380
1 2913
1 16644
1 1437
2 9007
2 309
1 10921
1 1853
1 170
2 23773
1 561
1 2...

output:


result: