编号 题目 状态 分数 总时间 内存 代码 / 答案文件 提交者 提交时间
#46916 #1017. JM的完美集合 Accepted 100 731 ms 4340 K C++ / 4.2 K 20183400682 2020-12-17 22:05:23
显示原始代码
#include <cstdio>
#include <cstdlib>
#define ll long long
#define maxn 300000
using namespace std;
ll a[40];
struct SplayTree {
    struct node {
        int lson, rson, father;
        ll val, cnt;
    } tree[maxn];
    int root, size;

private:
    void zig(int x) {
        int y = tree[x].father;
        tree[x].father = tree[y].father;
        if (tree[y].father)
            if (tree[tree[y].father].lson == y)
                tree[tree[y].father].lson = x;
            else
                tree[tree[y].father].rson = x;
        int z = tree[x].rson;
        tree[y].lson = z;
        if (z)
            tree[z].father = y;
        tree[y].father = x;
        tree[x].rson = y;
    }
    void zag(int x) {
        int y = tree[x].father;
        tree[x].father = tree[y].father;
        if (tree[y].father)
            if (tree[tree[y].father].lson == y)
                tree[tree[y].father].lson = x;
            else
                tree[tree[y].father].rson = x;
        int z = tree[x].lson;
        tree[y].rson = z;
        if (z)
            tree[z].father = y;
        tree[y].father = x;
        tree[x].lson = y;
    }
    void splay(int x) {
        while (tree[x].father) {
            int y = tree[x].father, z = tree[y].father;
            if (!z) {
                if (tree[y].lson == x)
                    zig(x);
                else
                    zag(x);
            } else {
                if (tree[z].lson == y && tree[y].lson == x) {
                    zig(y);
                    zig(x);
                } else if (tree[z].rson == y && tree[y].rson == x) {
                    zag(y);
                    zag(x);
                } else if (tree[z].lson == y && tree[y].rson == x) {
                    zag(x);
                    zig(x);
                } else {
                    zig(x);
                    zag(x);
                }
            }
        }
        root = x;
    }
    void insert(int pos, int x) {
        if (!root) {
            root = x;
            return;
        }
        if (tree[pos].val < tree[x].val) {
            if (tree[pos].rson)
                insert(tree[pos].rson, x);
            else {
                tree[pos].rson = x;
                tree[x].father = pos;
            }
        } else {
            if (tree[pos].lson)
                insert(tree[pos].lson, x);
            else {
                tree[pos].lson = x;
                tree[x].father = pos;
            }
        }
        return;
    }
    int build(ll x) {
        tree[++size].val = x;
        tree[size].cnt = 1;
        return size;
    }
    ll query(int pos, ll x) {
        if (!pos)
            return 0;
        if (tree[pos].val == x)
            return tree[pos].cnt;
        if (tree[pos].val < x)
            return query(tree[pos].rson, x);
        else
            return query(tree[pos].lson, x);
    }
    int find(int pos, ll x) {
        if (!pos)
            return 0;
        if (tree[pos].val == x)
            return pos;
        if (tree[pos].val < x)
            return find(tree[pos].rson, x);
        else
            return find(tree[pos].lson, x);
    }

public:
    void push(ll x) {
        int f = find(root, x);
        if (f)
            tree[f].cnt++;
        else
            insert(root, build(x));
    }
    ll count(ll x) { return query(root, x); }
    void clear() { size = root = 0; }
} s;
int main() {
    int n, t;
    ll ans = 0;
    scanf("%d", &n);
    for (register int i = 1; i <= n; ++i) {
        scanf("%lld", &a[i]);
    }
    s.clear();
    s.push(0);
    t = 1 << (n >> 1);
    for (register int i = 1; i < t; ++i) {
        ll sum = 0;
        for (register int j = 1; j <= n >> 1; ++j) {
            if ((1 << j - 1) & i)
                sum += a[j];
        }
        s.push(sum);
    }
    t = 1 << ((n + 1) >> 1);
    for (register int i = 0; i < t; ++i) {
        ll sum = 0;
        for (register int j = 1; j <= (n + 1) >> 1; ++j) {
            if ((1 << j - 1) & i)
                sum += a[n / 2 + j];
        }
        ans += s.count(-sum);
    }
    ans--;
    printf("%lld", ans);
    return 0;
}
子任务 #1
Accepted
得分:100
测试点 #1
Accepted
得分:100
用时:2 ms
内存:248 KiB

