QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#721972 | #9588. 可重集合 | Grenier | WA | 371ms | 7772kb | C++20 | 2.1kb | 2024-11-07 17:20:31 | 2024-11-07 17:20:33 |
Judging History
answer
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <unordered_map>
#include <vector>
#define int long long
typedef long long ll;
typedef double db;
typedef std::pair<int, int> PII;
const int N = 5e3, F = 5e5 + 5;
struct group {
int l, r;
std::vector<int> p;
} sgt[N * 4 + 2];
std::vector<int> op, ans;
std::vector<PII> itv;
std::map<int, int> mp;
void build(int u, int l, int r) {
if (l == r) {
sgt[u] = {l, r}; // 修改3
return;
}
sgt[u] = {l, r};
int mid = (l + r) >> 1;
build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
}
void deal(int u, int x, int l, int r) {
if (sgt[u].l >= l && sgt[u].r <= r) {
sgt[u].p.push_back(x);
return;
}
int mid = (sgt[u].l + sgt[u].r) >> 1;
if (l <= mid) deal(u << 1, x, l, r);
if (r > mid) deal(u << 1 | 1, x, l, r);
}
void dfs(int u, std::bitset<F> d) {
for (auto i : sgt[u].p) {
d |= (d << i);
}
if (sgt[u].l == sgt[u].r) {
ans.push_back(d.count() - 1); // 去掉0
return;
}
dfs(u << 1, d), dfs(u << 1 | 1, d);
}
void solve() {
int n;
mp.clear(), op.clear(), itv.clear(), ans.clear();
std::cin >> n;
for (int i = 1; i <= n; i++) {
int o, x;
std::cin >> o >> x;
if (o == 1) {
op.push_back(x);
mp[x] = op.size() - 1;
itv.push_back({i, n});
} else {
itv[mp[x]].second = i - 1;
}
}
build(1, 1, n);
for (int i = 0; i < (int)op.size(); i++) {
deal(1, op[i], itv[i].first, itv[i].second);
}
std::bitset<F> ini;
ini[0] = 1;
dfs(1, ini);
for (auto i : ans) std::cout << i << std::endl;
}
signed main() {
std::ios::sync_with_stdio(0);
std::cin.tie(0), std::cout.tie(0);
int times = 1;
// std::cin >> times;
while (times--) {
solve();
}
return 0;
}
/*
4
1 100
1 999
1 10
2 100
7
1 1
1 2
1 1
1 4
1 5
2 1
2 4
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 4920kb
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: 1ms
memory: 5052kb
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
Wrong Answer
time: 371ms
memory: 7772kb
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:
1 0 1 3 7 15 31 15 7 15 31 15 31 15 31 63 127 255 127 255 511 255 507 255 511 1023 2015 1007 2015 4031 8055 4031 2015 4031 7759 15515 7775 15387 30382 58433 108009 190146 111225 185051 285581 368440 423581 454204 396073 336717 213883 159845 245001 322194 254226 170951 93547 170423 268968 353531 4067...
result:
wrong answer 123rd lines differ - expected: '497093', found: '497118'