답안 #812557

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
812557 2023-08-07T09:17:37 Z BT21tata 디지털 회로 (IOI22_circuit) C++17
100 / 100
1044 ms 24224 KB
#include "circuit.h"
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;
const ll MOD=1e9+2022;
const int N=2e5+5;
 
struct tree
{
    ll one, zero, lazy;
}t[4*N];
 
int nw[N], cnt, old[N], n, m;
ll suff[N], prv=1, a[N];
vector<int>g[N];
 
void dfs(int v)
{
    if(v>=n) return;    
    old[cnt]=v;
    nw[v]=cnt++;
    for(int u : g[v])
        dfs(u);
}
 
void calc(int v, int p)
{
    if(v>=n)
    {
        a[v-n]=(1ll*prv*suff[cnt])%MOD;
        return;
    }
    cnt++;
    
    for(int u : g[v])
        calc(u, v);
    
    prv=(1ll*prv*g[v].size())%MOD;
}
 
void build(int v, int l, int r, vector<int>&state)
{
    if(l==r)
    {
        if(state[l]) t[v]={a[l], 0, 0};
        else t[v]={0, a[l], 0};
        return;
    }
    
    int mid=(l+r)>>1;
    build(v<<1, l, mid, state);
    build(v<<1|1, mid+1, r, state);
 
    t[v]={(t[v<<1].one+t[v<<1|1].one)%MOD, (t[v<<1].zero+t[v<<1|1].zero)%MOD, 0};
}
 
void push(int v, int l, int r)
{
    swap(t[v].zero, t[v].one);
    t[v].lazy=0;
    if(l!=r)
    {
        t[v<<1].lazy^=1;
        t[v<<1|1].lazy^=1;
    }
}
 
void update(int v, int l, int r, int tl, int tr)
{
    if(t[v].lazy) push(v, l, r);
    if(r<tl or tr<l) return;
    if(tl<=l and r<=tr)
    {
        push(v, l, r);
        return;
    }
 
    int mid=(l+r)>>1;
    update(v<<1, l, mid, tl, tr);
    update(v<<1|1, mid+1, r, tl, tr);
 
    t[v]={(t[v<<1].one+t[v<<1|1].one)%MOD, (t[v<<1].zero+t[v<<1|1].zero)%MOD, 0};
}
 
void init(int N, int M, vector<int> p, vector<int> state)
{
    n=N; m=M;
    for(int i=1; i<n+m; i++)
        g[p[i]].push_back(i);
 
    dfs(0);
 
    suff[n]=1;
    for(int i=n-1; i>=0; i--)
    {
        suff[i]=1ll*suff[i+1]*g[old[i]].size();
        suff[i]%=MOD;
    }
    
    cnt=0;
    calc(0, -1);
 
    build(1, 0, m-1, state);
}
 
