답안 #653500

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
653500 2022-10-27T02:21:27 Z Lobo 디지털 회로 (IOI22_circuit) C++17
100 / 100
1163 ms 39268 KB
#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

const int maxn = 2e5+10;
const int mod = 1000002022;
int n, m, p[maxn], a[maxn];
vector<int> g[maxn];
int c[maxn], pw2[maxn], prd[maxn];
int32_t tr0[4*maxn],tr1[4*maxn],lz[4*maxn];

void build(int no, int l, int r) {
    if(l == r) {
        tr0[no] = (a[l-n] == 0)*prd[l];
        tr1[no] = (a[l-n] == 1)*prd[l];
        return;
    }
    int f1=2*no,f2=2*no+1,mid=(l+r)>>1;
    build(f1,l,mid);
    build(f2,mid+1,r);
    tr0[no] = (tr0[f1]+tr0[f2])%mod;
    tr1[no] = (tr1[f1]+tr1[f2])%mod;
}

void flush(int no, int l, int r) {
    if(lz[no] == 0) return;
    swap(tr0[no],tr1[no]);
    if(l != r) {
        int f1=2*no,f2=2*no+1,mid=(l+r)>>1;
        lz[f1]^= 1;
        lz[f2]^= 1;
    }
    lz[no] = 0;
}

void att(int32_t no, int32_t l, int32_t r, int32_t L, int32_t R) {
    flush(no,l,r);
    if(l > R || r < L) return;
    if(l >= L && r <= R) {
        lz[no] = 1;
        flush(no,l,r);
        return;
    }
    int32_t f1=2*no,f2=2*no+1,mid=(l+r)>>1;
    att(f1,l,mid,L,R);
    att(f2,mid+1,r,L,R);
    tr0[no] = (tr0[f1]+tr0[f2])%mod;
    tr1[no] = (tr1[f1]+tr1[f2])%mod;
}

void dfssz(int u) {
    c[u] = g[u].size();
    if(u >= n) c[u] = 1;
    if(u >= n) return;
    for(auto v : g[u]) {
        dfssz(v);
        c[u] = c[u]*c[v]%mod;
    }
}

void dfs(int u) {
    vector<int> pf(g[u].size()+1), sf(g[u].size()+1);

    for(int i = 0; i < (int) g[u].size(); i++) {
        int v = g[u][i];
        pf[i] = c[v];
        if(i!=0) pf[i] = pf[i]*pf[i-1]%mod;
    }
    for(int i = (int) g[u].size()-1; i >= 0; i--) {
        int v = g[u][i];
        sf[i] = c[v];
        if(i != (int) g[u].size()-1) sf[i] = sf[i]*sf[i+1]%mod;
    }

    for(int i = 0; i < (int) g[u].size(); i++) {
        int v = g[u][i];
        prd[v] = prd[u];
        if(i != 0) prd[v] = prd[v]*pf[i-1]%mod;
        if(i != (int) g[u].size()-1) prd[v] = prd[v]*sf[i+1]%mod;
        dfs(v);
    }
}

int ans = 0;
void init(int32_t N, int32_t M, vector<int32_t> P, vector<int32_t> A) {
    n = N;
    m = M;
    for(int i = 1; i < n+m; i++) {
        p[i] = P[i];
        g[p[i]].pb(i);
    }
    for(int i = 0; i < m; i++) {
        a[i] = A[i];
    }
    dfssz(0);
    prd[0] = 1;
    dfs(0);
    build(1,n,n+m-1);
}
int32_t count_ways(int32_t L, int32_t R) {
    att(1,n,n+m-1,L,R);
    return tr1[1];
}

Compilation message

circuit.cpp: In function 'void flush(long long int, long long int, long long int)':
circuit.cpp:37:31: warning: unused variable 'mid' [-Wunused-variable]
   37 |         int f1=2*no,f2=2*no+1,mid=(l+r)>>1;
      |                               ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 5140 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5028 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 5072 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 4 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 4 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 5140 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5028 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 4 ms 5072 KB Output is correct