输入文件(1.in

5
1 5 -4 3 -1

答案文件(1.out

3

用户输出

3

系统信息

Exited with return code 0
测试点 #2
Accepted
得分:100
用时:2 ms
内存:248 KiB

输入文件(2.in

6
-1 2 2 5 5 -5

答案文件(2.out

2

用户输出

2

系统信息

Exited with return code 0
测试点 #3
Accepted
得分:100
用时:2 ms
内存:248 KiB

输入文件(3.in

10
5 -5 5 1 2 3 3 -1 3 1

答案文件(3.out

23

用户输出

23

系统信息

Exited with return code 0
测试点 #4
Accepted
得分:100
用时:1 ms
内存:248 KiB

输入文件(4.in

1
0

答案文件(4.out

1

用户输出

1

系统信息

Exited with return code 0
测试点 #5
Accepted
得分:100
用时:2 ms
内存:248 KiB

输入文件(5.in

4
1 4 -1 0

答案文件(5.out

3

用户输出

3

系统信息

Exited with return code 0
测试点 #6
Accepted
得分:100
用时:2 ms
内存:248 KiB

输入文件(6.in

3
0 0 0

答案文件(6.out

7

用户输出

7

系统信息

Exited with return code 0
测试点 #7
Accepted
得分:100
用时:13 ms
内存:376 KiB

输入文件(7.in

31
749 349 69 -880 282 -926 -831 225 988 552 -193 634 369 476 204 487 387 -803 -370 -975 -17 -485 3
<40 bytes omitted>

答案文件(7.out

520729

用户输出

520729

系统信息

Exited with return code 0
测试点 #8
Accepted
得分:100
用时:16 ms
内存:412 KiB

输入文件(8.in

31
362 -14 -181 -465 -400 -232 26 963 70 728 -728 -222 -510 854 139 386 555 994 103 279 213 76 953 
<36 bytes omitted>

答案文件(8.out

163619

用户输出

163619

系统信息

Exited with return code 0
测试点 #9
Accepted
得分:100
用时:7 ms
内存:276 KiB

输入文件(9.in

30
0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15

答案文件(9.out

32767

用户输出

32767

系统信息

Exited with return code 0
测试点 #10
Accepted
得分:100
用时:32 ms
内存:492 KiB

输入文件(10.in

34
-480 -519 50 980 136 511 821 -785 471 -781 -452 33 -828 -95 61 939 -372 -942 163 622 447 -48 -46
<51 bytes omitted>

答案文件(10.out

4162792

用户输出

4162792

系统信息

Exited with return code 0
测试点 #11
Accepted
得分:100
用时:84 ms
内存:4264 KiB

输入文件(11.in

34
48519807 -53389835 49483403 17212025 -35476527 29754885 -22197599 -15471042 20851481 -49606949 -
<219 bytes omitted>

答案文件(11.out

47

用户输出

47

系统信息

Exited with return code 0
测试点 #12
Accepted
得分:100
用时:23 ms
内存:1268 KiB

输入文件(12.in

31
58533164 -58898543 15918910 -44326927 -34936787 -22301908 -31391841 6479531 21841516 -39666628 5
<196 bytes omitted>

答案文件(12.out

9

用户输出

9

系统信息

Exited with return code 0
测试点 #13
Accepted
得分:100
用时:148 ms
内存:4340 KiB

输入文件(13.in

35
7230510 -11706249 -3304187 10122861 9546298 -4442935 -33084582 -27010272 -43066828 -38618779 126
<227 bytes omitted>

答案文件(13.out

148

用户输出

148

系统信息

Exited with return code 0
测试点 #14
Accepted
得分:100
用时:87 ms
内存:4340 KiB

输入文件(14.in

34
-41418109 33342962 -39042254 28956950 -426371 -52708040 27657595 13857069 -46409548 -4181307 -43
<221 bytes omitted>

答案文件(14.out

40

用户输出

40

系统信息

Exited with return code 0
测试点 #15
Accepted
得分:100
用时:16 ms
内存:1268 KiB

输入文件(15.in

30
12891648 42473494 8187791 31646680 15117362 21049429 -5219011 -3836405 51563712 -23453243 493559
<181 bytes omitted>

答案文件(15.out

1

用户输出

1

系统信息

Exited with return code 0
测试点 #16
Accepted
得分:100
用时:37 ms
内存:2312 KiB

输入文件(16.in

32
14064413 50585082 19765257 2999136 24894051 -42290511 20154916 -23633481 -46140190 -22836277 -14
<204 bytes omitted>

答案文件(16.out

21

用户输出

21

系统信息

Exited with return code 0
测试点 #17
Accepted
得分:100
用时:86 ms
内存:4340 KiB

输入文件(17.in

34
-36585710 20358839 52054688 6497673 -20688047 16346134 -31405363 -32737212 -53397594 -44921061 -
<222 bytes omitted>

答案文件(17.out

57

用户输出

57

系统信息

Exited with return code 0
测试点 #18
Accepted
得分:100
用时:123 ms
内存:4296 KiB

输入文件(18.in

35
16603843 -45892403 -45886820 -44441674 40785156 19628683 47358422 -19887459 38501762 -57319125 -
<233 bytes omitted>

答案文件(18.out

105

用户输出

105

系统信息

Exited with return code 0
测试点 #19
Accepted
得分:100
用时:16 ms
内存:1268 KiB

输入文件(19.in

30
20140884 51573053 -52691015 -23126027 42246059 55981176 42361277 25020920 58763999 41810806 -376
<185 bytes omitted>

答案文件(19.out

3

用户输出

3

系统信息

Exited with return code 0
测试点 #20
Accepted
得分:100
用时:32 ms
内存:272 KiB

输入文件(20.in

35
-10000000 -20000000 0 20000000 30000000 40000000 -40000000 -60000000 10000000 -20000000 -4000000
<225 bytes omitted>

答案文件(20.out

828283647

用户输出

828283647

系统信息

Exited with return code 0