답안 #826265

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826265 2023-08-15T11:42:11 Z PixelCat 디지털 회로 (IOI22_circuit) C++17
100 / 100
942 ms 42404 KB
#include "circuit.h"

#ifdef NYAOWO
#include "stub.cpp"
#endif

#include <bits/stdc++.h>
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Forr(i, a, b) for(int i = a; i >= b; i--)
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sz(x) ((int)x.size())
#define eb emplace_back
#define int LL
using namespace std;
using i32 = int32_t;
using LL = long long;
using pii = pair<int, int>;

const int MAXN = 200'000;
const int MOD = 1'000'002'022;

#define L(id) ((id) * 2 + 1)
#define R(id) ((id) * 2 + 2)
struct SegTree {
    struct Node {
        bool flip;
        int dp1, sum;
    } a[MAXN * 4 + 10];
    void build(int id, int l, int r, int* A) {
        a[id].flip = 0;
        if(l == r) {
            a[id].sum = A[l];
            a[id].dp1 = 0;
            return;
        }
        int m = (l + r) / 2;
        build(L(id), l, m, A);
        build(R(id), m + 1, r, A);
        a[id].dp1 = (a[L(id)].dp1 + a[R(id)].dp1) % MOD;
        a[id].sum = (a[L(id)].sum + a[R(id)].sum) % MOD;
    }
    void range_flip(int id, int l, int r, int L, int R) {
        if(l >= L && r <= R) {
            a[id].flip ^= 1;
            a[id].dp1 = (a[id].sum - a[id].dp1) % MOD;
            return;
        }
        int m = (l + r) / 2;
        if(L <= m) range_flip(L(id), l, m, L, R);
        if(R > m)  range_flip(R(id), m + 1, r, L, R);
        a[id].dp1 = (a[L(id)].dp1 + a[R(id)].dp1) % MOD;
        if(a[id].flip) a[id].dp1 = (a[id].sum - a[id].dp1) % MOD;
    }
    int qry() {
        return (a[0].dp1 + MOD) % MOD;
    }
} seg;

int n, m;
vector<int> adj[MAXN + 10];
int p[MAXN + 10];
int a[MAXN + 10];

int s[MAXN + 10];

void dfs(int x) {
    if(x >= n) {
        s[x] = 1;
        return;
    }
    s[x] = sz(adj[x]);
    for(auto &i:adj[x]) {
        dfs(i);
        s[x] = s[x] * s[i] % MOD;
    }
}

int ss[MAXN + 10];
void dfs2(int x, int owo) {
    if(x >= n) {
        ss[x] = owo;
        return;
    }
    int c = sz(adj[x]);
    vector<int> pre(c), suf(c);
    pre[0] = s[adj[x][0]];
    For(i, 1, c - 1) pre[i] = pre[i - 1] * s[adj[x][i]] % MOD;
    suf[c - 1] = s[adj[x][c - 1]];
    Forr(i, c - 2, 0) suf[i] = suf[i + 1] * s[adj[x][i]] % MOD;
    For(i, 0, c - 1) {
        int uwu = owo;
        if(i) uwu = uwu * pre[i - 1] % MOD;
        if(i < c - 1) uwu = uwu * suf[i + 1] % MOD;
        dfs2(adj[x][i], uwu);
    }
}

// int ans = 0;
// void update_leaf(int pos, int val) {
//     ans = ((ans + val * ss[pos]) % MOD + MOD) % MOD;
// }

void init(i32 N, i32 M, std::vector<i32> P, std::vector<i32> A) {
    n = N; m = M;
    p[0] = -1;
    For(i, 1, n + m - 1) {
        adj[P[i]].eb(i);
        p[i] = P[i];
    }
    dfs(0);
    dfs2(0, 1);
    seg.build(0, n, n + m - 1, ss);
    For(i, 0, m - 1) {
        a[n + i] = A[i];
        if(A[i]) seg.range_flip(0, n, n + m - 1, n + i, n + i);
        // update_leaf(n + i, A[i]);
    }
}

