답안 #1013282

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1013282 2024-07-03T11:19:15 Z andrei_iorgulescu 디지털 회로 (IOI22_circuit) C++17
100 / 100
731 ms 28352 KB
#include <bits/stdc++.h>
#include "circuit.h"

using namespace std;

int modulo = (int)1e9 + 2022;

int n,m;
int t[200005];
vector<int> f[200005];
int a[100005];
int v[100005];
int dp[200005],s[200005],sp[200005];
int ff[200005];

void dfs(int nod)
{
    if (nod > n)
        s[nod] = 1;
    else
    {
        for (auto fiu : f[nod])
            dfs(fiu);
        s[nod] = f[nod].size();
        for (auto fiu : f[nod])
            s[nod] = 1ll * s[nod] * s[fiu] % modulo;
        vector<int> pref_prod(f[nod].size()),suf_prod(f[nod].size());
        pref_prod[0] = s[f[nod][0]];
        for (int i = 1; i < f[nod].size(); i++)
            pref_prod[i] = 1ll * pref_prod[i - 1] * s[f[nod][i]] % modulo;
        suf_prod[f[nod].size() - 1] = s[f[nod].back()];
        for (int i = (int)f[nod].size() - 2; i >= 0; i--)
            suf_prod[i] = 1ll * suf_prod[i + 1] * s[f[nod][i]] % modulo;
        for (int i = 0; i < f[nod].size(); i++)
        {
            sp[f[nod][i]] = 1;
            if (i != 0)
                sp[f[nod][i]] = pref_prod[i - 1];
            if (i + 1 != f[nod].size())
                sp[f[nod][i]] = 1ll * sp[f[nod][i]] * suf_prod[i + 1] % modulo;
        }
    }
}

void dfs2(int nod)
{
    if (nod == 1)
        ff[nod] = 1;
    else
        ff[nod] = 1ll * sp[nod] * ff[t[nod]] % modulo;
    for (auto fiu : f[nod])
        dfs2(fiu);
}

int aint[400005],sm[400005];
bool lazy[400005];

void build(int nod,int l,int r)
{
    if (l == r)
    {
        sm[nod] = v[l];
        aint[nod] = v[l] * a[l];
    }
    else
    {
        int mij = (l + r) / 2;
        build(2 * nod,l,mij);
        build(2 * nod + 1,mij + 1,r);
        sm[nod] = (sm[2 * nod] + sm[2 * nod + 1]) % modulo;
        aint[nod] = (aint[2 * nod] + aint[2 * nod + 1]) % modulo;
    }
}

void prop(int nod,int l,int r)
{
    if (!lazy[nod])
        return;
    lazy[nod] = false;
    if (l == r)
        return;
    aint[2 * nod] = (sm[2 * nod] + modulo - aint[2 * nod]) % modulo;
    aint[2 * nod + 1] = (sm[2 * nod + 1] + modulo - aint[2 * nod + 1]) % modulo;
    lazy[2 * nod] ^= 1;
    lazy[2 * nod + 1] ^= 1;
}

void update(int nod,int l,int r,int st,int dr)
{
    prop(nod,l,r);
    if (r < st or dr < l)
        return;
    if (st <= l and r <= dr)
    {
        aint[nod] = (sm[nod] + modulo - aint[nod]) % modulo;
        lazy[nod] = true;
        return;
    }
    int mij = (l + r) / 2;
    update(2 * nod,l,mij,st,dr);
    update(2 * nod + 1,mij + 1,r,st,dr);
    aint[nod] = (aint[2 * nod] + aint[2 * nod + 1]) % modulo;
}

void init(int N, int M, vector<int> P, vector<int> A)
{
    n = N;
    m = M;
    for (int i = 0; i < P.size(); i++)
        P[i]++;
    for (int i = 0; i < P.size(); i++)
    {
        t[i + 1] = P[i];
        f[P[i]].push_back(i + 1);
    }
    for (int i = 1; i <= m; i++)
        a[i] = A[i - 1];
    dfs(1);
    dfs2(1);
    for (int i = 1; i <= m; i++)
        v[i] = ff[n + i];
    build(1,1,m);
}

int count_ways(int L, int R)
{
    L++;
    R++;
    L -= n;
    R -= n;
    update(1,1,m,L,R);
    return aint[1];
}

Compilation message

circuit.cpp: In function 'void dfs(int)':
circuit.cpp:29:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |         for (int i = 1; i < f[nod].size(); i++)
      |                         ~~^~~~~~~~~~~~~~~
