답안 #826255

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
826255 2023-08-15T11:35:13 Z PixelCat 디지털 회로 (IOI22_circuit) C++17
89 / 100
3000 ms 27556 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;
    }
    for(auto &i:adj[x]) {
        int uwu = owo;
        for(auto &j:adj[x]) if(j != i) {
            uwu = (uwu * s[j]) % MOD;
        }
        dfs2(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 2 ms 4944 KB Output is correct
3 Correct 7 ms 5116 KB Output is correct
4 Correct 7 ms 5072 KB Output is correct
5 Correct 7 ms 5072 KB Output is correct
6 Correct 7 ms 5072 KB Output is correct
7 Correct 6 ms 5072 KB Output is correct
8 Correct 7 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 3 ms 5160 KB Output is correct
8 Correct 3 ms 5172 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5220 KB Output is correct
11 Correct 2 ms 5200 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 2 ms 4944 KB Output is correct
3 Correct 7 ms 5116 KB Output is correct
4 Correct 7 ms 5072 KB Output is correct
5 Correct 7 ms 5072 KB Output is correct
6 Correct 7 ms 5072 KB Output is correct
7 Correct 6 ms 5072 KB Output is correct
8 Correct 7 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 2 ms 5072 KB Output is correct
14 Correct 2 ms 5072 KB Output is correct
15 Correct 3 ms 5160 KB Output is correct
16 Correct 3 ms 5172 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5220 KB Output is correct
19 Correct 2 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 2 ms 5072 KB Output is correct
24 Correct 3 ms 5120 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 7 ms 5072 KB Output is correct
30 Correct 8 ms 5072 KB Output is correct
31 Correct 2 ms 5072 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 4 ms 5072 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 7 ms 5200 KB Output is correct
38 Correct 7 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5092 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 507 ms 9804 KB Output is correct
2 Correct 668 ms 14664 KB Output is correct
3 Correct 680 ms 14668 KB Output is correct
4 Correct 530 ms 14728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 507 ms 9804 KB Output is correct
2 Correct 668 ms 14664 KB Output is correct
3 Correct 680 ms 14668 KB Output is correct
4 Correct 530 ms 14728 KB Output is correct
5 Correct 700 ms 9872 KB Output is correct
6 Correct 899 ms 14724 KB Output is correct
7 Correct 622 ms 14664 KB Output is correct
8 Correct 789 ms 14744 KB Output is correct
9 Correct 295 ms 5328 KB Output is correct
10 Correct 587 ms 5584 KB Output is correct
11 Correct 758 ms 5584 KB Output is correct
12 Correct 742 ms 5632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 ms 5072 KB Output is correct
7 Correct 3 ms 5160 KB Output is correct
8 Correct 3 ms 5172 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5220 KB Output is correct
11 Correct 2 ms 5200 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 507 ms 9804 KB Output is correct
14 Correct 668 ms 14664 KB Output is correct
15 Correct 680 ms 14668 KB Output is correct
16 Correct 530 ms 14728 KB Output is correct
17 Correct 700 ms 9872 KB Output is correct
18 Correct 899 ms 14724 KB Output is correct
19 Correct 622 ms 14664 KB Output is correct
20 Correct 789 ms 14744 KB Output is correct
21 Correct 295 ms 5328 KB Output is correct
22 Correct 587 ms 5584 KB Output is correct
23 Correct 758 ms 5584 KB Output is correct
24 Correct 742 ms 5632 KB Output is correct
25 Correct 853 ms 21140 KB Output is correct
26 Correct 1153 ms 21304 KB Output is correct
27 Correct 721 ms 21292 KB Output is correct
28 Correct 714 ms 21324 KB Output is correct
29 Correct 1121 ms 27556 KB Output is correct
30 Correct 868 ms 27508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 7 ms 5116 KB Output is correct
4 Correct 7 ms 5072 KB Output is correct
5 Correct 7 ms 5072 KB Output is correct
6 Correct 7 ms 5072 KB Output is correct
7 Correct 6 ms 5072 KB Output is correct
8 Correct 7 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 2 ms 5072 KB Output is correct
14 Correct 2 ms 5072 KB Output is correct
15 Correct 3 ms 5160 KB Output is correct
16 Correct 3 ms 5172 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5220 KB Output is correct
19 Correct 2 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 2 ms 5072 KB Output is correct
24 Correct 3 ms 5120 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 7 ms 5072 KB Output is correct
30 Correct 8 ms 5072 KB Output is correct
31 Correct 2 ms 5072 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 4 ms 5072 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 7 ms 5200 KB Output is correct
38 Correct 7 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5092 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 443 ms 5516 KB Output is correct
44 Correct 844 ms 5456 KB Output is correct
45 Correct 812 ms 5456 KB Output is correct
46 Correct 819 ms 5836 KB Output is correct
47 Correct 627 ms 5840 KB Output is correct
48 Correct 844 ms 5840 KB Output is correct
49 Correct 941 ms 5840 KB Output is correct
50 Correct 724 ms 5840 KB Output is correct
51 Correct 705 ms 5740 KB Output is correct
52 Correct 769 ms 5736 KB Output is correct
53 Correct 849 ms 5584 KB Output is correct
54 Correct 929 ms 5896 KB Output is correct
55 Correct 574 ms 5712 KB Output is correct
56 Correct 774 ms 5712 KB Output is correct
57 Correct 673 ms 5584 KB Output is correct
58 Correct 701 ms 6224 KB Output is correct
59 Correct 614 ms 6368 KB Output is correct
60 Correct 644 ms 6312 KB Output is correct
61 Correct 721 ms 5584 KB Output is correct
62 Correct 687 ms 5456 KB Output is correct
63 Correct 625 ms 5456 KB Output is correct
64 Correct 624 ms 5712 KB Output is correct
65 Correct 329 ms 5328 KB Output is correct
66 Correct 758 ms 5556 KB Output is correct
67 Correct 731 ms 5584 KB Output is correct
68 Correct 562 ms 5584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 7 ms 5116 KB Output is correct
4 Correct 7 ms 5072 KB Output is correct
5 Correct 7 ms 5072 KB Output is correct
6 Correct 7 ms 5072 KB Output is correct
7 Correct 6 ms 5072 KB Output is correct
8 Correct 7 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 2 ms 5072 KB Output is correct
14 Correct 2 ms 5072 KB Output is correct
15 Correct 3 ms 5160 KB Output is correct
16 Correct 3 ms 5172 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5220 KB Output is correct
19 Correct 2 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 2 ms 5072 KB Output is correct
24 Correct 3 ms 5120 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 7 ms 5072 KB Output is correct
30 Correct 8 ms 5072 KB Output is correct
31 Correct 2 ms 5072 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 4 ms 5072 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 7 ms 5200 KB Output is correct
38 Correct 7 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5092 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 507 ms 9804 KB Output is correct
44 Correct 668 ms 14664 KB Output is correct
45 Correct 680 ms 14668 KB Output is correct
46 Correct 530 ms 14728 KB Output is correct
47 Correct 700 ms 9872 KB Output is correct
48 Correct 899 ms 14724 KB Output is correct
49 Correct 622 ms 14664 KB Output is correct
50 Correct 789 ms 14744 KB Output is correct
51 Correct 295 ms 5328 KB Output is correct
52 Correct 587 ms 5584 KB Output is correct
53 Correct 758 ms 5584 KB Output is correct
54 Correct 742 ms 5632 KB Output is correct
55 Correct 853 ms 21140 KB Output is correct
56 Correct 1153 ms 21304 KB Output is correct
57 Correct 721 ms 21292 KB Output is correct
58 Correct 714 ms 21324 KB Output is correct
59 Correct 1121 ms 27556 KB Output is correct
60 Correct 868 ms 27508 KB Output is correct
61 Correct 443 ms 5516 KB Output is correct
62 Correct 844 ms 5456 KB Output is correct
63 Correct 812 ms 5456 KB Output is correct
64 Correct 819 ms 5836 KB Output is correct
65 Correct 627 ms 5840 KB Output is correct
66 Correct 844 ms 5840 KB Output is correct
67 Correct 941 ms 5840 KB Output is correct
68 Correct 724 ms 5840 KB Output is correct
69 Correct 705 ms 5740 KB Output is correct
70 Correct 769 ms 5736 KB Output is correct
71 Correct 849 ms 5584 KB Output is correct
72 Correct 929 ms 5896 KB Output is correct
73 Correct 574 ms 5712 KB Output is correct
74 Correct 774 ms 5712 KB Output is correct
75 Correct 673 ms 5584 KB Output is correct
76 Correct 701 ms 6224 KB Output is correct
77 Correct 614 ms 6368 KB Output is correct
78 Correct 644 ms 6312 KB Output is correct
79 Correct 721 ms 5584 KB Output is correct
80 Correct 687 ms 5456 KB Output is correct
81 Correct 625 ms 5456 KB Output is correct
82 Correct 624 ms 5712 KB Output is correct
83 Correct 329 ms 5328 KB Output is correct
84 Correct 758 ms 5556 KB Output is correct
85 Correct 731 ms 5584 KB Output is correct
86 Correct 562 ms 5584 KB Output is correct
87 Correct 2 ms 4944 KB Output is correct
88 Correct 461 ms 20608 KB Output is correct
89 Correct 747 ms 14664 KB Output is correct
90 Correct 756 ms 14724 KB Output is correct
91 Correct 673 ms 21932 KB Output is correct
92 Correct 725 ms 21832 KB Output is correct
93 Correct 874 ms 21900 KB Output is correct
94 Correct 699 ms 21860 KB Output is correct
95 Correct 688 ms 21844 KB Output is correct
96 Execution timed out 3045 ms 9216 KB Time limit exceeded
97 Halted 0 ms 0 KB -