Submission #812532

# Submission time Handle Problem Language Result Execution time Memory
812532 2023-08-07T09:07:11 Z BT21tata Digital Circuit (IOI22_circuit) C++17
100 / 100
997 ms 24196 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)
    {
        old[cnt]=v;
        nw[v]=cnt++;
    }
    for(int u : g[v])
        dfs(u);
}
 
void calc(int v)
{
    if(v>=n)
    {
        a[v-n]=(1ll*prv*suff[cnt])%MOD;
        return;
    }
    else cnt++;
    
    for(int u : g[v])
        calc(u);
    
    if(v<n) 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);
 
    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;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 4 ms 4944 KB Output is correct
3 Correct 3 ms 5092 KB Output is correct
4 Correct 3 ms 5104 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 3 ms 5044 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 3 ms 5092 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 2 ms 5092 KB Output is correct
6 Correct 3 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 3 ms 5072 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 3 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 4 ms 4944 KB Output is correct
3 Correct 3 ms 5092 KB Output is correct
4 Correct 3 ms 5104 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 3 ms 5044 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5092 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 2 ms 5092 KB Output is correct
14 Correct 3 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 3 ms 5072 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 3 ms 5200 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 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 5120 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 5052 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 2 ms 5072 KB Output is correct
32 Correct 2 ms 5072 KB Output is correct
33 Correct 4 ms 5072 KB Output is correct
34 Correct 2 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5072 KB Output is correct
37 Correct 3 ms 5200 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 5000 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 4 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 456 ms 9116 KB Output is correct
2 Correct 916 ms 13212 KB Output is correct
3 Correct 716 ms 13204 KB Output is correct
4 Correct 907 ms 13168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 456 ms 9116 KB Output is correct
2 Correct 916 ms 13212 KB Output is correct
3 Correct 716 ms 13204 KB Output is correct
4 Correct 907 ms 13168 KB Output is correct
5 Correct 488 ms 9096 KB Output is correct
6 Correct 767 ms 13188 KB Output is correct
7 Correct 753 ms 13128 KB Output is correct
8 Correct 646 ms 13188 KB Output is correct
9 Correct 325 ms 5200 KB Output is correct
10 Correct 596 ms 5432 KB Output is correct
11 Correct 786 ms 5456 KB Output is correct
12 Correct 895 ms 5456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 3 ms 5092 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 2 ms 5092 KB Output is correct
6 Correct 3 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 3 ms 5072 KB Output is correct
11 Correct 4 ms 5120 KB Output is correct
12 Correct 3 ms 5200 KB Output is correct
13 Correct 456 ms 9116 KB Output is correct
14 Correct 916 ms 13212 KB Output is correct
15 Correct 716 ms 13204 KB Output is correct
16 Correct 907 ms 13168 KB Output is correct
17 Correct 488 ms 9096 KB Output is correct
18 Correct 767 ms 13188 KB Output is correct
19 Correct 753 ms 13128 KB Output is correct
20 Correct 646 ms 13188 KB Output is correct
21 Correct 325 ms 5200 KB Output is correct
22 Correct 596 ms 5432 KB Output is correct
23 Correct 786 ms 5456 KB Output is correct
24 Correct 895 ms 5456 KB Output is correct
25 Correct 755 ms 18824 KB Output is correct
26 Correct 790 ms 18992 KB Output is correct
27 Correct 974 ms 18972 KB Output is correct
28 Correct 548 ms 18936 KB Output is correct
29 Correct 691 ms 23672 KB Output is correct
30 Correct 643 ms 23576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 4 ms 4944 KB Output is correct
3 Correct 3 ms 5092 KB Output is correct
4 Correct 3 ms 5104 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 3 ms 5044 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5092 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 2 ms 5092 KB Output is correct
14 Correct 3 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 3 ms 5072 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 3 ms 5200 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 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 5120 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 5052 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 2 ms 5072 KB Output is correct
32 Correct 2 ms 5072 KB Output is correct
33 Correct 4 ms 5072 KB Output is correct
34 Correct 2 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5072 KB Output is correct
37 Correct 3 ms 5200 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 5000 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 4 ms 5072 KB Output is correct
43 Correct 686 ms 5328 KB Output is correct
44 Correct 565 ms 5456 KB Output is correct
45 Correct 703 ms 5456 KB Output is correct
46 Correct 791 ms 5776 KB Output is correct
47 Correct 575 ms 5764 KB Output is correct
48 Correct 862 ms 5712 KB Output is correct
49 Correct 474 ms 5812 KB Output is correct
50 Correct 775 ms 5792 KB Output is correct
51 Correct 480 ms 5456 KB Output is correct
52 Correct 726 ms 5632 KB Output is correct
53 Correct 751 ms 5512 KB Output is correct
54 Correct 730 ms 5712 KB Output is correct
55 Correct 922 ms 5584 KB Output is correct
56 Correct 654 ms 5516 KB Output is correct
57 Correct 717 ms 5524 KB Output is correct
58 Correct 736 ms 6028 KB Output is correct
59 Correct 721 ms 6072 KB Output is correct
60 Correct 701 ms 6080 KB Output is correct
61 Correct 640 ms 5456 KB Output is correct
62 Correct 806 ms 5364 KB Output is correct
63 Correct 809 ms 5388 KB Output is correct
64 Correct 690 ms 5456 KB Output is correct
65 Correct 365 ms 5200 KB Output is correct
66 Correct 713 ms 5516 KB Output is correct
67 Correct 639 ms 5456 KB Output is correct
68 Correct 904 ms 5504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 4 ms 4944 KB Output is correct
3 Correct 3 ms 5092 KB Output is correct
4 Correct 3 ms 5104 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 3 ms 5044 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5092 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 2 ms 5092 KB Output is correct
14 Correct 3 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 3 ms 5072 KB Output is correct
19 Correct 4 ms 5120 KB Output is correct
20 Correct 3 ms 5200 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 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 5120 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 5052 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 2 ms 5072 KB Output is correct
32 Correct 2 ms 5072 KB Output is correct
33 Correct 4 ms 5072 KB Output is correct
34 Correct 2 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5072 KB Output is correct
37 Correct 3 ms 5200 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 5000 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 4 ms 5072 KB Output is correct
43 Correct 456 ms 9116 KB Output is correct
44 Correct 916 ms 13212 KB Output is correct
45 Correct 716 ms 13204 KB Output is correct
46 Correct 907 ms 13168 KB Output is correct
47 Correct 488 ms 9096 KB Output is correct
48 Correct 767 ms 13188 KB Output is correct
49 Correct 753 ms 13128 KB Output is correct
50 Correct 646 ms 13188 KB Output is correct
51 Correct 325 ms 5200 KB Output is correct
52 Correct 596 ms 5432 KB Output is correct
53 Correct 786 ms 5456 KB Output is correct
54 Correct 895 ms 5456 KB Output is correct
55 Correct 755 ms 18824 KB Output is correct
56 Correct 790 ms 18992 KB Output is correct
57 Correct 974 ms 18972 KB Output is correct
58 Correct 548 ms 18936 KB Output is correct
59 Correct 691 ms 23672 KB Output is correct
60 Correct 643 ms 23576 KB Output is correct
61 Correct 686 ms 5328 KB Output is correct
62 Correct 565 ms 5456 KB Output is correct
63 Correct 703 ms 5456 KB Output is correct
64 Correct 791 ms 5776 KB Output is correct
65 Correct 575 ms 5764 KB Output is correct
66 Correct 862 ms 5712 KB Output is correct
67 Correct 474 ms 5812 KB Output is correct
68 Correct 775 ms 5792 KB Output is correct
69 Correct 480 ms 5456 KB Output is correct
70 Correct 726 ms 5632 KB Output is correct
71 Correct 751 ms 5512 KB Output is correct
72 Correct 730 ms 5712 KB Output is correct
73 Correct 922 ms 5584 KB Output is correct
74 Correct 654 ms 5516 KB Output is correct
75 Correct 717 ms 5524 KB Output is correct
76 Correct 736 ms 6028 KB Output is correct
77 Correct 721 ms 6072 KB Output is correct
78 Correct 701 ms 6080 KB Output is correct
79 Correct 640 ms 5456 KB Output is correct
80 Correct 806 ms 5364 KB Output is correct
81 Correct 809 ms 5388 KB Output is correct
82 Correct 690 ms 5456 KB Output is correct
83 Correct 365 ms 5200 KB Output is correct
84 Correct 713 ms 5516 KB Output is correct
85 Correct 639 ms 5456 KB Output is correct
86 Correct 904 ms 5504 KB Output is correct
87 Correct 2 ms 4944 KB Output is correct
88 Correct 456 ms 18300 KB Output is correct
89 Correct 699 ms 13556 KB Output is correct
90 Correct 997 ms 13148 KB Output is correct
91 Correct 800 ms 19072 KB Output is correct
92 Correct 930 ms 19048 KB Output is correct
93 Correct 769 ms 19060 KB Output is correct
94 Correct 863 ms 19060 KB Output is correct
95 Correct 678 ms 19100 KB Output is correct
96 Correct 626 ms 13976 KB Output is correct
97 Correct 690 ms 14076 KB Output is correct
98 Correct 591 ms 15116 KB Output is correct
99 Correct 863 ms 18944 KB Output is correct
100 Correct 738 ms 16260 KB Output is correct
101 Correct 725 ms 15400 KB Output is correct
102 Correct 688 ms 13996 KB Output is correct
103 Correct 747 ms 23692 KB Output is correct
104 Correct 713 ms 24192 KB Output is correct
105 Correct 737 ms 24196 KB Output is correct
106 Correct 707 ms 14220 KB Output is correct
107 Correct 771 ms 14076 KB Output is correct
108 Correct 753 ms 14720 KB Output is correct
109 Correct 774 ms 14084 KB Output is correct