circuit.cpp:34:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for (int i = 0; i < f[nod].size(); i++)
      |                         ~~^~~~~~~~~~~~~~~
circuit.cpp:39:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |             if (i + 1 != f[nod].size())
      |                 ~~~~~~^~~~~~~~~~~~~~~~
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:109:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  109 |     for (int i = 0; i < P.size(); i++)
      |                     ~~^~~~~~~~~~
circuit.cpp:111:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |     for (int i = 0; i < P.size(); i++)
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 2 ms 12632 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 1 ms 12632 KB Output is correct
8 Correct 2 ms 12644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 12720 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 3 ms 12632 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 3 ms 12632 KB Output is correct
9 Correct 2 ms 12632 KB Output is correct
10 Correct 2 ms 12888 KB Output is correct
11 Correct 2 ms 12888 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 2 ms 12632 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 1 ms 12632 KB Output is correct
8 Correct 2 ms 12644 KB Output is correct
9 Correct 2 ms 12632 KB Output is correct
10 Correct 2 ms 12632 KB Output is correct
11 Correct 2 ms 12720 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 3 ms 12632 KB Output is correct
14 Correct 2 ms 12632 KB Output is correct
15 Correct 2 ms 12632 KB Output is correct
16 Correct 3 ms 12632 KB Output is correct
17 Correct 2 ms 12632 KB Output is correct
18 Correct 2 ms 12888 KB Output is correct
19 Correct 2 ms 12888 KB Output is correct
20 Correct 2 ms 12632 KB Output is correct
21 Correct 3 ms 12632 KB Output is correct
22 Correct 2 ms 12632 KB Output is correct
23 Correct 2 ms 12632 KB Output is correct
24 Correct 2 ms 12632 KB Output is correct
25 Correct 2 ms 12792 KB Output is correct
26 Correct 2 ms 12632 KB Output is correct
27 Correct 2 ms 12720 KB Output is correct
28 Correct 3 ms 12632 KB Output is correct
29 Correct 2 ms 12632 KB Output is correct
30 Correct 2 ms 12628 KB Output is correct
31 Correct 2 ms 12632 KB Output is correct
32 Correct 2 ms 12632 KB Output is correct
33 Correct 3 ms 12632 KB Output is correct
34 Correct 2 ms 12628 KB Output is correct
35 Correct 2 ms 12632 KB Output is correct
36 Correct 2 ms 12888 KB Output is correct
37 Correct 2 ms 12884 KB Output is correct
38 Correct 3 ms 12888 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 3 ms 12632 KB Output is correct
41 Correct 1 ms 10584 KB Output is correct
42 Correct 2 ms 12632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 416 ms 14424 KB Output is correct
2 Correct 678 ms 16336 KB Output is correct
3 Correct 480 ms 16252 KB Output is correct
4 Correct 544 ms 16468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 416 ms 14424 KB Output is correct
2 Correct 678 ms 16336 KB Output is correct
3 Correct 480 ms 16252 KB Output is correct
4 Correct 544 ms 16468 KB Output is correct
5 Correct 480 ms 14564 KB Output is correct
6 Correct 649 ms 16472 KB Output is correct
7 Correct 609 ms 16472 KB Output is correct
8 Correct 657 ms 16464 KB Output is correct
9 Correct 280 ms 12632 KB Output is correct
10 Correct 550 ms 12888 KB Output is correct
11 Correct 601 ms 12888 KB Output is correct
12 Correct 629 ms 12888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 12720 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 3 ms 12632 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 3 ms 12632 KB Output is correct
9 Correct 2 ms 12632 KB Output is correct
10 Correct 2 ms 12888 KB Output is correct
11 Correct 2 ms 12888 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 416 ms 14424 KB Output is correct
14 Correct 678 ms 16336 KB Output is correct
15 Correct 480 ms 16252 KB Output is correct
16 Correct 544 ms 16468 KB Output is correct
17 Correct 480 ms 14564 KB Output is correct
18 Correct 649 ms 16472 KB Output is correct
19 Correct 609 ms 16472 KB Output is correct
20 Correct 657 ms 16464 KB Output is correct
21 Correct 280 ms 12632 KB Output is correct
22 Correct 550 ms 12888 KB Output is correct
23 Correct 601 ms 12888 KB Output is correct
24 Correct 629 ms 12888 KB Output is correct
25 Correct 703 ms 18484 KB Output is correct
26 Correct 729 ms 18512 KB Output is correct
27 Correct 731 ms 18524 KB Output is correct
28 Correct 520 ms 17740 KB Output is correct
29 Correct 677 ms 28000 KB Output is correct
30 Correct 678 ms 27996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 2 ms 12632 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 1 ms 12632 KB Output is correct
8 Correct 2 ms 12644 KB Output is correct
9 Correct 2 ms 12632 KB Output is correct
10 Correct 2 ms 12632 KB Output is correct
11 Correct 2 ms 12720 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 3 ms 12632 KB Output is correct
14 Correct 2 ms 12632 KB Output is correct
15 Correct 2 ms 12632 KB Output is correct
16 Correct 3 ms 12632 KB Output is correct
17 Correct 2 ms 12632 KB Output is correct
18 Correct 2 ms 12888 KB Output is correct
19 Correct 2 ms 12888 KB Output is correct
20 Correct 2 ms 12632 KB Output is correct
21 Correct 3 ms 12632 KB Output is correct
22 Correct 2 ms 12632 KB Output is correct
23 Correct 2 ms 12632 KB Output is correct
24 Correct 2 ms 12632 KB Output is correct
25 Correct 2 ms 12792 KB Output is correct
26 Correct 2 ms 12632 KB Output is correct
27 Correct 2 ms 12720 KB Output is correct
28 Correct 3 ms 12632 KB Output is correct
29 Correct 2 ms 12632 KB Output is correct
30 Correct 2 ms 12628 KB Output is correct
31 Correct 2 ms 12632 KB Output is correct
32 Correct 2 ms 12632 KB Output is correct
33 Correct 3 ms 12632 KB Output is correct
34 Correct 2 ms 12628 KB Output is correct
35 Correct 2 ms 12632 KB Output is correct
36 Correct 2 ms 12888 KB Output is correct
37 Correct 2 ms 12884 KB Output is correct
38 Correct 3 ms 12888 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 3 ms 12632 KB Output is correct
41 Correct 1 ms 10584 KB Output is correct
42 Correct 2 ms 12632 KB Output is correct
43 Correct 422 ms 12888 KB Output is correct
44 Correct 478 ms 12936 KB Output is correct
45 Correct 480 ms 12888 KB Output is correct
46 Correct 444 ms 13140 KB Output is correct
47 Correct 577 ms 6744 KB Output is correct
48 Correct 594 ms 12888 KB Output is correct
49 Correct 566 ms 12888 KB Output is correct
50 Correct 508 ms 5720 KB Output is correct
51 Correct 518 ms 5464 KB Output is correct
52 Correct 550 ms 12888 KB Output is correct
53 Correct 527 ms 13400 KB Output is correct
54 Correct 565 ms 12888 KB Output is correct
55 Correct 509 ms 12888 KB Output is correct
56 Correct 560 ms 12888 KB Output is correct
57 Correct 543 ms 12632 KB Output is correct
58 Correct 539 ms 13400 KB Output is correct
59 Correct 535 ms 13556 KB Output is correct
60 Correct 534 ms 13552 KB Output is correct
61 Correct 607 ms 12888 KB Output is correct
62 Correct 618 ms 12888 KB Output is correct
63 Correct 608 ms 12632 KB Output is correct
64 Correct 606 ms 12632 KB Output is correct
65 Correct 278 ms 12632 KB Output is correct
66 Correct 616 ms 12888 KB Output is correct
67 Correct 569 ms 12888 KB Output is correct
68 Correct 506 ms 12888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12632 KB Output is correct
2 Correct 2 ms 12632 KB Output is correct
3 Correct 2 ms 12632 KB Output is correct
4 Correct 2 ms 12632 KB Output is correct
5 Correct 2 ms 12632 KB Output is correct
6 Correct 2 ms 12632 KB Output is correct
7 Correct 1 ms 12632 KB Output is correct
8 Correct 2 ms 12644 KB Output is correct
9 Correct 2 ms 12632 KB Output is correct
10 Correct 2 ms 12632 KB Output is correct
11 Correct 2 ms 12720 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 3 ms 12632 KB Output is correct
14 Correct 2 ms 12632 KB Output is correct
15 Correct 2 ms 12632 KB Output is correct
16 Correct 3 ms 12632 KB Output is correct
17 Correct 2 ms 12632 KB Output is correct
18 Correct 2 ms 12888 KB Output is correct
19 Correct 2 ms 12888 KB Output is correct
20 Correct 2 ms 12632 KB Output is correct
21 Correct 3 ms 12632 KB Output is correct
22 Correct 2 ms 12632 KB Output is correct
23 Correct 2 ms 12632 KB Output is correct
24 Correct 2 ms 12632 KB Output is correct
25 Correct 2 ms 12792 KB Output is correct
26 Correct 2 ms 12632 KB Output is correct
27 Correct 2 ms 12720 KB Output is correct
28 Correct 3 ms 12632 KB Output is correct
29 Correct 2 ms 12632 KB Output is correct
30 Correct 2 ms 12628 KB Output is correct
31 Correct 2 ms 12632 KB Output is correct
32 Correct 2 ms 12632 KB Output is correct
33 Correct 3 ms 12632 KB Output is correct
34 Correct 2 ms 12628 KB Output is correct
35 Correct 2 ms 12632 KB Output is correct
36 Correct 2 ms 12888 KB Output is correct
37 Correct 2 ms 12884 KB Output is correct
38 Correct 3 ms 12888 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 3 ms 12632 KB Output is correct
41 Correct 1 ms 10584 KB Output is correct
42 Correct 2 ms 12632 KB Output is correct
43 Correct 416 ms 14424 KB Output is correct
44 Correct 678 ms 16336 KB Output is correct
45 Correct 480 ms 16252 KB Output is correct
46 Correct 544 ms 16468 KB Output is correct
47 Correct 480 ms 14564 KB Output is correct
48 Correct 649 ms 16472 KB Output is correct
49 Correct 609 ms 16472 KB Output is correct
50 Correct 657 ms 16464 KB Output is correct
51 Correct 280 ms 12632 KB Output is correct
52 Correct 550 ms 12888 KB Output is correct
53 Correct 601 ms 12888 KB Output is correct
54 Correct 629 ms 12888 KB Output is correct
55 Correct 703 ms 18484 KB Output is correct
56 Correct 729 ms 18512 KB Output is correct
57 Correct 731 ms 18524 KB Output is correct
58 Correct 520 ms 17740 KB Output is correct
59 Correct 677 ms 28000 KB Output is correct
60 Correct 678 ms 27996 KB Output is correct
61 Correct 422 ms 12888 KB Output is correct
62 Correct 478 ms 12936 KB Output is correct
63 Correct 480 ms 12888 KB Output is correct
64 Correct 444 ms 13140 KB Output is correct
65 Correct 577 ms 6744 KB Output is correct
66 Correct 594 ms 12888 KB Output is correct
67 Correct 566 ms 12888 KB Output is correct
68 Correct 508 ms 5720 KB Output is correct
69 Correct 518 ms 5464 KB Output is correct
70 Correct 550 ms 12888 KB Output is correct
71 Correct 527 ms 13400 KB Output is correct
72 Correct 565 ms 12888 KB Output is correct
73 Correct 509 ms 12888 KB Output is correct
74 Correct 560 ms 12888 KB Output is correct
75 Correct 543 ms 12632 KB Output is correct
76 Correct 539 ms 13400 KB Output is correct
77 Correct 535 ms 13556 KB Output is correct
78 Correct 534 ms 13552 KB Output is correct
79 Correct 607 ms 12888 KB Output is correct
80 Correct 618 ms 12888 KB Output is correct
81 Correct 608 ms 12632 KB Output is correct
82 Correct 606 ms 12632 KB Output is correct
83 Correct 278 ms 12632 KB Output is correct
84 Correct 616 ms 12888 KB Output is correct
85 Correct 569 ms 12888 KB Output is correct
86 Correct 506 ms 12888 KB Output is correct
87 Correct 2 ms 12632 KB Output is correct
88 Correct 368 ms 18088 KB Output is correct
89 Correct 559 ms 15276 KB Output is correct
90 Correct 617 ms 16312 KB Output is correct
91 Correct 657 ms 18512 KB Output is correct
92 Correct 670 ms 18508 KB Output is correct
93 Correct 657 ms 18512 KB Output is correct
94 Correct 685 ms 18616 KB Output is correct
95 Correct 681 ms 18508 KB Output is correct
96 Correct 651 ms 14784 KB Output is correct
97 Correct 657 ms 14784 KB Output is correct
98 Correct 569 ms 26028 KB Output is correct
99 Correct 656 ms 18512 KB Output is correct
100 Correct 685 ms 16464 KB Output is correct
101 Correct 603 ms 15704 KB Output is correct
102 Correct 639 ms 14680 KB Output is correct
103 Correct 690 ms 27980 KB Output is correct
104 Correct 694 ms 28352 KB Output is correct
105 Correct 644 ms 28352 KB Output is correct
106 Correct 654 ms 18520 KB Output is correct
107 Correct 667 ms 15476 KB Output is correct
108 Correct 673 ms 15292 KB Output is correct
109 Correct 669 ms 14936 KB Output is correct