i32 count_ways(i32 L, i32 R) {
    seg.range_flip(0, n, n + m - 1, L, R);
    return (i32) seg.qry();
    // int i = min(L, R);
    // int last = i;
    // int d = 1 - 2 * a[i];
    // a[i] += d;
    // update_leaf(i, d);
    // return (i32)ans;
}

/*

3 4 3
-1 0 1 2 1 1 0
1 0 1 0
3 4
4 5
3 6

2
0
6

*/
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5124 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 4 ms 5072 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 2 ms 5072 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5124 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 4 ms 5072 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 2 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 2 ms 5072 KB Output is correct
24 Correct 5 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 4 ms 5144 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 2 ms 5072 KB Output is correct
33 Correct 3 ms 5096 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 4 ms 5388 KB Output is correct
39 Correct 2 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 452 ms 9896 KB Output is correct
2 Correct 827 ms 14700 KB Output is correct
3 Correct 676 ms 14732 KB Output is correct
4 Correct 696 ms 14760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 452 ms 9896 KB Output is correct
2 Correct 827 ms 14700 KB Output is correct
3 Correct 676 ms 14732 KB Output is correct
4 Correct 696 ms 14760 KB Output is correct
5 Correct 712 ms 9884 KB Output is correct
6 Correct 743 ms 14752 KB Output is correct
7 Correct 942 ms 14724 KB Output is correct
8 Correct 845 ms 14744 KB Output is correct
9 Correct 414 ms 5336 KB Output is correct
10 Correct 701 ms 5584 KB Output is correct
11 Correct 774 ms 5584 KB Output is correct
12 Correct 561 ms 5584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 4 ms 5072 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 2 ms 5072 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 452 ms 9896 KB Output is correct
14 Correct 827 ms 14700 KB Output is correct
15 Correct 676 ms 14732 KB Output is correct
16 Correct 696 ms 14760 KB Output is correct
17 Correct 712 ms 9884 KB Output is correct
18 Correct 743 ms 14752 KB Output is correct
19 Correct 942 ms 14724 KB Output is correct
20 Correct 845 ms 14744 KB Output is correct
21 Correct 414 ms 5336 KB Output is correct
22 Correct 701 ms 5584 KB Output is correct
23 Correct 774 ms 5584 KB Output is correct
24 Correct 561 ms 5584 KB Output is correct
25 Correct 857 ms 21132 KB Output is correct
26 Correct 825 ms 21292 KB Output is correct
27 Correct 645 ms 21320 KB Output is correct
28 Correct 639 ms 21252 KB Output is correct
29 Correct 917 ms 41608 KB Output is correct
30 Correct 890 ms 41632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5124 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 4 ms 5072 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 2 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 2 ms 5072 KB Output is correct
24 Correct 5 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 4 ms 5144 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 2 ms 5072 KB Output is correct
33 Correct 3 ms 5096 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 4 ms 5388 KB Output is correct
39 Correct 2 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5052 KB Output is correct
43 Correct 450 ms 5456 KB Output is correct
44 Correct 681 ms 5456 KB Output is correct
45 Correct 713 ms 5456 KB Output is correct
46 Correct 665 ms 5840 KB Output is correct
47 Correct 718 ms 5928 KB Output is correct
48 Correct 665 ms 5840 KB Output is correct
49 Correct 538 ms 5840 KB Output is correct
50 Correct 575 ms 5840 KB Output is correct
51 Correct 693 ms 5768 KB Output is correct
52 Correct 691 ms 5772 KB Output is correct
53 Correct 468 ms 6224 KB Output is correct
54 Correct 654 ms 5840 KB Output is correct
55 Correct 695 ms 5840 KB Output is correct
56 Correct 647 ms 5712 KB Output is correct
57 Correct 880 ms 5712 KB Output is correct
58 Correct 670 ms 6864 KB Output is correct
59 Correct 634 ms 6992 KB Output is correct
60 Correct 665 ms 6992 KB Output is correct
61 Correct 610 ms 5712 KB Output is correct
62 Correct 666 ms 5456 KB Output is correct
63 Correct 705 ms 5456 KB Output is correct
64 Correct 751 ms 5676 KB Output is correct
65 Correct 445 ms 5328 KB Output is correct
66 Correct 520 ms 5584 KB Output is correct
67 Correct 817 ms 5584 KB Output is correct
68 Correct 690 ms 5584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 2 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5124 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 4 ms 5072 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 2 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 2 ms 5072 KB Output is correct
24 Correct 5 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 4 ms 5144 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 2 ms 5072 KB Output is correct
33 Correct 3 ms 5096 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 4 ms 5388 KB Output is correct
39 Correct 2 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5052 KB Output is correct
43 Correct 452 ms 9896 KB Output is correct
44 Correct 827 ms 14700 KB Output is correct
45 Correct 676 ms 14732 KB Output is correct
46 Correct 696 ms 14760 KB Output is correct
47 Correct 712 ms 9884 KB Output is correct
48 Correct 743 ms 14752 KB Output is correct
49 Correct 942 ms 14724 KB Output is correct
50 Correct 845 ms 14744 KB Output is correct
51 Correct 414 ms 5336 KB Output is correct
52 Correct 701 ms 5584 KB Output is correct
53 Correct 774 ms 5584 KB Output is correct
54 Correct 561 ms 5584 KB Output is correct
55 Correct 857 ms 21132 KB Output is correct
56 Correct 825 ms 21292 KB Output is correct
57 Correct 645 ms 21320 KB Output is correct
58 Correct 639 ms 21252 KB Output is correct
59 Correct 917 ms 41608 KB Output is correct
60 Correct 890 ms 41632 KB Output is correct
61 Correct 450 ms 5456 KB Output is correct
62 Correct 681 ms 5456 KB Output is correct
63 Correct 713 ms 5456 KB Output is correct
64 Correct 665 ms 5840 KB Output is correct
65 Correct 718 ms 5928 KB Output is correct
66 Correct 665 ms 5840 KB Output is correct
67 Correct 538 ms 5840 KB Output is correct
68 Correct 575 ms 5840 KB Output is correct
69 Correct 693 ms 5768 KB Output is correct
70 Correct 691 ms 5772 KB Output is correct
71 Correct 468 ms 6224 KB Output is correct
72 Correct 654 ms 5840 KB Output is correct
73 Correct 695 ms 5840 KB Output is correct
74 Correct 647 ms 5712 KB Output is correct
75 Correct 880 ms 5712 KB Output is correct
76 Correct 670 ms 6864 KB Output is correct
77 Correct 634 ms 6992 KB Output is correct
78 Correct 665 ms 6992 KB Output is correct
79 Correct 610 ms 5712 KB Output is correct
80 Correct 666 ms 5456 KB Output is correct
81 Correct 705 ms 5456 KB Output is correct
82 Correct 751 ms 5676 KB Output is correct
83 Correct 445 ms 5328 KB Output is correct
84 Correct 520 ms 5584 KB Output is correct
85 Correct 817 ms 5584 KB Output is correct
86 Correct 690 ms 5584 KB Output is correct
87 Correct 2 ms 4944 KB Output is correct
88 Correct 437 ms 20620 KB Output is correct
89 Correct 720 ms 14648 KB Output is correct
90 Correct 644 ms 14716 KB Output is correct
91 Correct 709 ms 21896 KB Output is correct
92 Correct 903 ms 21920 KB Output is correct
93 Correct 813 ms 21900 KB Output is correct
94 Correct 777 ms 21892 KB Output is correct
95 Correct 853 ms 21892 KB Output is correct
96 Correct 902 ms 16752 KB Output is correct
97 Correct 726 ms 16760 KB Output is correct
98 Correct 711 ms 30788 KB Output is correct
99 Correct 797 ms 21300 KB Output is correct
100 Correct 794 ms 19592 KB Output is correct
101 Correct 806 ms 18564 KB Output is correct
102 Correct 772 ms 16812 KB Output is correct
103 Correct 873 ms 41616 KB Output is correct
104 Correct 745 ms 42404 KB Output is correct
105 Correct 871 ms 42364 KB Output is correct
106 Correct 864 ms 18760 KB Output is correct
107 Correct 738 ms 16772 KB Output is correct
108 Correct 732 ms 17176 KB Output is correct
109 Correct 705 ms 17028 KB Output is correct