답안 #855626

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
855626 2023-10-01T14:22:50 Z 12345678 디지털 회로 (IOI22_circuit) C++17
100 / 100
638 ms 38736 KB
#include "circuit.h"
 
#include <bits/stdc++.h>
 
using namespace std;
 
#define ll long long
 
const int nx=2e5+5, mod=1e9+2022;
 
int n, m, sz[nx], v[nx];
ll dn[nx], dp[nx];
vector<int> d[nx];
 
ll dfs(int u)
{
    dn[u]=max(1, (int)d[u].size());
    for (auto v:d[u]) dn[u]=(dn[u]*dfs(v))%mod;
    //cout<<"dn"<<' '<<u<<' '<<dn[u]<<'\n';
    return dn[u];
}

void dfs2(int u)
{
    vector<ll> pref(d[u].size()+2, 1), suf(d[u].size()+2, 1);
    for (int i=1; i<=d[u].size(); i++) pref[i]=(pref[i-1]*dn[d[u][i-1]])%mod;
    for (int i=d[u].size(); i>=1; i--) suf[i]=(suf[i+1]*dn[d[u][i-1]])%mod;
    for (int i=1; i<=d[u].size(); i++) dp[d[u][i-1]]=((dp[u]*pref[i-1])%mod*suf[i+1])%mod, dfs2(d[u][i-1]);
    //cout<<u<<' '<<dp[u]<<'\n';
}

struct segtree
{
    int d1[2*nx], d2[2*nx];
    bool lz[2*nx];
    void build(int l, int r, int i, vector<int> &t)
    {
        if (l==r) return t[l]?d1[i]=v[l]:d2[i]=v[l], void();
        int md=(l+r)/2;
        build(l, md, 2*i, t);
        build(md+1, r, 2*i+1, t);
        d1[i]=(d1[2*i]+d1[2*i+1])%mod;
        d2[i]=(d2[2*i]+d2[2*i+1])%mod;
    }
    void pushlz(int l, int r, int i)
    {
        if (!lz[i]) return;
        lz[i]=0; swap(d1[i], d2[i]);
        if (l==r) return;
        lz[2*i]=!lz[2*i];
        lz[2*i+1]=!lz[2*i+1];
    }
    void update(int l, int r, int i, int ql, int qr)
    {
        pushlz(l, r, i);
        if (r<ql||qr<l) return;
        if (ql<=l&&r<=qr) return lz[i]=1, pushlz(l, r, i), void();
        int md=(l+r)/2;
        update(l, md, 2*i, ql, qr);
        update(md+1, r, 2*i+1, ql, qr);
        d1[i]=(d1[2*i]+d1[2*i+1])%mod;
        d2[i]=(d2[2*i]+d2[2*i+1])%mod;
    }
} s;
 
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    n=N; m=M;
    for (int i=1; i<N+M; i++) d[P[i]].push_back(i);
    dp[0]=1;
    dfs(0); dfs2(0);
    for (int i=N; i<N+M; i++) v[i-N]=dp[i];
    s.build(0, M-1, 1, A);
}
 
int count_ways(int L, int R) {;
    s.update(0, m-1, 1, L-n, R-n);
    return s.d1[1];
}

Compilation message

circuit.cpp: In function 'void dfs2(int)':
circuit.cpp:26:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for (int i=1; i<=d[u].size(); i++) pref[i]=(pref[i-1]*dn[d[u][i-1]])%mod;
      |                   ~^~~~~~~~~~~~~
circuit.cpp:28:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for (int i=1; i<=d[u].size(); i++) dp[d[u][i-1]]=((dp[u]*pref[i-1])%mod*suf[i+1])%mod, dfs2(d[u][i-1]);
      |                   ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 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 10584 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 10584 KB Output is correct