15 Correct 4 ms 5072 KB Output is correct
16 Correct 4 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 3 ms 5120 KB Output is correct
23 Correct 4 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 4 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 4 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 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 4 ms 5072 KB Output is correct
36 Correct 4 ms 5328 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 4 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 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 549 ms 9112 KB Output is correct
2 Correct 799 ms 13192 KB Output is correct
3 Correct 784 ms 13192 KB Output is correct
4 Correct 903 ms 13216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 549 ms 9112 KB Output is correct
2 Correct 799 ms 13192 KB Output is correct
3 Correct 784 ms 13192 KB Output is correct
4 Correct 903 ms 13216 KB Output is correct
5 Correct 733 ms 9116 KB Output is correct
6 Correct 1041 ms 13256 KB Output is correct
7 Correct 923 ms 13244 KB Output is correct
8 Correct 913 ms 13132 KB Output is correct
9 Correct 492 ms 5200 KB Output is correct
10 Correct 931 ms 5584 KB Output is correct
11 Correct 795 ms 5568 KB Output is correct
12 Correct 800 ms 5456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 5072 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 4 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 4 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 549 ms 9112 KB Output is correct
14 Correct 799 ms 13192 KB Output is correct
15 Correct 784 ms 13192 KB Output is correct
16 Correct 903 ms 13216 KB Output is correct
17 Correct 733 ms 9116 KB Output is correct
18 Correct 1041 ms 13256 KB Output is correct
19 Correct 923 ms 13244 KB Output is correct
20 Correct 913 ms 13132 KB Output is correct
21 Correct 492 ms 5200 KB Output is correct
22 Correct 931 ms 5584 KB Output is correct
23 Correct 795 ms 5568 KB Output is correct
24 Correct 800 ms 5456 KB Output is correct
25 Correct 900 ms 17864 KB Output is correct
26 Correct 949 ms 18020 KB Output is correct
27 Correct 918 ms 17960 KB Output is correct
28 Correct 843 ms 18024 KB Output is correct
29 Correct 1116 ms 38344 KB Output is correct
30 Correct 959 ms 38308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 5140 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5028 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 4 ms 5072 KB Output is correct
15 Correct 4 ms 5072 KB Output is correct
16 Correct 4 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 3 ms 5120 KB Output is correct
23 Correct 4 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 4 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 4 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 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 4 ms 5072 KB Output is correct
36 Correct 4 ms 5328 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 4 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 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 697 ms 5456 KB Output is correct
44 Correct 954 ms 5456 KB Output is correct
45 Correct 1010 ms 5456 KB Output is correct
46 Correct 855 ms 5712 KB Output is correct
47 Correct 666 ms 5712 KB Output is correct
48 Correct 831 ms 5712 KB Output is correct
49 Correct 761 ms 5712 KB Output is correct
50 Correct 787 ms 5712 KB Output is correct
51 Correct 838 ms 5544 KB Output is correct
52 Correct 874 ms 5588 KB Output is correct
53 Correct 644 ms 6352 KB Output is correct
54 Correct 894 ms 5712 KB Output is correct
55 Correct 970 ms 5584 KB Output is correct
56 Correct 952 ms 5584 KB Output is correct
57 Correct 834 ms 5456 KB Output is correct
58 Correct 889 ms 6736 KB Output is correct
59 Correct 858 ms 6864 KB Output is correct
60 Correct 765 ms 6864 KB Output is correct
61 Correct 614 ms 5712 KB Output is correct
62 Correct 908 ms 5328 KB Output is correct
63 Correct 964 ms 5456 KB Output is correct
64 Correct 884 ms 5528 KB Output is correct
65 Correct 446 ms 5200 KB Output is correct
66 Correct 997 ms 5584 KB Output is correct
67 Correct 1010 ms 5456 KB Output is correct
68 Correct 922 ms 5552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 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 5140 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5028 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 4 ms 5072 KB Output is correct
15 Correct 4 ms 5072 KB Output is correct
16 Correct 4 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 3 ms 5120 KB Output is correct
23 Correct 4 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 4 ms 5072 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 4 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 3 ms 5072 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 4 ms 5072 KB Output is correct
36 Correct 4 ms 5328 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 4 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 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 549 ms 9112 KB Output is correct
44 Correct 799 ms 13192 KB Output is correct
45 Correct 784 ms 13192 KB Output is correct
46 Correct 903 ms 13216 KB Output is correct
47 Correct 733 ms 9116 KB Output is correct
48 Correct 1041 ms 13256 KB Output is correct
49 Correct 923 ms 13244 KB Output is correct
50 Correct 913 ms 13132 KB Output is correct
51 Correct 492 ms 5200 KB Output is correct
52 Correct 931 ms 5584 KB Output is correct
53 Correct 795 ms 5568 KB Output is correct
54 Correct 800 ms 5456 KB Output is correct
55 Correct 900 ms 17864 KB Output is correct
56 Correct 949 ms 18020 KB Output is correct
57 Correct 918 ms 17960 KB Output is correct
58 Correct 843 ms 18024 KB Output is correct
59 Correct 1116 ms 38344 KB Output is correct
60 Correct 959 ms 38308 KB Output is correct
61 Correct 697 ms 5456 KB Output is correct
62 Correct 954 ms 5456 KB Output is correct
63 Correct 1010 ms 5456 KB Output is correct
64 Correct 855 ms 5712 KB Output is correct
65 Correct 666 ms 5712 KB Output is correct
66 Correct 831 ms 5712 KB Output is correct
67 Correct 761 ms 5712 KB Output is correct
68 Correct 787 ms 5712 KB Output is correct
69 Correct 838 ms 5544 KB Output is correct
70 Correct 874 ms 5588 KB Output is correct
71 Correct 644 ms 6352 KB Output is correct
72 Correct 894 ms 5712 KB Output is correct
73 Correct 970 ms 5584 KB Output is correct
74 Correct 952 ms 5584 KB Output is correct
75 Correct 834 ms 5456 KB Output is correct
76 Correct 889 ms 6736 KB Output is correct
77 Correct 858 ms 6864 KB Output is correct
78 Correct 765 ms 6864 KB Output is correct
79 Correct 614 ms 5712 KB Output is correct
80 Correct 908 ms 5328 KB Output is correct
81 Correct 964 ms 5456 KB Output is correct
82 Correct 884 ms 5528 KB Output is correct
83 Correct 446 ms 5200 KB Output is correct
84 Correct 997 ms 5584 KB Output is correct
85 Correct 1010 ms 5456 KB Output is correct
86 Correct 922 ms 5552 KB Output is correct
87 Correct 2 ms 4944 KB Output is correct
88 Correct 572 ms 17316 KB Output is correct
89 Correct 1153 ms 13188 KB Output is correct
90 Correct 945 ms 13272 KB Output is correct
91 Correct 982 ms 18564 KB Output is correct
92 Correct 1059 ms 18632 KB Output is correct
93 Correct 884 ms 18564 KB Output is correct
94 Correct 1153 ms 18632 KB Output is correct
95 Correct 923 ms 18632 KB Output is correct
96 Correct 838 ms 12700 KB Output is correct
97 Correct 927 ms 12948 KB Output is correct
98 Correct 835 ms 31560 KB Output is correct
99 Correct 1163 ms 17928 KB Output is correct
100 Correct 873 ms 15972 KB Output is correct
101 Correct 916 ms 14864 KB Output is correct
102 Correct 916 ms 13036 KB Output is correct
103 Correct 1014 ms 38344 KB Output is correct
104 Correct 1034 ms 39268 KB Output is correct
105 Correct 704 ms 39140 KB Output is correct
106 Correct 941 ms 17480 KB Output is correct
107 Correct 884 ms 13604 KB Output is correct
108 Correct 929 ms 13764 KB Output is correct
109 Correct 951 ms 13304 KB Output is correct