답안 #1063330

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1063330 2024-08-17T16:56:40 Z jerzyk 디지털 회로 (IOI22_circuit) C++17
100 / 100
817 ms 32316 KB
#include <bits/stdc++.h>
#include "circuit.h"

using namespace std;
#define pb push_back
#define st first
#define nd second
typedef long long ll;
typedef long double ld;
const ll I = 1000LL * 1000LL * 1000LL * 1000LL * 1000LL * 1000LL;
const int II = 2 * 1000 * 1000 * 1000;
const ll M = 1000002022LL;
const int N = 1<<18;
ll drz[2 * N][2];
int laz[2 * N];
vector<int> ed[N];
ll il[N];
int bas;

void Query(int v, int p, int k, int pz, int kz)
{
    if(p > kz || k < pz) return;
    if(p >= pz && k <= kz)
    {
        swap(drz[v][0], drz[v][1]);
        laz[v] ^= 1;
        return;
    }
    Query(v * 2, p, (p + k) / 2, pz, kz);
    Query(v * 2 + 1, (p + k) / 2 + 1, k, pz, kz);
    drz[v][0] = (drz[v * 2][0] + drz[v * 2 + 1][0]) % M;
    drz[v][1] = (drz[v * 2][1] + drz[v * 2 + 1][1]) % M;
    if(laz[v] == 1)
        swap(drz[v][0], drz[v][1]);
}

ll QP(ll a, ll n)
{
    ll ans = 1LL;
    while(n > 0LL)
    {
        if(n % 2LL == 1LL)
            ans = (ans * a) % M;
        a = (a * a) % M;
        n /= 2LL;
    }
    return ans;
}

void DFSL(int v)
{
    il[v] = max(1LL, (ll)ed[v].size());
    for(int i = 0; i < (int)ed[v].size(); ++i)
    {
        DFSL(ed[v][i]);
        il[v] = (il[v] * il[ed[v][i]]) % M;
    }
}

void DFS(int v, ll cur)
{
    if(v > bas)
    {
        drz[v - bas + N][0] += cur;
        return;
    }
    vector<ll> prf;
    for(int i = 0; i < (int)ed[v].size(); ++i)
    {
        prf.pb(il[ed[v][i]]);
        if(i > 0)
            prf[i] = (prf[i] * prf[i - 1]) % M;
    }
    for(int i = (int)ed[v].size() - 1; i >= 0; --i)
    {
        ll xd = cur;
        if(i > 0) xd = (xd * prf[i - 1]) % M;
        DFS(ed[v][i], xd);
        cur = (cur * il[ed[v][i]]) % M;
    }
}

void init(int XN, int XM, vector<int> P, vector<int> A)
{
    int n = XN + XM;
    bas = XN;
    for(int i = 1; i < n; ++i)
        ed[P[i] + 1].pb(i + 1);
    DFSL(1);
    DFS(1, 1LL);
    for(int i = 1; i <= n - bas; ++i)
    {
        if(A[i - 1] == 0)
            swap(drz[i + N][0], drz[i + N][1]);
    }

    for(int i = N - 1; i >= 1; --i)
    {
        drz[i][0] = (drz[i * 2][0] + drz[i * 2 + 1][0]) % M;
        drz[i][1] = (drz[i * 2][1] + drz[i * 2 + 1][1]) % M;
    }
}

