답안 #745274

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
745274 2023-05-19T17:17:00 Z doowey 디지털 회로 (IOI22_circuit) C++17
100 / 100
1092 ms 37540 KB
#include <bits/stdc++.h>
#include "circuit.h"

using namespace std;

typedef long long ll;

const int N = (int)2e5 + 10;
const int MOD = (int)1e9 + 2022;
vector<int> T[N];
int W[N];
int n, m;

void dfs0(int u){
    if(T[u].empty()) W[u] = 1;
    else{
        W[u] = 1;
        for(auto x : T[u]){
            dfs0(x);
            W[u] = (W[u] * 1ll * W[x]) % MOD;
        }
        W[u] = (W[u] * 1ll * T[u].size()) % MOD;
    }
}

int coeff[N];



void dfs1(int u, int wei){
    if(T[u].empty()){
        coeff[u - n] = wei;
        return;
    }
    vector<int> pre, suff;
    for(auto x : T[u]){
        pre.push_back(W[x]);
        suff.push_back(W[x]);
    }
    for(int i = 1; i < pre.size(); i ++ ){
        pre[i] = (pre[i - 1] * 1ll * pre[i]) % MOD;
    }
    for(int i = (int)suff.size() - 2; i >= 0 ; i -- ){
        suff[i] = (suff[i] * 1ll * suff[i + 1]) % MOD;
    }
    int cf;
    for(int i = 0 ;i < T[u].size(); i ++ ){
        cf = 1;
        if(i) cf = (cf * 1ll * pre[i - 1]) % MOD;
        if(i + 1 < T[u].size()) cf = (cf * 1ll * suff[i + 1]) % MOD;
        dfs1(T[u][i], (wei * 1ll * cf) % MOD);
    }

}

vector<int> A;

struct Node{
    int total;
    int cum;
    int flip;
};

Node tr[N * 4 + 512];

void build(int node, int cl, int cr){
    tr[node].total = 0;
    tr[node].cum = 0;
    tr[node].flip = 0;
    if(cl == cr){
        tr[node].total = coeff[cl];
        if(A[cl]) tr[node].cum = coeff[cl];
        return;
    }
    int mid = (cl + cr) / 2;
    build(node * 2, cl, mid);
    build(node * 2 + 1, mid + 1, cr);
    tr[node].total = (tr[node * 2].total + tr[node * 2 + 1].total) % MOD;
    tr[node].cum = (tr[node * 2].cum + tr[node * 2 + 1].cum) % MOD;
}

void init(int _n, int _m, std::vector<int> P, vector<int> _A) {
    n = _n;
    m = _m;
    A = _A;
    for(int i = 1; i < n + m; i ++ ){
        T[P[i]].push_back(i);
    }
    dfs0(0);
    dfs1(0, 1);
    build(1, 0, m - 1);
}

void push(int node, int cl, int cr){
    if(tr[node].flip){
        tr[node].cum = (tr[node].total - tr[node].cum + MOD) % MOD;
        if(cl != cr){
            tr[node * 2].flip ^= 1;
            tr[node * 2 + 1].flip ^= 1;
        }
        tr[node].flip = 0;
    }
}

void inv(int node, int cl, int cr, int tl, int rr){
    push(node, cl, cr);
    if(cr < tl || cl > rr) return;
    if(cl >= tl && cr <= rr){
        tr[node].flip=1;
        push(node,cl,cr);
        return;
    }
    int mid = (cl + cr) / 2;
    inv(node * 2, cl, mid, tl, rr);
    inv(node * 2 + 1, mid + 1, cr, tl, rr);
    tr[node].cum = (tr[node * 2].cum + tr[node * 2 + 1].cum) % MOD;
}

int count_ways(int li, int ri) {
    inv(1, 0, m - 1, li - n, ri - n);
    return tr[1].cum;
}

Compilation message

