QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#721802#9588. 可重集合GrenierWA 369ms84232kbC++202.2kb2024-11-07 16:54:022024-11-07 16:54:03

Judging History

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

  • [2024-11-07 16:54:03]
  • 评测
  • 测评结果:WA
  • 用时:369ms
  • 内存:84232kb
  • [2024-11-07 16:54:02]
  • 提交

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 = 5e5;
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<500001> d) {
    std::bitset<500001> ls;
    for (auto i : sgt[u].p) {
        ls = d;
        ls <<= i;
        d |= ls;
    }
    if (sgt[u].l == sgt[u].r) {
        ans.push_back(d.count());
        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<500001> ini;
    ini[0] = 1;
    dfs(1, ini);
    for (auto i : ans) std::cout << i - 1 << 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

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 82080kb

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: 12ms
memory: 82260kb

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: 369ms
memory: 84232kb

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'