int count_ways(int L, int R)
{
    ++L; ++R;
    L -= bas; R -= bas;
    Query(1, 0, N - 1, L, R);
    return drz[1][0];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10584 KB Output is correct
2 Correct 5 ms 10584 KB Output is correct
3 Correct 5 ms 10688 KB Output is correct
4 Correct 6 ms 10584 KB Output is correct
5 Correct 6 ms 10580 KB Output is correct
6 Correct 5 ms 10584 KB Output is correct
7 Correct 5 ms 10584 KB Output is correct
8 Correct 5 ms 10584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10584 KB Output is correct
2 Correct 5 ms 10584 KB Output is correct
3 Correct 6 ms 10584 KB Output is correct
4 Correct 5 ms 10584 KB Output is correct
5 Correct 5 ms 10584 KB Output is correct
6 Correct 5 ms 10584 KB Output is correct
7 Correct 6 ms 10840 KB Output is correct
8 Correct 5 ms 10748 KB Output is correct
9 Correct 5 ms 10840 KB Output is correct
10 Correct 5 ms 10840 KB Output is correct
11 Correct 6 ms 10840 KB Output is correct
12 Correct 5 ms 10584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10584 KB Output is correct
2 Correct 5 ms 10584 KB Output is correct
3 Correct 5 ms 10688 KB Output is correct
4 Correct 6 ms 10584 KB Output is correct
5 Correct 6 ms 10580 KB Output is correct
6 Correct 5 ms 10584 KB Output is correct
7 Correct 5 ms 10584 KB Output is correct
8 Correct 5 ms 10584 KB Output is correct
9 Correct 5 ms 10584 KB Output is correct
10 Correct 5 ms 10584 KB Output is correct
11 Correct 6 ms 10584 KB Output is correct
12 Correct 5 ms 10584 KB Output is correct
13 Correct 5 ms 10584 KB Output is correct
14 Correct 5 ms 10584 KB Output is correct
15 Correct 6 ms 10840 KB Output is correct
16 Correct 5 ms 10748 KB Output is correct
17 Correct 5 ms 10840 KB Output is correct
18 Correct 5 ms 10840 KB Output is correct
19 Correct 6 ms 10840 KB Output is correct
20 Correct 5 ms 10584 KB Output is correct
21 Correct 5 ms 10580 KB Output is correct
22 Correct 5 ms 10584 KB Output is correct
23 Correct 5 ms 10584 KB Output is correct
24 Correct 6 ms 10584 KB Output is correct
25 Correct 5 ms 10840 KB Output is correct
26 Correct 5 ms 10624 KB Output is correct
27 Correct 6 ms 10732 KB Output is correct
28 Correct 5 ms 10840 KB Output is correct
29 Correct 6 ms 10584 KB Output is correct
30 Correct 6 ms 10568 KB Output is correct
31 Correct 5 ms 10840 KB Output is correct
32 Correct 5 ms 10840 KB Output is correct
33 Correct 5 ms 10592 KB Output is correct
34 Correct 5 ms 10584 KB Output is correct
35 Correct 7 ms 10592 KB Output is correct
36 Correct 5 ms 10840 KB Output is correct
37 Correct 5 ms 10836 KB Output is correct
38 Correct 5 ms 10840 KB Output is correct
39 Correct 6 ms 10584 KB Output is correct
40 Correct 5 ms 10584 KB Output is correct
41 Correct 5 ms 10584 KB Output is correct
42 Correct 5 ms 10584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 483 ms 13400 KB Output is correct
2 Correct 624 ms 16208 KB Output is correct
3 Correct 680 ms 16340 KB Output is correct
4 Correct 659 ms 16460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 483 ms 13400 KB Output is correct
2 Correct 624 ms 16208 KB Output is correct
3 Correct 680 ms 16340 KB Output is correct
4 Correct 659 ms 16460 KB Output is correct
5 Correct 531 ms 13440 KB Output is correct
6 Correct 692 ms 16216 KB Output is correct
7 Correct 679 ms 16216 KB Output is correct
8 Correct 601 ms 16216 KB Output is correct
9 Correct 307 ms 10840 KB Output is correct
10 Correct 660 ms 11096 KB Output is correct
11 Correct 668 ms 11096 KB Output is correct
12 Correct 642 ms 11096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10584 KB Output is correct
2 Correct 5 ms 10584 KB Output is correct
3 Correct 6 ms 10584 KB Output is correct
4 Correct 5 ms 10584 KB Output is correct
5 Correct 5 ms 10584 KB Output is correct
6 Correct 5 ms 10584 KB Output is correct
7 Correct 6 ms 10840 KB Output is correct
8 Correct 5 ms 10748 KB Output is correct
9 Correct 5 ms 10840 KB Output is correct
10 Correct 5 ms 10840 KB Output is correct
11 Correct 6 ms 10840 KB Output is correct
12 Correct 5 ms 10584 KB Output is correct
13 Correct 483 ms 13400 KB Output is correct
14 Correct 624 ms 16208 KB Output is correct
15 Correct 680 ms 16340 KB Output is correct
16 Correct 659 ms 16460 KB Output is correct
17 Correct 531 ms 13440 KB Output is correct
18 Correct 692 ms 16216 KB Output is correct
19 Correct 679 ms 16216 KB Output is correct
20 Correct 601 ms 16216 KB Output is correct
21 Correct 307 ms 10840 KB Output is correct
22 Correct 660 ms 11096 KB Output is correct
23 Correct 668 ms 11096 KB Output is correct
24 Correct 642 ms 11096 KB Output is correct
25 Correct 710 ms 19024 KB Output is correct
26 Correct 724 ms 19288 KB Output is correct
27 Correct 730 ms 19296 KB Output is correct
28 Correct 548 ms 19304 KB Output is correct
29 Correct 749 ms 31820 KB Output is correct
30 Correct 724 ms 31824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10584 KB Output is correct
2 Correct 5 ms 10584 KB Output is correct
3 Correct 5 ms 10688 KB Output is correct
4 Correct 6 ms 10584 KB Output is correct
5 Correct 6 ms 10580 KB Output is correct
6 Correct 5 ms 10584 KB Output is correct
7 Correct 5 ms 10584 KB Output is correct
8 Correct 5 ms 10584 KB Output is correct
9 Correct 5 ms 10584 KB Output is correct
10 Correct 5 ms 10584 KB Output is correct
11 Correct 6 ms 10584 KB Output is correct
12 Correct 5 ms 10584 KB Output is correct
13 Correct 5 ms 10584 KB Output is correct
14 Correct 5 ms 10584 KB Output is correct
15 Correct 6 ms 10840 KB Output is correct
16 Correct 5 ms 10748 KB Output is correct
17 Correct 5 ms 10840 KB Output is correct
18 Correct 5 ms 10840 KB Output is correct
19 Correct 6 ms 10840 KB Output is correct
20 Correct 5 ms 10584 KB Output is correct
21 Correct 5 ms 10580 KB Output is correct
22 Correct 5 ms 10584 KB Output is correct
23 Correct 5 ms 10584 KB Output is correct
24 Correct 6 ms 10584 KB Output is correct
25 Correct 5 ms 10840 KB Output is correct
26 Correct 5 ms 10624 KB Output is correct
27 Correct 6 ms 10732 KB Output is correct
28 Correct 5 ms 10840 KB Output is correct
29 Correct 6 ms 10584 KB Output is correct
30 Correct 6 ms 10568 KB Output is correct
31 Correct 5 ms 10840 KB Output is correct
32 Correct 5 ms 10840 KB Output is correct
33 Correct 5 ms 10592 KB Output is correct
34 Correct 5 ms 10584 KB Output is correct
35 Correct 7 ms 10592 KB Output is correct
36 Correct 5 ms 10840 KB Output is correct
37 Correct 5 ms 10836 KB Output is correct
38 Correct 5 ms 10840 KB Output is correct
39 Correct 6 ms 10584 KB Output is correct
40 Correct 5 ms 10584 KB Output is correct
41 Correct 5 ms 10584 KB Output is correct
42 Correct 5 ms 10584 KB Output is correct
43 Correct 416 ms 10840 KB Output is correct
44 Correct 625 ms 10840 KB Output is correct
45 Correct 693 ms 10840 KB Output is correct
46 Correct 622 ms 11096 KB Output is correct
47 Correct 652 ms 11096 KB Output is correct
48 Correct 634 ms 11096 KB Output is correct
49 Correct 564 ms 11096 KB Output is correct
50 Correct 515 ms 11096 KB Output is correct
51 Correct 551 ms 11060 KB Output is correct
52 Correct 579 ms 11096 KB Output is correct
53 Correct 554 ms 11352 KB Output is correct
54 Correct 603 ms 11096 KB Output is correct
55 Correct 600 ms 11096 KB Output is correct
56 Correct 699 ms 10836 KB Output is correct
57 Correct 646 ms 10840 KB Output is correct
58 Correct 667 ms 11608 KB Output is correct
59 Correct 649 ms 11864 KB Output is correct
60 Correct 646 ms 11864 KB Output is correct
61 Correct 652 ms 11096 KB Output is correct
62 Correct 638 ms 10840 KB Output is correct
63 Correct 666 ms 10840 KB Output is correct
64 Correct 706 ms 10840 KB Output is correct
65 Correct 338 ms 10840 KB Output is correct
66 Correct 663 ms 11096 KB Output is correct
67 Correct 618 ms 11096 KB Output is correct
68 Correct 600 ms 11096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 10584 KB Output is correct
2 Correct 5 ms 10584 KB Output is correct
3 Correct 5 ms 10688 KB Output is correct
4 Correct 6 ms 10584 KB Output is correct
5 Correct 6 ms 10580 KB Output is correct
6 Correct 5 ms 10584 KB Output is correct
7 Correct 5 ms 10584 KB Output is correct
8 Correct 5 ms 10584 KB Output is correct
9 Correct 5 ms 10584 KB Output is correct
10 Correct 5 ms 10584 KB Output is correct
11 Correct 6 ms 10584 KB Output is correct
12 Correct 5 ms 10584 KB Output is correct
13 Correct 5 ms 10584 KB Output is correct
14 Correct 5 ms 10584 KB Output is correct
15 Correct 6 ms 10840 KB Output is correct
16 Correct 5 ms 10748 KB Output is correct
17 Correct 5 ms 10840 KB Output is correct
18 Correct 5 ms 10840 KB Output is correct
19 Correct 6 ms 10840 KB Output is correct
20 Correct 5 ms 10584 KB Output is correct
21 Correct 5 ms 10580 KB Output is correct
22 Correct 5 ms 10584 KB Output is correct
23 Correct 5 ms 10584 KB Output is correct
24 Correct 6 ms 10584 KB Output is correct
25 Correct 5 ms 10840 KB Output is correct
26 Correct 5 ms 10624 KB Output is correct
27 Correct 6 ms 10732 KB Output is correct
28 Correct 5 ms 10840 KB Output is correct
29 Correct 6 ms 10584 KB Output is correct
30 Correct 6 ms 10568 KB Output is correct
31 Correct 5 ms 10840 KB Output is correct
32 Correct 5 ms 10840 KB Output is correct
33 Correct 5 ms 10592 KB Output is correct
34 Correct 5 ms 10584 KB Output is correct
35 Correct 7 ms 10592 KB Output is correct
36 Correct 5 ms 10840 KB Output is correct
37 Correct 5 ms 10836 KB Output is correct
38 Correct 5 ms 10840 KB Output is correct
39 Correct 6 ms 10584 KB Output is correct
40 Correct 5 ms 10584 KB Output is correct
41 Correct 5 ms 10584 KB Output is correct
42 Correct 5 ms 10584 KB Output is correct
43 Correct 483 ms 13400 KB Output is correct
44 Correct 624 ms 16208 KB Output is correct
45 Correct 680 ms 16340 KB Output is correct
46 Correct 659 ms 16460 KB Output is correct
47 Correct 531 ms 13440 KB Output is correct
48 Correct 692 ms 16216 KB Output is correct
49 Correct 679 ms 16216 KB Output is correct
50 Correct 601 ms 16216 KB Output is correct
51 Correct 307 ms 10840 KB Output is correct
52 Correct 660 ms 11096 KB Output is correct
53 Correct 668 ms 11096 KB Output is correct
54 Correct 642 ms 11096 KB Output is correct
55 Correct 710 ms 19024 KB Output is correct
56 Correct 724 ms 19288 KB Output is correct
57 Correct 730 ms 19296 KB Output is correct
58 Correct 548 ms 19304 KB Output is correct
59 Correct 749 ms 31820 KB Output is correct
60 Correct 724 ms 31824 KB Output is correct
61 Correct 416 ms 10840 KB Output is correct
62 Correct 625 ms 10840 KB Output is correct
63 Correct 693 ms 10840 KB Output is correct
64 Correct 622 ms 11096 KB Output is correct
65 Correct 652 ms 11096 KB Output is correct
66 Correct 634 ms 11096 KB Output is correct
67 Correct 564 ms 11096 KB Output is correct
68 Correct 515 ms 11096 KB Output is correct
69 Correct 551 ms 11060 KB Output is correct
70 Correct 579 ms 11096 KB Output is correct
71 Correct 554 ms 11352 KB Output is correct
72 Correct 603 ms 11096 KB Output is correct
73 Correct 600 ms 11096 KB Output is correct
74 Correct 699 ms 10836 KB Output is correct
75 Correct 646 ms 10840 KB Output is correct
76 Correct 667 ms 11608 KB Output is correct
77 Correct 649 ms 11864 KB Output is correct
78 Correct 646 ms 11864 KB Output is correct
79 Correct 652 ms 11096 KB Output is correct
80 Correct 638 ms 10840 KB Output is correct
81 Correct 666 ms 10840 KB Output is correct
82 Correct 706 ms 10840 KB Output is correct
83 Correct 338 ms 10840 KB Output is correct
84 Correct 663 ms 11096 KB Output is correct
85 Correct 618 ms 11096 KB Output is correct
86 Correct 600 ms 11096 KB Output is correct
87 Correct 5 ms 10580 KB Output is correct
88 Correct 440 ms 18368 KB Output is correct
89 Correct 692 ms 16208 KB Output is correct
90 Correct 730 ms 15952 KB Output is correct
91 Correct 706 ms 19280 KB Output is correct
92 Correct 666 ms 19296 KB Output is correct
93 Correct 710 ms 19380 KB Output is correct
94 Correct 715 ms 19368 KB Output is correct
95 Correct 683 ms 19280 KB Output is correct
96 Correct 673 ms 14904 KB Output is correct
97 Correct 761 ms 15176 KB Output is correct
98 Correct 627 ms 27728 KB Output is correct
99 Correct 713 ms 19280 KB Output is correct
100 Correct 693 ms 16804 KB Output is correct
101 Correct 709 ms 16232 KB Output is correct
102 Correct 700 ms 15164 KB Output is correct
103 Correct 817 ms 31824 KB Output is correct
104 Correct 758 ms 32112 KB Output is correct
105 Correct 626 ms 32316 KB Output is correct
106 Correct 685 ms 18504 KB Output is correct
107 Correct 698 ms 15188 KB Output is correct
108 Correct 686 ms 15184 KB Output is correct
109 Correct 704 ms 15256 KB Output is correct