circuit.cpp: In function 'void dfs1(int, int)':
circuit.cpp:40:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i = 1; i < pre.size(); i ++ ){
      |                    ~~^~~~~~~~~~~~
circuit.cpp:47:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |     for(int i = 0 ;i < T[u].size(); i ++ ){
      |                    ~~^~~~~~~~~~~~~
circuit.cpp:50:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |         if(i + 1 < T[u].size()) cf = (cf * 1ll * suff[i + 1]) % MOD;
      |            ~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 4 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 4992 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 4 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 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 4 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 4 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 3 ms 5072 KB Output is correct
24 Correct 5 ms 5072 KB Output is correct
25 Correct 4 ms 5012 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 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 4 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 5 ms 5072 KB Output is correct
35 Correct 3 ms 4944 KB Output is correct
36 Correct 4 ms 5200 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 4972 KB Output is correct
42 Correct 3 ms 4944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 660 ms 8036 KB Output is correct
2 Correct 913 ms 11152 KB Output is correct
3 Correct 849 ms 11180 KB Output is correct
4 Correct 740 ms 11168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 660 ms 8036 KB Output is correct
2 Correct 913 ms 11152 KB Output is correct
3 Correct 849 ms 11180 KB Output is correct
4 Correct 740 ms 11168 KB Output is correct
5 Correct 671 ms 8084 KB Output is correct
6 Correct 696 ms 11080 KB Output is correct
7 Correct 955 ms 11128 KB Output is correct
8 Correct 895 ms 11120 KB Output is correct
9 Correct 398 ms 5200 KB Output is correct
10 Correct 961 ms 5328 KB Output is correct
11 Correct 802 ms 5328 KB Output is correct
12 Correct 818 ms 5328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4952 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 4944 KB Output is correct
4 Correct 4 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 4992 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 4 ms 5200 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 660 ms 8036 KB Output is correct
14 Correct 913 ms 11152 KB Output is correct
15 Correct 849 ms 11180 KB Output is correct
16 Correct 740 ms 11168 KB Output is correct
17 Correct 671 ms 8084 KB Output is correct
18 Correct 696 ms 11080 KB Output is correct
19 Correct 955 ms 11128 KB Output is correct
20 Correct 895 ms 11120 KB Output is correct
21 Correct 398 ms 5200 KB Output is correct
22 Correct 961 ms 5328 KB Output is correct
23 Correct 802 ms 5328 KB Output is correct
24 Correct 818 ms 5328 KB Output is correct
25 Correct 850 ms 15108 KB Output is correct
26 Correct 814 ms 15004 KB Output is correct
27 Correct 1000 ms 15176 KB Output is correct
28 Correct 810 ms 15124 KB Output is correct
29 Correct 820 ms 36936 KB Output is correct
30 Correct 779 ms 37024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 4 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 4 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 3 ms 5072 KB Output is correct
24 Correct 5 ms 5072 KB Output is correct
25 Correct 4 ms 5012 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 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 4 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 5 ms 5072 KB Output is correct
35 Correct 3 ms 4944 KB Output is correct
36 Correct 4 ms 5200 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 4972 KB Output is correct
42 Correct 3 ms 4944 KB Output is correct
43 Correct 665 ms 5200 KB Output is correct
44 Correct 984 ms 5328 KB Output is correct
45 Correct 855 ms 5328 KB Output is correct
46 Correct 831 ms 5456 KB Output is correct
47 Correct 924 ms 5456 KB Output is correct
48 Correct 967 ms 5456 KB Output is correct
49 Correct 667 ms 5456 KB Output is correct
50 Correct 840 ms 5456 KB Output is correct
51 Correct 1008 ms 5440 KB Output is correct
52 Correct 742 ms 5456 KB Output is correct
53 Correct 663 ms 6224 KB Output is correct
54 Correct 892 ms 5456 KB Output is correct
55 Correct 816 ms 5328 KB Output is correct
56 Correct 951 ms 5328 KB Output is correct
57 Correct 816 ms 5328 KB Output is correct
58 Correct 810 ms 6608 KB Output is correct
59 Correct 784 ms 6736 KB Output is correct
60 Correct 754 ms 6736 KB Output is correct
61 Correct 843 ms 5584 KB Output is correct
62 Correct 678 ms 5200 KB Output is correct
63 Correct 852 ms 5200 KB Output is correct
64 Correct 684 ms 5328 KB Output is correct
65 Correct 348 ms 5200 KB Output is correct
66 Correct 871 ms 5328 KB Output is correct
67 Correct 831 ms 5328 KB Output is correct
68 Correct 790 ms 5328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4952 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 4944 KB Output is correct
12 Correct 4 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 4 ms 4992 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 4 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 3 ms 5072 KB Output is correct
24 Correct 5 ms 5072 KB Output is correct
25 Correct 4 ms 5012 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 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 4 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 5 ms 5072 KB Output is correct
35 Correct 3 ms 4944 KB Output is correct
36 Correct 4 ms 5200 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 4972 KB Output is correct
42 Correct 3 ms 4944 KB Output is correct
43 Correct 660 ms 8036 KB Output is correct
44 Correct 913 ms 11152 KB Output is correct
45 Correct 849 ms 11180 KB Output is correct
46 Correct 740 ms 11168 KB Output is correct
47 Correct 671 ms 8084 KB Output is correct
48 Correct 696 ms 11080 KB Output is correct
49 Correct 955 ms 11128 KB Output is correct
50 Correct 895 ms 11120 KB Output is correct
51 Correct 398 ms 5200 KB Output is correct
52 Correct 961 ms 5328 KB Output is correct
53 Correct 802 ms 5328 KB Output is correct
54 Correct 818 ms 5328 KB Output is correct
55 Correct 850 ms 15108 KB Output is correct
56 Correct 814 ms 15004 KB Output is correct
57 Correct 1000 ms 15176 KB Output is correct
58 Correct 810 ms 15124 KB Output is correct
59 Correct 820 ms 36936 KB Output is correct
60 Correct 779 ms 37024 KB Output is correct
61 Correct 665 ms 5200 KB Output is correct
62 Correct 984 ms 5328 KB Output is correct
63 Correct 855 ms 5328 KB Output is correct
64 Correct 831 ms 5456 KB Output is correct
65 Correct 924 ms 5456 KB Output is correct
66 Correct 967 ms 5456 KB Output is correct
67 Correct 667 ms 5456 KB Output is correct
68 Correct 840 ms 5456 KB Output is correct
69 Correct 1008 ms 5440 KB Output is correct
70 Correct 742 ms 5456 KB Output is correct
71 Correct 663 ms 6224 KB Output is correct
72 Correct 892 ms 5456 KB Output is correct
73 Correct 816 ms 5328 KB Output is correct
74 Correct 951 ms 5328 KB Output is correct
75 Correct 816 ms 5328 KB Output is correct
76 Correct 810 ms 6608 KB Output is correct
77 Correct 784 ms 6736 KB Output is correct
78 Correct 754 ms 6736 KB Output is correct
79 Correct 843 ms 5584 KB Output is correct
80 Correct 678 ms 5200 KB Output is correct
81 Correct 852 ms 5200 KB Output is correct
82 Correct 684 ms 5328 KB Output is correct
83 Correct 348 ms 5200 KB Output is correct
84 Correct 871 ms 5328 KB Output is correct
85 Correct 831 ms 5328 KB Output is correct
86 Correct 790 ms 5328 KB Output is correct
87 Correct 2 ms 4944 KB Output is correct
88 Correct 591 ms 14436 KB Output is correct
89 Correct 902 ms 11208 KB Output is correct
90 Correct 1000 ms 11012 KB Output is correct
91 Correct 891 ms 15236 KB Output is correct
92 Correct 761 ms 15316 KB Output is correct
93 Correct 1083 ms 15224 KB Output is correct
94 Correct 1092 ms 15240 KB Output is correct
95 Correct 1070 ms 15232 KB Output is correct
96 Correct 904 ms 11300 KB Output is correct
97 Correct 937 ms 11280 KB Output is correct
98 Correct 631 ms 31128 KB Output is correct
99 Correct 944 ms 15104 KB Output is correct
100 Correct 913 ms 12896 KB Output is correct
101 Correct 957 ms 12408 KB Output is correct
102 Correct 915 ms 11264 KB Output is correct
103 Correct 1006 ms 37016 KB Output is correct
104 Correct 930 ms 37540 KB Output is correct
105 Correct 949 ms 37484 KB Output is correct
106 Correct 893 ms 15688 KB Output is correct
107 Correct 851 ms 11592 KB Output is correct
108 Correct 951 ms 11592 KB Output is correct
109 Correct 961 ms 11400 KB Output is correct