int count_ways(int l, int r)
{
    update(1, 0, m-1, l-n, r-n);
    return t[1].one;
}
# 결과 실행 시간 메모리 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 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 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 5072 KB Output is correct
10 Correct 4 ms 5200 KB Output is correct
11 Correct 2 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 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 2 ms 5072 KB Output is correct
14 Correct 2 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 2 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 2 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 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 2 ms 5072 KB Output is correct
31 Correct 2 ms 5072 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 2 ms 5072 KB Output is correct
34 Correct 3 ms 5004 KB Output is correct
35 Correct 2 ms 5072 KB Output is correct
36 Correct 3 ms 5072 KB Output is correct
37 Correct 4 ms 5208 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 2 ms 5072 KB Output is correct
42 Correct 2 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 421 ms 9060 KB Output is correct
2 Correct 649 ms 13132 KB Output is correct
3 Correct 753 ms 13196 KB Output is correct
4 Correct 873 ms 13188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 421 ms 9060 KB Output is correct
2 Correct 649 ms 13132 KB Output is correct
3 Correct 753 ms 13196 KB Output is correct
4 Correct 873 ms 13188 KB Output is correct
5 Correct 710 ms 9040 KB Output is correct
6 Correct 908 ms 13240 KB Output is correct
7 Correct 777 ms 13176 KB Output is correct
8 Correct 646 ms 13120 KB Output is correct
9 Correct 326 ms 5200 KB Output is correct
10 Correct 616 ms 5456 KB Output is correct
11 Correct 630 ms 5456 KB Output is correct
12 Correct 975 ms 5456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 2 ms 5072 KB Output is correct
5 Correct 2 ms 5072 KB Output is correct
6 Correct 2 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 5072 KB Output is correct
10 Correct 4 ms 5200 KB Output is correct
11 Correct 2 ms 5200 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 421 ms 9060 KB Output is correct
14 Correct 649 ms 13132 KB Output is correct
15 Correct 753 ms 13196 KB Output is correct
16 Correct 873 ms 13188 KB Output is correct
17 Correct 710 ms 9040 KB Output is correct
18 Correct 908 ms 13240 KB Output is correct
19 Correct 777 ms 13176 KB Output is correct
20 Correct 646 ms 13120 KB Output is correct
21 Correct 326 ms 5200 KB Output is correct
22 Correct 616 ms 5456 KB Output is correct
23 Correct 630 ms 5456 KB Output is correct
24 Correct 975 ms 5456 KB Output is correct
25 Correct 799 ms 18852 KB Output is correct
26 Correct 1044 ms 18948 KB Output is correct
27 Correct 978 ms 18992 KB Output is correct
28 Correct 585 ms 18976 KB Output is correct
29 Correct 884 ms 23680 KB Output is correct
30 Correct 834 ms 23684 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 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 2 ms 5072 KB Output is correct
14 Correct 2 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 2 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 2 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 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 2 ms 5072 KB Output is correct
31 Correct 2 ms 5072 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 2 ms 5072 KB Output is correct
34 Correct 3 ms 5004 KB Output is correct
35 Correct 2 ms 5072 KB Output is correct
36 Correct 3 ms 5072 KB Output is correct
37 Correct 4 ms 5208 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 2 ms 5072 KB Output is correct
42 Correct 2 ms 5072 KB Output is correct
43 Correct 453 ms 5328 KB Output is correct
44 Correct 751 ms 5456 KB Output is correct
45 Correct 618 ms 5456 KB Output is correct
46 Correct 671 ms 5804 KB Output is correct
47 Correct 610 ms 5712 KB Output is correct
48 Correct 751 ms 5712 KB Output is correct
49 Correct 808 ms 5712 KB Output is correct
50 Correct 678 ms 5712 KB Output is correct
51 Correct 714 ms 5456 KB Output is correct
52 Correct 655 ms 5584 KB Output is correct
53 Correct 673 ms 5456 KB Output is correct
54 Correct 705 ms 5712 KB Output is correct
55 Correct 589 ms 5584 KB Output is correct
56 Correct 850 ms 5584 KB Output is correct
57 Correct 748 ms 5536 KB Output is correct
58 Correct 639 ms 5968 KB Output is correct
59 Correct 616 ms 6076 KB Output is correct
60 Correct 729 ms 6076 KB Output is correct
61 Correct 696 ms 5456 KB Output is correct
62 Correct 830 ms 5328 KB Output is correct
63 Correct 759 ms 5328 KB Output is correct
64 Correct 663 ms 5456 KB Output is correct
65 Correct 430 ms 5200 KB Output is correct
66 Correct 787 ms 5456 KB Output is correct
67 Correct 652 ms 5456 KB Output is correct
68 Correct 883 ms 5456 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 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 2 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 2 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 2 ms 5072 KB Output is correct
13 Correct 2 ms 5072 KB Output is correct
14 Correct 2 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 2 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 2 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 3 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 2 ms 5072 KB Output is correct
31 Correct 2 ms 5072 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 2 ms 5072 KB Output is correct
34 Correct 3 ms 5004 KB Output is correct
35 Correct 2 ms 5072 KB Output is correct
36 Correct 3 ms 5072 KB Output is correct
37 Correct 4 ms 5208 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 2 ms 5072 KB Output is correct
42 Correct 2 ms 5072 KB Output is correct
43 Correct 421 ms 9060 KB Output is correct
44 Correct 649 ms 13132 KB Output is correct
45 Correct 753 ms 13196 KB Output is correct
46 Correct 873 ms 13188 KB Output is correct
47 Correct 710 ms 9040 KB Output is correct
48 Correct 908 ms 13240 KB Output is correct
49 Correct 777 ms 13176 KB Output is correct
50 Correct 646 ms 13120 KB Output is correct
51 Correct 326 ms 5200 KB Output is correct
52 Correct 616 ms 5456 KB Output is correct
53 Correct 630 ms 5456 KB Output is correct
54 Correct 975 ms 5456 KB Output is correct
55 Correct 799 ms 18852 KB Output is correct
56 Correct 1044 ms 18948 KB Output is correct
57 Correct 978 ms 18992 KB Output is correct
58 Correct 585 ms 18976 KB Output is correct
59 Correct 884 ms 23680 KB Output is correct
60 Correct 834 ms 23684 KB Output is correct
61 Correct 453 ms 5328 KB Output is correct
62 Correct 751 ms 5456 KB Output is correct
63 Correct 618 ms 5456 KB Output is correct
64 Correct 671 ms 5804 KB Output is correct
65 Correct 610 ms 5712 KB Output is correct
66 Correct 751 ms 5712 KB Output is correct
67 Correct 808 ms 5712 KB Output is correct
68 Correct 678 ms 5712 KB Output is correct
69 Correct 714 ms 5456 KB Output is correct
70 Correct 655 ms 5584 KB Output is correct
71 Correct 673 ms 5456 KB Output is correct
72 Correct 705 ms 5712 KB Output is correct
73 Correct 589 ms 5584 KB Output is correct
74 Correct 850 ms 5584 KB Output is correct
75 Correct 748 ms 5536 KB Output is correct
76 Correct 639 ms 5968 KB Output is correct
77 Correct 616 ms 6076 KB Output is correct
78 Correct 729 ms 6076 KB Output is correct
79 Correct 696 ms 5456 KB Output is correct
80 Correct 830 ms 5328 KB Output is correct
81 Correct 759 ms 5328 KB Output is correct
82 Correct 663 ms 5456 KB Output is correct
83 Correct 430 ms 5200 KB Output is correct
84 Correct 787 ms 5456 KB Output is correct
85 Correct 652 ms 5456 KB Output is correct
86 Correct 883 ms 5456 KB Output is correct
87 Correct 3 ms 4944 KB Output is correct
88 Correct 578 ms 18208 KB Output is correct
89 Correct 827 ms 13556 KB Output is correct
90 Correct 646 ms 13120 KB Output is correct
91 Correct 639 ms 19036 KB Output is correct
92 Correct 528 ms 19092 KB Output is correct
93 Correct 740 ms 19208 KB Output is correct
94 Correct 747 ms 19104 KB Output is correct
95 Correct 650 ms 19076 KB Output is correct
96 Correct 732 ms 14016 KB Output is correct
97 Correct 733 ms 13964 KB Output is correct
98 Correct 599 ms 15108 KB Output is correct
99 Correct 785 ms 18976 KB Output is correct
100 Correct 618 ms 16260 KB Output is correct
101 Correct 801 ms 15364 KB Output is correct
102 Correct 708 ms 14024 KB Output is correct
103 Correct 728 ms 23596 KB Output is correct
104 Correct 696 ms 24224 KB Output is correct
105 Correct 841 ms 24184 KB Output is correct
106 Correct 559 ms 14288 KB Output is correct
107 Correct 800 ms 14024 KB Output is correct
108 Correct 785 ms 14664 KB Output is correct
109 Correct 771 ms 14024 KB Output is correct