답안 #1025197

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025197 2024-07-16T17:20:32 Z vjudge1 디지털 회로 (IOI22_circuit) C++17
100 / 100
879 ms 82340 KB
#include "circuit.h"
#include <bits/stdc++.h>

using namespace std;

#define rall(s) s.rbegin(), s.rend()
#define all(s) s.begin(), s.end()
#define sz(s) (int) s.size()
#define s second 
#define f first 

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int N = 1e6, mod = 1000002022;

int n, m, is = 1;
vector<int> g[N], a(N);

vector<ll> pr(N), sf(N), val(N), gvl(N);

void calc(int u) {
    for (int to: g[u]) {
        calc(to);
    }
    int M = sz(g[u]);
    if (!M) {
        val[u] = 1;
        return;
    }
    for (int i = 0; i < M; i++) {
        if (i) pr[i] = pr[i - 1];
        else pr[i] = 1;
        pr[i] = (pr[i] * val[g[u][i]]) % mod;
    }
    for (int i = M - 1; i >= 0; i--) {
        if (i < M - 1) sf[i] = sf[i + 1];
        else sf[i] = 1;
        sf[i] = (sf[i] * val[g[u][i]]) % mod; 
    }
    for (int i = 0; i < M; i++) {
        gvl[g[u][i]] = ((i ? pr[i - 1] : 1ll) * (i < M - 1 ? sf[i + 1] : 1ll)) % mod;
    }
    val[u] = (pr[M - 1] * M) % mod;
}

ll vl[N];

void dfs(int u, int x) {
    int M = sz(g[u]);
    if (!M) {
        vl[u - n] = x;
        return;
    }
    for (int to: g[u]) {
        dfs(to, (x * gvl[to]) % mod);
    }
}

pll t[4 * N];
int swp[4 * N];

void bld(int u = 1, int tl = 0, int tr = m - 1) {
    if (tl == tr) {
        if (a[tl]) t[u].f = vl[tl];
        else t[u].s = vl[tl];
        return;
    }
    int mid = (tl + tr) / 2;
    bld(u * 2, tl, mid);
    bld(u * 2 + 1, mid + 1, tr);
    t[u].f = (t[u * 2].f + t[u  * 2 + 1].f) % mod;
    t[u].s = (t[u * 2].s + t[u  * 2 + 1].s) % mod;
}

void push(int u, int tl, int tr) {
    if (!swp[u]) return;
    swap(t[u].f, t[u].s);
    if (tl < tr) {
        swp[u * 2] ^= 1;
        swp[u * 2 + 1] ^= 1;
    }
    swp[u] = 0;
}

void upd(int l, int r, int u = 1, int tl = 0, int tr = m - 1) {
    push(u, tl, tr);
    if (tl > r || tr < l) return;
    if (tl >= l && tr <= r) {
        swp[u] = 1;
        push(u, tl, tr);
        return;
    }
    int mid = (tl + tr) / 2;
    upd(l, r, u * 2, tl, mid);
    upd(l, r, u * 2 + 1, mid + 1, tr);    
    t[u].f = (t[u * 2].f + t[u  * 2 + 1].f) % mod;
    t[u].s = (t[u * 2].s + t[u  * 2 + 1].s) % mod;
}


void init(int nn, int M, vector<int> P, vector<int> A) {
    n = nn, m = M;
    for (int i = 0; i < m; i++) a[i] = A[i];
    for (int i = 1; i < n + m; i++) g[P[i]].push_back(i);
    calc(0), dfs(0, 1), bld();
}

