답안 #794616

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
794616 2023-07-26T16:30:10 Z adrilen 디지털 회로 (IOI22_circuit) C++17
100 / 100
932 ms 33264 KB
#include "circuit.h"
//#pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using arr = array<ll, 2>;
using arrr = array<int, 3>;

constexpr ll mod = 1e9 + 2022;
constexpr int maxn = 2e5;

void fmod(ll &val)
{
    if (val >= mod) val %= mod;
}

int n, m;
basic_string <int> children[maxn];


ll subtree[maxn] = { 0 }, vals[maxn];


ll find_subtree_vals(int p)
{
    ll v = children[p].size();
    for (int i : children[p])
    {
        v *= find_subtree_vals(i);
        fmod(v);
    }
    
    subtree[p] = v;
    if (v == 0) subtree[p] = 1;
    return subtree[p];
}



void get_vals(int p)
{
    int g = children[p].size();

    vector<ll> l(g + 1, vals[p]), r(g + 1, 1);



    for (int i = 1; i <= g; i++) {
        l[i] = l[i - 1] * subtree[children[p][i - 1]]; fmod(l[i]);
    }
    
    for (int i = g - 1; i >= 0; i--) {
        r[i] = r[i + 1] * subtree[children[p][i]]; fmod(r[i]);
    }

    // cout << "P" << p << " " << vals[p] << "\n";
    // for (int i : l) cout << i << " ";
    // cout << "\n";
    // for (int i : r) cout << i << " ";
    // cout << "\n";


    for (int i = 0; i < g; i++)
    {
        vals[children[p][i]] = l[i] * r[i + 1];
        fmod(vals[children[p][i]]);
    }

    for (int i : children[p]) get_vals(i);

}

constexpr int siz = 1 << 17;

arr segtree[siz * 2] = { 0 };
bool flipped[siz * 2] = { 0 };

arr merge(arr ap, arr bp)
{
    ap[0] += bp[0], ap[1] += bp[1];
    fmod(ap[0]), fmod(ap[1]);
    return ap;
}

void print()
{
    for (int i = 1; i < 2 * siz; i++)
    {
        if (__builtin_popcount(i) == 1) cout << "\n";
        cout << segtree[i][0] << " ";
    }
    cout << endl;
}


void init(int N, int M, std::vector<int> p, std::vector<int> a) {
    n = N, m = M;


    for (int i = 1; i < n + m; i++)
    {
        children[p[i]].push_back(i);
    }

    find_subtree_vals(0);
    vals[0] = 1;
    get_vals(0);

    // for (int i = 0; i < n + m; i++) cout << subtree[i] << " ";
    // cout << "\n";
    // for (int i = 0; i < n + m; i++) cout << vals[i] << " ";
    // cout << "\n";

    for (int i = 0; i < m; i++)
    {
        segtree[i + siz][1] = vals[i + n]; // Doesn't work with modulo
        if (a[i]) segtree[i + siz][0] = segtree[i + siz][1]; 
    }

    for (int i = siz - 1; i > 0; i--)
    {
        segtree[i] = merge(segtree[i * 2], segtree[i * 2 + 1]);
    }

}

void update(int p, int sl, int sr, int gl, int gr)
{
    if (flipped[p])
    {
        segtree[p][0] = segtree[p][1] - segtree[p][0];
        if (segtree[p][0] < 0) segtree[p][0] += mod;
        

        if (p < siz) flipped[p * 2] ^= 1, flipped[p * 2 + 1] ^= 1;
        flipped[p] ^= 1;
    }

    // cout << p << " " << sl << " " << sr << " " << gl << " " << gr << " \n";

    if (gl <= sl && sr <= gr) {
        segtree[p][0] = segtree[p][1] - segtree[p][0];
        if (segtree[p][0] < 0) segtree[p][0] += mod;


        if (p < siz) flipped[p * 2] ^= 1, flipped[p * 2 + 1] ^= 1;

        return ;
    }


    if (gl > sr || sl > gr) return ;

    int mid = (sl + sr) >> 1;

    update(p * 2, sl, mid, gl, gr);
    update(p * 2 + 1, mid + 1, sr, gl, gr);

    segtree[p] = merge(segtree[p * 2], segtree[p * 2 + 1]);
}



