QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#864033 | #9588. 可重集合 | AInfinity_Dream | RE | 54ms | 340400kb | C++14 | 1.5kb | 2025-01-20 09:16:07 | 2025-01-20 09:16:07 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n, tot, head, tmpans, ans[5009];
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) {
for (int i = head + val.x; i >= val.x; --i) {
if (!dp[i] && dp[i - val.x]) tmpans++, dp[i] = 1;
}
head = head + val.x;
}
void process(int s, int t, int p) {
bitset <500009> tmp = dp;
int ttmpans = tmpans;
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);
}
dp = tmp, tmpans = ttmpans;
}
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: 54ms
memory: 340392kb
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: 51ms
memory: 340400kb
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
Runtime Error
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...