int count_ways(int l, int r) {
    upd(l - n, r - n);
    return t[1].f;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 64856 KB Output is correct
2 Correct 11 ms 64856 KB Output is correct
3 Correct 12 ms 64856 KB Output is correct
4 Correct 12 ms 65112 KB Output is correct
5 Correct 12 ms 64856 KB Output is correct
6 Correct 12 ms 65112 KB Output is correct
7 Correct 17 ms 64856 KB Output is correct
8 Correct 13 ms 64856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 64856 KB Output is correct
2 Correct 13 ms 64856 KB Output is correct
3 Correct 12 ms 64856 KB Output is correct
4 Correct 12 ms 64856 KB Output is correct
5 Correct 11 ms 64964 KB Output is correct
6 Correct 12 ms 65112 KB Output is correct
7 Correct 15 ms 64948 KB Output is correct
8 Correct 12 ms 65112 KB Output is correct
9 Correct 13 ms 65112 KB Output is correct
10 Correct 17 ms 65112 KB Output is correct
11 Correct 12 ms 65060 KB Output is correct
12 Correct 12 ms 65112 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 64856 KB Output is correct
2 Correct 11 ms 64856 KB Output is correct
3 Correct 12 ms 64856 KB Output is correct
4 Correct 12 ms 65112 KB Output is correct
5 Correct 12 ms 64856 KB Output is correct
6 Correct 12 ms 65112 KB Output is correct
7 Correct 17 ms 64856 KB Output is correct
8 Correct 13 ms 64856 KB Output is correct
9 Correct 17 ms 64856 KB Output is correct
10 Correct 13 ms 64856 KB Output is correct
11 Correct 12 ms 64856 KB Output is correct
12 Correct 12 ms 64856 KB Output is correct
13 Correct 11 ms 64964 KB Output is correct
14 Correct 12 ms 65112 KB Output is correct
15 Correct 15 ms 64948 KB Output is correct
16 Correct 12 ms 65112 KB Output is correct
17 Correct 13 ms 65112 KB Output is correct
18 Correct 17 ms 65112 KB Output is correct
19 Correct 12 ms 65060 KB Output is correct
20 Correct 12 ms 65112 KB Output is correct
21 Correct 14 ms 65112 KB Output is correct
22 Correct 17 ms 64900 KB Output is correct
23 Correct 14 ms 65112 KB Output is correct
24 Correct 18 ms 65368 KB Output is correct
25 Correct 13 ms 65112 KB Output is correct
26 Correct 14 ms 65112 KB Output is correct
27 Correct 13 ms 65112 KB Output is correct
28 Correct 18 ms 65112 KB Output is correct
29 Correct 17 ms 64856 KB Output is correct
30 Correct 13 ms 64880 KB Output is correct
31 Correct 12 ms 65112 KB Output is correct
32 Correct 12 ms 65112 KB Output is correct
33 Correct 11 ms 65112 KB Output is correct
34 Correct 13 ms 64856 KB Output is correct
35 Correct 18 ms 64856 KB Output is correct
36 Correct 16 ms 65112 KB Output is correct
37 Correct 17 ms 65112 KB Output is correct
38 Correct 13 ms 65112 KB Output is correct
39 Correct 13 ms 65112 KB Output is correct
40 Correct 17 ms 65056 KB Output is correct
41 Correct 13 ms 64856 KB Output is correct
42 Correct 14 ms 64856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 586 ms 68924 KB Output is correct
2 Correct 713 ms 70480 KB Output is correct
3 Correct 754 ms 70484 KB Output is correct
4 Correct 754 ms 70480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 586 ms 68924 KB Output is correct
2 Correct 713 ms 70480 KB Output is correct
3 Correct 754 ms 70484 KB Output is correct
4 Correct 754 ms 70480 KB Output is correct
5 Correct 605 ms 71224 KB Output is correct
6 Correct 787 ms 72164 KB Output is correct
7 Correct 789 ms 70708 KB Output is correct
8 Correct 726 ms 70480 KB Output is correct
9 Correct 340 ms 65188 KB Output is correct
10 Correct 663 ms 65308 KB Output is correct
11 Correct 665 ms 65308 KB Output is correct
12 Correct 685 ms 65304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 64856 KB Output is correct
2 Correct 13 ms 64856 KB Output is correct
3 Correct 12 ms 64856 KB Output is correct
4 Correct 12 ms 64856 KB Output is correct
5 Correct 11 ms 64964 KB Output is correct
6 Correct 12 ms 65112 KB Output is correct
7 Correct 15 ms 64948 KB Output is correct
8 Correct 12 ms 65112 KB Output is correct
9 Correct 13 ms 65112 KB Output is correct
10 Correct 17 ms 65112 KB Output is correct
11 Correct 12 ms 65060 KB Output is correct
12 Correct 12 ms 65112 KB Output is correct
13 Correct 586 ms 68924 KB Output is correct
14 Correct 713 ms 70480 KB Output is correct
15 Correct 754 ms 70484 KB Output is correct
16 Correct 754 ms 70480 KB Output is correct
17 Correct 605 ms 71224 KB Output is correct
18 Correct 787 ms 72164 KB Output is correct
19 Correct 789 ms 70708 KB Output is correct
20 Correct 726 ms 70480 KB Output is correct
21 Correct 340 ms 65188 KB Output is correct
22 Correct 663 ms 65308 KB Output is correct
23 Correct 665 ms 65308 KB Output is correct
24 Correct 685 ms 65304 KB Output is correct
25 Correct 820 ms 75752 KB Output is correct
26 Correct 847 ms 74680 KB Output is correct
27 Correct 853 ms 74752 KB Output is correct
28 Correct 628 ms 74576 KB Output is correct
29 Correct 746 ms 80916 KB Output is correct
30 Correct 658 ms 80720 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 64856 KB Output is correct
2 Correct 11 ms 64856 KB Output is correct
3 Correct 12 ms 64856 KB Output is correct
4 Correct 12 ms 65112 KB Output is correct
5 Correct 12 ms 64856 KB Output is correct
6 Correct 12 ms 65112 KB Output is correct
7 Correct 17 ms 64856 KB Output is correct
8 Correct 13 ms 64856 KB Output is correct
9 Correct 17 ms 64856 KB Output is correct
10 Correct 13 ms 64856 KB Output is correct
11 Correct 12 ms 64856 KB Output is correct
12 Correct 12 ms 64856 KB Output is correct
13 Correct 11 ms 64964 KB Output is correct
14 Correct 12 ms 65112 KB Output is correct
15 Correct 15 ms 64948 KB Output is correct
16 Correct 12 ms 65112 KB Output is correct
17 Correct 13 ms 65112 KB Output is correct
18 Correct 17 ms 65112 KB Output is correct
19 Correct 12 ms 65060 KB Output is correct
20 Correct 12 ms 65112 KB Output is correct
21 Correct 14 ms 65112 KB Output is correct
22 Correct 17 ms 64900 KB Output is correct
23 Correct 14 ms 65112 KB Output is correct
24 Correct 18 ms 65368 KB Output is correct
25 Correct 13 ms 65112 KB Output is correct
26 Correct 14 ms 65112 KB Output is correct
27 Correct 13 ms 65112 KB Output is correct
28 Correct 18 ms 65112 KB Output is correct
29 Correct 17 ms 64856 KB Output is correct
30 Correct 13 ms 64880 KB Output is correct
31 Correct 12 ms 65112 KB Output is correct
32 Correct 12 ms 65112 KB Output is correct
33 Correct 11 ms 65112 KB Output is correct
34 Correct 13 ms 64856 KB Output is correct
35 Correct 18 ms 64856 KB Output is correct
36 Correct 16 ms 65112 KB Output is correct
37 Correct 17 ms 65112 KB Output is correct
38 Correct 13 ms 65112 KB Output is correct
39 Correct 13 ms 65112 KB Output is correct
40 Correct 17 ms 65056 KB Output is correct
41 Correct 13 ms 64856 KB Output is correct
42 Correct 14 ms 64856 KB Output is correct
43 Correct 439 ms 65244 KB Output is correct
44 Correct 565 ms 65280 KB Output is correct
45 Correct 630 ms 65368 KB Output is correct
46 Correct 583 ms 65384 KB Output is correct
47 Correct 640 ms 65392 KB Output is correct
48 Correct 593 ms 65396 KB Output is correct
49 Correct 614 ms 65396 KB Output is correct
50 Correct 548 ms 65356 KB Output is correct
51 Correct 603 ms 65208 KB Output is correct
52 Correct 659 ms 65252 KB Output is correct
53 Correct 647 ms 65564 KB Output is correct
54 Correct 721 ms 65388 KB Output is correct
55 Correct 634 ms 65300 KB Output is correct
56 Correct 741 ms 65276 KB Output is correct
57 Correct 669 ms 65220 KB Output is correct
58 Correct 626 ms 65696 KB Output is correct
59 Correct 611 ms 65884 KB Output is correct
60 Correct 612 ms 65704 KB Output is correct
61 Correct 597 ms 65344 KB Output is correct
62 Correct 615 ms 65220 KB Output is correct
63 Correct 551 ms 65204 KB Output is correct
64 Correct 657 ms 65228 KB Output is correct
65 Correct 315 ms 65364 KB Output is correct
66 Correct 658 ms 65304 KB Output is correct
67 Correct 596 ms 65316 KB Output is correct
68 Correct 622 ms 65292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 64856 KB Output is correct
2 Correct 11 ms 64856 KB Output is correct
3 Correct 12 ms 64856 KB Output is correct
4 Correct 12 ms 65112 KB Output is correct
5 Correct 12 ms 64856 KB Output is correct
6 Correct 12 ms 65112 KB Output is correct
7 Correct 17 ms 64856 KB Output is correct
8 Correct 13 ms 64856 KB Output is correct
9 Correct 17 ms 64856 KB Output is correct
10 Correct 13 ms 64856 KB Output is correct
11 Correct 12 ms 64856 KB Output is correct
12 Correct 12 ms 64856 KB Output is correct
13 Correct 11 ms 64964 KB Output is correct
14 Correct 12 ms 65112 KB Output is correct
15 Correct 15 ms 64948 KB Output is correct
16 Correct 12 ms 65112 KB Output is correct
17 Correct 13 ms 65112 KB Output is correct
18 Correct 17 ms 65112 KB Output is correct
19 Correct 12 ms 65060 KB Output is correct
20 Correct 12 ms 65112 KB Output is correct
21 Correct 14 ms 65112 KB Output is correct
22 Correct 17 ms 64900 KB Output is correct
23 Correct 14 ms 65112 KB Output is correct
24 Correct 18 ms 65368 KB Output is correct
25 Correct 13 ms 65112 KB Output is correct
26 Correct 14 ms 65112 KB Output is correct
27 Correct 13 ms 65112 KB Output is correct
28 Correct 18 ms 65112 KB Output is correct
29 Correct 17 ms 64856 KB Output is correct
30 Correct 13 ms 64880 KB Output is correct
31 Correct 12 ms 65112 KB Output is correct
32 Correct 12 ms 65112 KB Output is correct
33 Correct 11 ms 65112 KB Output is correct
34 Correct 13 ms 64856 KB Output is correct
35 Correct 18 ms 64856 KB Output is correct
36 Correct 16 ms 65112 KB Output is correct
37 Correct 17 ms 65112 KB Output is correct
38 Correct 13 ms 65112 KB Output is correct
39 Correct 13 ms 65112 KB Output is correct
40 Correct 17 ms 65056 KB Output is correct
41 Correct 13 ms 64856 KB Output is correct
42 Correct 14 ms 64856 KB Output is correct
43 Correct 586 ms 68924 KB Output is correct
44 Correct 713 ms 70480 KB Output is correct
45 Correct 754 ms 70484 KB Output is correct
46 Correct 754 ms 70480 KB Output is correct
47 Correct 605 ms 71224 KB Output is correct
48 Correct 787 ms 72164 KB Output is correct
49 Correct 789 ms 70708 KB Output is correct
50 Correct 726 ms 70480 KB Output is correct
51 Correct 340 ms 65188 KB Output is correct
52 Correct 663 ms 65308 KB Output is correct
53 Correct 665 ms 65308 KB Output is correct
54 Correct 685 ms 65304 KB Output is correct
55 Correct 820 ms 75752 KB Output is correct
56 Correct 847 ms 74680 KB Output is correct
57 Correct 853 ms 74752 KB Output is correct
58 Correct 628 ms 74576 KB Output is correct
59 Correct 746 ms 80916 KB Output is correct
60 Correct 658 ms 80720 KB Output is correct
61 Correct 439 ms 65244 KB Output is correct
62 Correct 565 ms 65280 KB Output is correct
63 Correct 630 ms 65368 KB Output is correct
64 Correct 583 ms 65384 KB Output is correct
65 Correct 640 ms 65392 KB Output is correct
66 Correct 593 ms 65396 KB Output is correct
67 Correct 614 ms 65396 KB Output is correct
68 Correct 548 ms 65356 KB Output is correct
69 Correct 603 ms 65208 KB Output is correct
70 Correct 659 ms 65252 KB Output is correct
71 Correct 647 ms 65564 KB Output is correct
72 Correct 721 ms 65388 KB Output is correct
73 Correct 634 ms 65300 KB Output is correct
74 Correct 741 ms 65276 KB Output is correct
75 Correct 669 ms 65220 KB Output is correct
76 Correct 626 ms 65696 KB Output is correct
77 Correct 611 ms 65884 KB Output is correct
78 Correct 612 ms 65704 KB Output is correct
79 Correct 597 ms 65344 KB Output is correct
80 Correct 615 ms 65220 KB Output is correct
81 Correct 551 ms 65204 KB Output is correct
82 Correct 657 ms 65228 KB Output is correct
83 Correct 315 ms 65364 KB Output is correct
84 Correct 658 ms 65304 KB Output is correct
85 Correct 596 ms 65316 KB Output is correct
86 Correct 622 ms 65292 KB Output is correct
87 Correct 16 ms 64856 KB Output is correct
88 Correct 488 ms 74204 KB Output is correct
89 Correct 808 ms 70796 KB Output is correct
90 Correct 802 ms 72176 KB Output is correct
91 Correct 808 ms 74732 KB Output is correct
92 Correct 879 ms 74608 KB Output is correct
93 Correct 810 ms 74740 KB Output is correct
94 Correct 822 ms 74700 KB Output is correct
95 Correct 739 ms 75660 KB Output is correct
96 Correct 678 ms 71120 KB Output is correct
97 Correct 766 ms 71492 KB Output is correct
98 Correct 604 ms 74980 KB Output is correct
99 Correct 753 ms 74576 KB Output is correct
100 Correct 837 ms 72740 KB Output is correct
101 Correct 784 ms 72364 KB Output is correct
102 Correct 801 ms 71468 KB Output is correct
103 Correct 761 ms 80748 KB Output is correct
104 Correct 781 ms 81276 KB Output is correct
105 Correct 730 ms 82340 KB Output is correct
106 Correct 723 ms 72044 KB Output is correct
107 Correct 723 ms 72188 KB Output is correct
108 Correct 768 ms 73164 KB Output is correct
109 Correct 762 ms 71548 KB Output is correct