int count_ways(int L, int R) {
    update(1, 0, siz - 1, L - n, R - n);


    return segtree[1][0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8528 KB Output is correct
2 Correct 4 ms 8528 KB Output is correct
3 Correct 4 ms 8728 KB Output is correct
4 Correct 4 ms 8656 KB Output is correct
5 Correct 6 ms 8732 KB Output is correct
6 Correct 5 ms 8728 KB Output is correct
7 Correct 4 ms 8656 KB Output is correct
8 Correct 5 ms 8656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8528 KB Output is correct
2 Correct 4 ms 8660 KB Output is correct
3 Correct 4 ms 8656 KB Output is correct
4 Correct 4 ms 8656 KB Output is correct
5 Correct 4 ms 8656 KB Output is correct
6 Correct 5 ms 8784 KB Output is correct
7 Correct 5 ms 8688 KB Output is correct
8 Correct 5 ms 8656 KB Output is correct
9 Correct 5 ms 8656 KB Output is correct
10 Correct 5 ms 8784 KB Output is correct
11 Correct 4 ms 8784 KB Output is correct
12 Correct 4 ms 8656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8528 KB Output is correct
2 Correct 4 ms 8528 KB Output is correct
3 Correct 4 ms 8728 KB Output is correct
4 Correct 4 ms 8656 KB Output is correct
5 Correct 6 ms 8732 KB Output is correct
6 Correct 5 ms 8728 KB Output is correct
7 Correct 4 ms 8656 KB Output is correct
8 Correct 5 ms 8656 KB Output is correct
9 Correct 4 ms 8528 KB Output is correct
10 Correct 4 ms 8660 KB Output is correct
11 Correct 4 ms 8656 KB Output is correct
12 Correct 4 ms 8656 KB Output is correct
13 Correct 4 ms 8656 KB Output is correct
14 Correct 5 ms 8784 KB Output is correct
15 Correct 5 ms 8688 KB Output is correct
16 Correct 5 ms 8656 KB Output is correct
17 Correct 5 ms 8656 KB Output is correct
18 Correct 5 ms 8784 KB Output is correct
19 Correct 4 ms 8784 KB Output is correct
20 Correct 4 ms 8656 KB Output is correct
21 Correct 5 ms 8656 KB Output is correct
22 Correct 4 ms 8692 KB Output is correct
23 Correct 4 ms 8688 KB Output is correct
24 Correct 4 ms 8656 KB Output is correct
25 Correct 5 ms 8660 KB Output is correct
26 Correct 4 ms 8656 KB Output is correct
27 Correct 4 ms 8656 KB Output is correct
28 Correct 4 ms 8656 KB Output is correct
29 Correct 6 ms 8656 KB Output is correct
30 Correct 5 ms 8656 KB Output is correct
31 Correct 4 ms 8748 KB Output is correct
32 Correct 4 ms 8656 KB Output is correct
33 Correct 4 ms 8656 KB Output is correct
34 Correct 5 ms 8728 KB Output is correct
35 Correct 4 ms 8720 KB Output is correct
36 Correct 4 ms 8784 KB Output is correct
37 Correct 5 ms 8920 KB Output is correct
38 Correct 5 ms 8840 KB Output is correct
39 Correct 4 ms 8720 KB Output is correct
40 Correct 4 ms 8656 KB Output is correct
41 Correct 4 ms 8656 KB Output is correct
42 Correct 4 ms 8656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 537 ms 10912 KB Output is correct
2 Correct 744 ms 13212 KB Output is correct
3 Correct 775 ms 13220 KB Output is correct
4 Correct 668 ms 13212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 537 ms 10912 KB Output is correct
2 Correct 744 ms 13212 KB Output is correct
3 Correct 775 ms 13220 KB Output is correct
4 Correct 668 ms 13212 KB Output is correct
5 Correct 750 ms 10928 KB Output is correct
6 Correct 795 ms 13212 KB Output is correct
7 Correct 875 ms 13244 KB Output is correct
8 Correct 694 ms 13212 KB Output is correct
9 Correct 398 ms 8768 KB Output is correct
10 Correct 610 ms 8872 KB Output is correct
11 Correct 875 ms 8864 KB Output is correct
12 Correct 813 ms 8856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 8528 KB Output is correct
2 Correct 4 ms 8660 KB Output is correct
3 Correct 4 ms 8656 KB Output is correct
4 Correct 4 ms 8656 KB Output is correct
5 Correct 4 ms 8656 KB Output is correct
6 Correct 5 ms 8784 KB Output is correct
7 Correct 5 ms 8688 KB Output is correct
8 Correct 5 ms 8656 KB Output is correct
9 Correct 5 ms 8656 KB Output is correct
10 Correct 5 ms 8784 KB Output is correct
11 Correct 4 ms 8784 KB Output is correct
12 Correct 4 ms 8656 KB Output is correct
13 Correct 537 ms 10912 KB Output is correct
14 Correct 744 ms 13212 KB Output is correct
15 Correct 775 ms 13220 KB Output is correct
16 Correct 668 ms 13212 KB Output is correct
17 Correct 750 ms 10928 KB Output is correct
18 Correct 795 ms 13212 KB Output is correct
19 Correct 875 ms 13244 KB Output is correct
20 Correct 694 ms 13212 KB Output is correct
21 Correct 398 ms 8768 KB Output is correct
22 Correct 610 ms 8872 KB Output is correct
23 Correct 875 ms 8864 KB Output is correct
24 Correct 813 ms 8856 KB Output is correct
25 Correct 696 ms 15516 KB Output is correct
26 Correct 871 ms 15632 KB Output is correct
27 Correct 662 ms 15628 KB Output is correct
28 Correct 608 ms 15640 KB Output is correct
29 Correct 885 ms 32820 KB Output is correct
30 Correct 758 ms 32820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8528 KB Output is correct
2 Correct 4 ms 8528 KB Output is correct
3 Correct 4 ms 8728 KB Output is correct
4 Correct 4 ms 8656 KB Output is correct
5 Correct 6 ms 8732 KB Output is correct
6 Correct 5 ms 8728 KB Output is correct
7 Correct 4 ms 8656 KB Output is correct
8 Correct 5 ms 8656 KB Output is correct
9 Correct 4 ms 8528 KB Output is correct
10 Correct 4 ms 8660 KB Output is correct
11 Correct 4 ms 8656 KB Output is correct
12 Correct 4 ms 8656 KB Output is correct
13 Correct 4 ms 8656 KB Output is correct
14 Correct 5 ms 8784 KB Output is correct
15 Correct 5 ms 8688 KB Output is correct
16 Correct 5 ms 8656 KB Output is correct
17 Correct 5 ms 8656 KB Output is correct
18 Correct 5 ms 8784 KB Output is correct
19 Correct 4 ms 8784 KB Output is correct
20 Correct 4 ms 8656 KB Output is correct
21 Correct 5 ms 8656 KB Output is correct
22 Correct 4 ms 8692 KB Output is correct
23 Correct 4 ms 8688 KB Output is correct
24 Correct 4 ms 8656 KB Output is correct
25 Correct 5 ms 8660 KB Output is correct
26 Correct 4 ms 8656 KB Output is correct
27 Correct 4 ms 8656 KB Output is correct
28 Correct 4 ms 8656 KB Output is correct
29 Correct 6 ms 8656 KB Output is correct
30 Correct 5 ms 8656 KB Output is correct
31 Correct 4 ms 8748 KB Output is correct
32 Correct 4 ms 8656 KB Output is correct
33 Correct 4 ms 8656 KB Output is correct
34 Correct 5 ms 8728 KB Output is correct
35 Correct 4 ms 8720 KB Output is correct
36 Correct 4 ms 8784 KB Output is correct
37 Correct 5 ms 8920 KB Output is correct
38 Correct 5 ms 8840 KB Output is correct
39 Correct 4 ms 8720 KB Output is correct
40 Correct 4 ms 8656 KB Output is correct
41 Correct 4 ms 8656 KB Output is correct
42 Correct 4 ms 8656 KB Output is correct
43 Correct 641 ms 8784 KB Output is correct
44 Correct 674 ms 8868 KB Output is correct
45 Correct 801 ms 8788 KB Output is correct
46 Correct 688 ms 8912 KB Output is correct
47 Correct 702 ms 9040 KB Output is correct
48 Correct 582 ms 9040 KB Output is correct
49 Correct 737 ms 8988 KB Output is correct
50 Correct 699 ms 9040 KB Output is correct
51 Correct 681 ms 9000 KB Output is correct
52 Correct 732 ms 9008 KB Output is correct
53 Correct 642 ms 9512 KB Output is correct
54 Correct 809 ms 9012 KB Output is correct
55 Correct 693 ms 8936 KB Output is correct
56 Correct 768 ms 8912 KB Output is correct
57 Correct 674 ms 8912 KB Output is correct
58 Correct 661 ms 9808 KB Output is correct
59 Correct 676 ms 9928 KB Output is correct
60 Correct 861 ms 9936 KB Output is correct
61 Correct 852 ms 8992 KB Output is correct
62 Correct 822 ms 8776 KB Output is correct
63 Correct 680 ms 8864 KB Output is correct
64 Correct 836 ms 8864 KB Output is correct
65 Correct 403 ms 8784 KB Output is correct
66 Correct 735 ms 8912 KB Output is correct
67 Correct 741 ms 8848 KB Output is correct
68 Correct 651 ms 8864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 8528 KB Output is correct
2 Correct 4 ms 8528 KB Output is correct
3 Correct 4 ms 8728 KB Output is correct
4 Correct 4 ms 8656 KB Output is correct
5 Correct 6 ms 8732 KB Output is correct
6 Correct 5 ms 8728 KB Output is correct
7 Correct 4 ms 8656 KB Output is correct
8 Correct 5 ms 8656 KB Output is correct
9 Correct 4 ms 8528 KB Output is correct
10 Correct 4 ms 8660 KB Output is correct
11 Correct 4 ms 8656 KB Output is correct
12 Correct 4 ms 8656 KB Output is correct
13 Correct 4 ms 8656 KB Output is correct
14 Correct 5 ms 8784 KB Output is correct
15 Correct 5 ms 8688 KB Output is correct
16 Correct 5 ms 8656 KB Output is correct
17 Correct 5 ms 8656 KB Output is correct
18 Correct 5 ms 8784 KB Output is correct
19 Correct 4 ms 8784 KB Output is correct
20 Correct 4 ms 8656 KB Output is correct
21 Correct 5 ms 8656 KB Output is correct
22 Correct 4 ms 8692 KB Output is correct
23 Correct 4 ms 8688 KB Output is correct
24 Correct 4 ms 8656 KB Output is correct
25 Correct 5 ms 8660 KB Output is correct
26 Correct 4 ms 8656 KB Output is correct
27 Correct 4 ms 8656 KB Output is correct
28 Correct 4 ms 8656 KB Output is correct
29 Correct 6 ms 8656 KB Output is correct
30 Correct 5 ms 8656 KB Output is correct
31 Correct 4 ms 8748 KB Output is correct
32 Correct 4 ms 8656 KB Output is correct
33 Correct 4 ms 8656 KB Output is correct
34 Correct 5 ms 8728 KB Output is correct
35 Correct 4 ms 8720 KB Output is correct
36 Correct 4 ms 8784 KB Output is correct
37 Correct 5 ms 8920 KB Output is correct
38 Correct 5 ms 8840 KB Output is correct
39 Correct 4 ms 8720 KB Output is correct
40 Correct 4 ms 8656 KB Output is correct
41 Correct 4 ms 8656 KB Output is correct
42 Correct 4 ms 8656 KB Output is correct
43 Correct 537 ms 10912 KB Output is correct
44 Correct 744 ms 13212 KB Output is correct
45 Correct 775 ms 13220 KB Output is correct
46 Correct 668 ms 13212 KB Output is correct
47 Correct 750 ms 10928 KB Output is correct
48 Correct 795 ms 13212 KB Output is correct
49 Correct 875 ms 13244 KB Output is correct
50 Correct 694 ms 13212 KB Output is correct
51 Correct 398 ms 8768 KB Output is correct
52 Correct 610 ms 8872 KB Output is correct
53 Correct 875 ms 8864 KB Output is correct
54 Correct 813 ms 8856 KB Output is correct
55 Correct 696 ms 15516 KB Output is correct
56 Correct 871 ms 15632 KB Output is correct
57 Correct 662 ms 15628 KB Output is correct
58 Correct 608 ms 15640 KB Output is correct
59 Correct 885 ms 32820 KB Output is correct
60 Correct 758 ms 32820 KB Output is correct
61 Correct 641 ms 8784 KB Output is correct
62 Correct 674 ms 8868 KB Output is correct
63 Correct 801 ms 8788 KB Output is correct
64 Correct 688 ms 8912 KB Output is correct
65 Correct 702 ms 9040 KB Output is correct
66 Correct 582 ms 9040 KB Output is correct
67 Correct 737 ms 8988 KB Output is correct
68 Correct 699 ms 9040 KB Output is correct
69 Correct 681 ms 9000 KB Output is correct
70 Correct 732 ms 9008 KB Output is correct
71 Correct 642 ms 9512 KB Output is correct
72 Correct 809 ms 9012 KB Output is correct
73 Correct 693 ms 8936 KB Output is correct
74 Correct 768 ms 8912 KB Output is correct
75 Correct 674 ms 8912 KB Output is correct
76 Correct 661 ms 9808 KB Output is correct
77 Correct 676 ms 9928 KB Output is correct
78 Correct 861 ms 9936 KB Output is correct
79 Correct 852 ms 8992 KB Output is correct
80 Correct 822 ms 8776 KB Output is correct
81 Correct 680 ms 8864 KB Output is correct
82 Correct 836 ms 8864 KB Output is correct
83 Correct 403 ms 8784 KB Output is correct
84 Correct 735 ms 8912 KB Output is correct
85 Correct 741 ms 8848 KB Output is correct
86 Correct 651 ms 8864 KB Output is correct
87 Correct 4 ms 8528 KB Output is correct
88 Correct 492 ms 15124 KB Output is correct
89 Correct 607 ms 12772 KB Output is correct
90 Correct 841 ms 13000 KB Output is correct
91 Correct 684 ms 16200 KB Output is correct
92 Correct 873 ms 16184 KB Output is correct
93 Correct 839 ms 16284 KB Output is correct
94 Correct 932 ms 16156 KB Output is correct
95 Correct 748 ms 16276 KB Output is correct
96 Correct 681 ms 13840 KB Output is correct
97 Correct 801 ms 13840 KB Output is correct
98 Correct 549 ms 28104 KB Output is correct
99 Correct 783 ms 15644 KB Output is correct
100 Correct 764 ms 14488 KB Output is correct
101 Correct 790 ms 15048 KB Output is correct
102 Correct 616 ms 14020 KB Output is correct
103 Correct 691 ms 32820 KB Output is correct
104 Correct 824 ms 33248 KB Output is correct
105 Correct 707 ms 33264 KB Output is correct
106 Correct 650 ms 16280 KB Output is correct
107 Correct 646 ms 12872 KB Output is correct
108 Correct 870 ms 13336 KB Output is correct
109 Correct 849 ms 14024 KB Output is correct