8 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 10584 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 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 10584 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 10584 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 10584 KB Output is correct
8 Correct 2 ms 12632 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 12632 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 12632 KB Output is correct
14 Correct 2 ms 10584 KB Output is correct
15 Correct 2 ms 12632 KB Output is correct
16 Correct 2 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 10584 KB Output is correct
21 Correct 2 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 10584 KB Output is correct
26 Correct 2 ms 12632 KB Output is correct
27 Correct 2 ms 10584 KB Output is correct
28 Correct 2 ms 12632 KB Output is correct
29 Correct 2 ms 12764 KB Output is correct
30 Correct 3 ms 12632 KB Output is correct
31 Correct 3 ms 12888 KB Output is correct
32 Correct 2 ms 12632 KB Output is correct
33 Correct 2 ms 10584 KB Output is correct
34 Correct 2 ms 12720 KB Output is correct
35 Correct 2 ms 12632 KB Output is correct
36 Correct 2 ms 13084 KB Output is correct
37 Correct 2 ms 12888 KB Output is correct
38 Correct 2 ms 12888 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 2 ms 12632 KB Output is correct
41 Correct 2 ms 12720 KB Output is correct
42 Correct 2 ms 10584 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 378 ms 14672 KB Output is correct
2 Correct 547 ms 16340 KB Output is correct
3 Correct 548 ms 16340 KB Output is correct
4 Correct 545 ms 16464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 378 ms 14672 KB Output is correct
2 Correct 547 ms 16340 KB Output is correct
3 Correct 548 ms 16340 KB Output is correct
4 Correct 545 ms 16464 KB Output is correct
5 Correct 467 ms 14676 KB Output is correct
6 Correct 582 ms 16328 KB Output is correct
7 Correct 583 ms 16320 KB Output is correct
8 Correct 589 ms 16312 KB Output is correct
9 Correct 262 ms 10840 KB Output is correct
10 Correct 560 ms 12888 KB Output is correct
11 Correct 555 ms 12888 KB Output is correct
12 Correct 542 ms 10840 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 10584 KB Output is correct
7 Correct 2 ms 12632 KB Output is correct
8 Correct 2 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 10584 KB Output is correct
13 Correct 378 ms 14672 KB Output is correct
14 Correct 547 ms 16340 KB Output is correct
15 Correct 548 ms 16340 KB Output is correct
16 Correct 545 ms 16464 KB Output is correct
17 Correct 467 ms 14676 KB Output is correct
18 Correct 582 ms 16328 KB Output is correct
19 Correct 583 ms 16320 KB Output is correct
20 Correct 589 ms 16312 KB Output is correct
21 Correct 262 ms 10840 KB Output is correct
22 Correct 560 ms 12888 KB Output is correct
23 Correct 555 ms 12888 KB Output is correct
24 Correct 542 ms 10840 KB Output is correct
25 Correct 603 ms 18124 KB Output is correct
26 Correct 638 ms 18248 KB Output is correct
27 Correct 627 ms 18424 KB Output is correct
28 Correct 496 ms 18248 KB Output is correct
29 Correct 621 ms 38736 KB Output is correct
30 Correct 612 ms 38488 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 10584 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 10584 KB Output is correct
8 Correct 2 ms 12632 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 12632 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 12632 KB Output is correct
14 Correct 2 ms 10584 KB Output is correct
15 Correct 2 ms 12632 KB Output is correct
16 Correct 2 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 10584 KB Output is correct
21 Correct 2 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 10584 KB Output is correct
26 Correct 2 ms 12632 KB Output is correct
27 Correct 2 ms 10584 KB Output is correct
28 Correct 2 ms 12632 KB Output is correct
29 Correct 2 ms 12764 KB Output is correct
30 Correct 3 ms 12632 KB Output is correct
31 Correct 3 ms 12888 KB Output is correct
32 Correct 2 ms 12632 KB Output is correct
33 Correct 2 ms 10584 KB Output is correct
34 Correct 2 ms 12720 KB Output is correct
35 Correct 2 ms 12632 KB Output is correct
36 Correct 2 ms 13084 KB Output is correct
37 Correct 2 ms 12888 KB Output is correct
38 Correct 2 ms 12888 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 2 ms 12632 KB Output is correct
41 Correct 2 ms 12720 KB Output is correct
42 Correct 2 ms 10584 KB Output is correct
43 Correct 357 ms 12888 KB Output is correct
44 Correct 514 ms 12888 KB Output is correct
45 Correct 503 ms 12888 KB Output is correct
46 Correct 510 ms 11096 KB Output is correct
47 Correct 533 ms 11096 KB Output is correct
48 Correct 537 ms 12888 KB Output is correct
49 Correct 563 ms 11096 KB Output is correct
50 Correct 522 ms 12888 KB Output is correct
51 Correct 489 ms 13000 KB Output is correct
52 Correct 505 ms 11020 KB Output is correct
53 Correct 466 ms 13656 KB Output is correct
54 Correct 506 ms 12888 KB Output is correct
55 Correct 519 ms 12888 KB Output is correct
56 Correct 540 ms 12888 KB Output is correct
57 Correct 548 ms 12888 KB Output is correct
58 Correct 571 ms 12120 KB Output is correct
59 Correct 510 ms 13912 KB Output is correct
60 Correct 500 ms 13912 KB Output is correct
61 Correct 548 ms 13144 KB Output is correct
62 Correct 525 ms 12884 KB Output is correct
63 Correct 538 ms 10840 KB Output is correct
64 Correct 548 ms 12888 KB Output is correct
65 Correct 262 ms 10836 KB Output is correct
66 Correct 539 ms 12896 KB Output is correct
67 Correct 522 ms 12888 KB Output is correct
68 Correct 537 ms 11092 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 10584 KB Output is correct
6 Correct 2 ms 10584 KB Output is correct
7 Correct 2 ms 10584 KB Output is correct
8 Correct 2 ms 12632 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 12632 KB Output is correct
12 Correct 2 ms 12632 KB Output is correct
13 Correct 2 ms 12632 KB Output is correct
14 Correct 2 ms 10584 KB Output is correct
15 Correct 2 ms 12632 KB Output is correct
16 Correct 2 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 10584 KB Output is correct
21 Correct 2 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 10584 KB Output is correct
26 Correct 2 ms 12632 KB Output is correct
27 Correct 2 ms 10584 KB Output is correct
28 Correct 2 ms 12632 KB Output is correct
29 Correct 2 ms 12764 KB Output is correct
30 Correct 3 ms 12632 KB Output is correct
31 Correct 3 ms 12888 KB Output is correct
32 Correct 2 ms 12632 KB Output is correct
33 Correct 2 ms 10584 KB Output is correct
34 Correct 2 ms 12720 KB Output is correct
35 Correct 2 ms 12632 KB Output is correct
36 Correct 2 ms 13084 KB Output is correct
37 Correct 2 ms 12888 KB Output is correct
38 Correct 2 ms 12888 KB Output is correct
39 Correct 2 ms 12632 KB Output is correct
40 Correct 2 ms 12632 KB Output is correct
41 Correct 2 ms 12720 KB Output is correct
42 Correct 2 ms 10584 KB Output is correct
43 Correct 378 ms 14672 KB Output is correct
44 Correct 547 ms 16340 KB Output is correct
45 Correct 548 ms 16340 KB Output is correct
46 Correct 545 ms 16464 KB Output is correct
47 Correct 467 ms 14676 KB Output is correct
48 Correct 582 ms 16328 KB Output is correct
49 Correct 583 ms 16320 KB Output is correct
50 Correct 589 ms 16312 KB Output is correct
51 Correct 262 ms 10840 KB Output is correct
52 Correct 560 ms 12888 KB Output is correct
53 Correct 555 ms 12888 KB Output is correct
54 Correct 542 ms 10840 KB Output is correct
55 Correct 603 ms 18124 KB Output is correct
56 Correct 638 ms 18248 KB Output is correct
57 Correct 627 ms 18424 KB Output is correct
58 Correct 496 ms 18248 KB Output is correct
59 Correct 621 ms 38736 KB Output is correct
60 Correct 612 ms 38488 KB Output is correct
61 Correct 357 ms 12888 KB Output is correct
62 Correct 514 ms 12888 KB Output is correct
63 Correct 503 ms 12888 KB Output is correct
64 Correct 510 ms 11096 KB Output is correct
65 Correct 533 ms 11096 KB Output is correct
66 Correct 537 ms 12888 KB Output is correct
67 Correct 563 ms 11096 KB Output is correct
68 Correct 522 ms 12888 KB Output is correct
69 Correct 489 ms 13000 KB Output is correct
70 Correct 505 ms 11020 KB Output is correct
71 Correct 466 ms 13656 KB Output is correct
72 Correct 506 ms 12888 KB Output is correct
73 Correct 519 ms 12888 KB Output is correct
74 Correct 540 ms 12888 KB Output is correct
75 Correct 548 ms 12888 KB Output is correct
76 Correct 571 ms 12120 KB Output is correct
77 Correct 510 ms 13912 KB Output is correct
78 Correct 500 ms 13912 KB Output is correct
79 Correct 548 ms 13144 KB Output is correct
80 Correct 525 ms 12884 KB Output is correct
81 Correct 538 ms 10840 KB Output is correct
82 Correct 548 ms 12888 KB Output is correct
83 Correct 262 ms 10836 KB Output is correct
84 Correct 539 ms 12896 KB Output is correct
85 Correct 522 ms 12888 KB Output is correct
86 Correct 537 ms 11092 KB Output is correct
87 Correct 2 ms 12632 KB Output is correct
88 Correct 362 ms 17836 KB Output is correct
89 Correct 595 ms 16764 KB Output is correct
90 Correct 571 ms 16316 KB Output is correct
91 Correct 606 ms 18252 KB Output is correct
92 Correct 605 ms 18272 KB Output is correct
93 Correct 625 ms 18332 KB Output is correct
94 Correct 612 ms 18256 KB Output is correct
95 Correct 625 ms 18464 KB Output is correct
96 Correct 568 ms 14768 KB Output is correct
97 Correct 596 ms 14904 KB Output is correct
98 Correct 512 ms 33792 KB Output is correct
99 Correct 624 ms 18256 KB Output is correct
100 Correct 579 ms 16264 KB Output is correct
101 Correct 632 ms 15912 KB Output is correct
102 Correct 597 ms 14816 KB Output is correct
103 Correct 624 ms 38644 KB Output is correct
104 Correct 620 ms 35880 KB Output is correct
105 Correct 588 ms 36028 KB Output is correct
106 Correct 579 ms 20568 KB Output is correct
107 Correct 581 ms 15456 KB Output is correct
108 Correct 578 ms 15260 KB Output is correct
109 Correct 567 ms 14968 KB Output is correct