Submission #938494

# Submission time Handle Problem Language Result Execution time Memory
938494 2024-03-05T08:08:29 Z Trisanu_Das Digital Circuit (IOI22_circuit) C++17
100 / 100
685 ms 27036 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;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 3 ms 8792 KB Output is correct
3 Correct 2 ms 8868 KB Output is correct
4 Correct 2 ms 8792 KB Output is correct
5 Correct 2 ms 8792 KB Output is correct
6 Correct 2 ms 8792 KB Output is correct
7 Correct 2 ms 8800 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8792 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Correct 2 ms 8792 KB Output is correct
5 Correct 2 ms 8792 KB Output is correct
6 Correct 2 ms 8792 KB Output is correct
7 Correct 2 ms 8792 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 8792 KB Output is correct
10 Correct 2 ms 8792 KB Output is correct
11 Correct 2 ms 8792 KB Output is correct
12 Correct 2 ms 8792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 3 ms 8792 KB Output is correct
3 Correct 2 ms 8868 KB Output is correct
4 Correct 2 ms 8792 KB Output is correct
5 Correct 2 ms 8792 KB Output is correct
6 Correct 2 ms 8792 KB Output is correct
7 Correct 2 ms 8800 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 8792 KB Output is correct
10 Correct 2 ms 8792 KB Output is correct
11 Correct 2 ms 8792 KB Output is correct
12 Correct 2 ms 8792 KB Output is correct
13 Correct 2 ms 8792 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 2 ms 8792 KB Output is correct
16 Correct 2 ms 8792 KB Output is correct
17 Correct 2 ms 8792 KB Output is correct
18 Correct 2 ms 8792 KB Output is correct
19 Correct 2 ms 8792 KB Output is correct
20 Correct 2 ms 8792 KB Output is correct
21 Correct 2 ms 8792 KB Output is correct
22 Correct 2 ms 8792 KB Output is correct
23 Correct 2 ms 8792 KB Output is correct
24 Correct 2 ms 8792 KB Output is correct
25 Correct 2 ms 8792 KB Output is correct
26 Correct 2 ms 8792 KB Output is correct
27 Correct 3 ms 8792 KB Output is correct
28 Correct 2 ms 8792 KB Output is correct
29 Correct 2 ms 8792 KB Output is correct
30 Correct 2 ms 8792 KB Output is correct
31 Correct 2 ms 8792 KB Output is correct
32 Correct 3 ms 8792 KB Output is correct
33 Correct 2 ms 8792 KB Output is correct
34 Correct 2 ms 8792 KB Output is correct
35 Correct 2 ms 8792 KB Output is correct
36 Correct 3 ms 8792 KB Output is correct
37 Correct 2 ms 8792 KB Output is correct
38 Correct 2 ms 8792 KB Output is correct
39 Correct 2 ms 8792 KB Output is correct
40 Correct 2 ms 8792 KB Output is correct
41 Correct 2 ms 8804 KB Output is correct
42 Correct 2 ms 8792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 380 ms 13776 KB Output is correct
2 Correct 594 ms 15696 KB Output is correct
3 Correct 552 ms 15748 KB Output is correct
4 Correct 554 ms 15744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 380 ms 13776 KB Output is correct
2 Correct 594 ms 15696 KB Output is correct
3 Correct 552 ms 15748 KB Output is correct
4 Correct 554 ms 15744 KB Output is correct
5 Correct 466 ms 13768 KB Output is correct
6 Correct 640 ms 15756 KB Output is correct
7 Correct 596 ms 15752 KB Output is correct
8 Correct 581 ms 15756 KB Output is correct
9 Correct 255 ms 9048 KB Output is correct
10 Correct 659 ms 9048 KB Output is correct
11 Correct 572 ms 9048 KB Output is correct
12 Correct 542 ms 9048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 2 ms 8792 KB Output is correct
3 Correct 2 ms 8792 KB Output is correct
4 Correct 2 ms 8792 KB Output is correct
5 Correct 2 ms 8792 KB Output is correct
6 Correct 2 ms 8792 KB Output is correct
7 Correct 2 ms 8792 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 8792 KB Output is correct
10 Correct 2 ms 8792 KB Output is correct
11 Correct 2 ms 8792 KB Output is correct
12 Correct 2 ms 8792 KB Output is correct
13 Correct 380 ms 13776 KB Output is correct
14 Correct 594 ms 15696 KB Output is correct
15 Correct 552 ms 15748 KB Output is correct
16 Correct 554 ms 15744 KB Output is correct
17 Correct 466 ms 13768 KB Output is correct
18 Correct 640 ms 15756 KB Output is correct
19 Correct 596 ms 15752 KB Output is correct
20 Correct 581 ms 15756 KB Output is correct
21 Correct 255 ms 9048 KB Output is correct
22 Correct 659 ms 9048 KB Output is correct
23 Correct 572 ms 9048 KB Output is correct
24 Correct 542 ms 9048 KB Output is correct
25 Correct 628 ms 21760 KB Output is correct
26 Correct 639 ms 21764 KB Output is correct
27 Correct 627 ms 21756 KB Output is correct
28 Correct 487 ms 21780 KB Output is correct
29 Correct 657 ms 26388 KB Output is correct
30 Correct 605 ms 26380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 3 ms 8792 KB Output is correct
3 Correct 2 ms 8868 KB Output is correct
4 Correct 2 ms 8792 KB Output is correct
5 Correct 2 ms 8792 KB Output is correct
6 Correct 2 ms 8792 KB Output is correct
7 Correct 2 ms 8800 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 8792 KB Output is correct
10 Correct 2 ms 8792 KB Output is correct
11 Correct 2 ms 8792 KB Output is correct
12 Correct 2 ms 8792 KB Output is correct
13 Correct 2 ms 8792 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 2 ms 8792 KB Output is correct
16 Correct 2 ms 8792 KB Output is correct
17 Correct 2 ms 8792 KB Output is correct
18 Correct 2 ms 8792 KB Output is correct
19 Correct 2 ms 8792 KB Output is correct
20 Correct 2 ms 8792 KB Output is correct
21 Correct 2 ms 8792 KB Output is correct
22 Correct 2 ms 8792 KB Output is correct
23 Correct 2 ms 8792 KB Output is correct
24 Correct 2 ms 8792 KB Output is correct
25 Correct 2 ms 8792 KB Output is correct
26 Correct 2 ms 8792 KB Output is correct
27 Correct 3 ms 8792 KB Output is correct
28 Correct 2 ms 8792 KB Output is correct
29 Correct 2 ms 8792 KB Output is correct
30 Correct 2 ms 8792 KB Output is correct
31 Correct 2 ms 8792 KB Output is correct
32 Correct 3 ms 8792 KB Output is correct
33 Correct 2 ms 8792 KB Output is correct
34 Correct 2 ms 8792 KB Output is correct
35 Correct 2 ms 8792 KB Output is correct
36 Correct 3 ms 8792 KB Output is correct
37 Correct 2 ms 8792 KB Output is correct
38 Correct 2 ms 8792 KB Output is correct
39 Correct 2 ms 8792 KB Output is correct
40 Correct 2 ms 8792 KB Output is correct
41 Correct 2 ms 8804 KB Output is correct
42 Correct 2 ms 8792 KB Output is correct
43 Correct 364 ms 9048 KB Output is correct
44 Correct 561 ms 9048 KB Output is correct
45 Correct 570 ms 9300 KB Output is correct
46 Correct 534 ms 9304 KB Output is correct
47 Correct 552 ms 9304 KB Output is correct
48 Correct 613 ms 9304 KB Output is correct
49 Correct 538 ms 9304 KB Output is correct
50 Correct 526 ms 9304 KB Output is correct
51 Correct 561 ms 9304 KB Output is correct
52 Correct 596 ms 9304 KB Output is correct
53 Correct 545 ms 9048 KB Output is correct
54 Correct 571 ms 9304 KB Output is correct
55 Correct 566 ms 9304 KB Output is correct
56 Correct 606 ms 9304 KB Output is correct
57 Correct 545 ms 9304 KB Output is correct
58 Correct 613 ms 9560 KB Output is correct
59 Correct 549 ms 9780 KB Output is correct
60 Correct 574 ms 9784 KB Output is correct
61 Correct 549 ms 9048 KB Output is correct
62 Correct 570 ms 9048 KB Output is correct
63 Correct 524 ms 9048 KB Output is correct
64 Correct 533 ms 9304 KB Output is correct
65 Correct 287 ms 9048 KB Output is correct
66 Correct 525 ms 9048 KB Output is correct
67 Correct 519 ms 9048 KB Output is correct
68 Correct 565 ms 9048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8792 KB Output is correct
2 Correct 3 ms 8792 KB Output is correct
3 Correct 2 ms 8868 KB Output is correct
4 Correct 2 ms 8792 KB Output is correct
5 Correct 2 ms 8792 KB Output is correct
6 Correct 2 ms 8792 KB Output is correct
7 Correct 2 ms 8800 KB Output is correct
8 Correct 2 ms 8792 KB Output is correct
9 Correct 2 ms 8792 KB Output is correct
10 Correct 2 ms 8792 KB Output is correct
11 Correct 2 ms 8792 KB Output is correct
12 Correct 2 ms 8792 KB Output is correct
13 Correct 2 ms 8792 KB Output is correct
14 Correct 2 ms 8792 KB Output is correct
15 Correct 2 ms 8792 KB Output is correct
16 Correct 2 ms 8792 KB Output is correct
17 Correct 2 ms 8792 KB Output is correct
18 Correct 2 ms 8792 KB Output is correct
19 Correct 2 ms 8792 KB Output is correct
20 Correct 2 ms 8792 KB Output is correct
21 Correct 2 ms 8792 KB Output is correct
22 Correct 2 ms 8792 KB Output is correct
23 Correct 2 ms 8792 KB Output is correct
24 Correct 2 ms 8792 KB Output is correct
25 Correct 2 ms 8792 KB Output is correct
26 Correct 2 ms 8792 KB Output is correct
27 Correct 3 ms 8792 KB Output is correct
28 Correct 2 ms 8792 KB Output is correct
29 Correct 2 ms 8792 KB Output is correct
30 Correct 2 ms 8792 KB Output is correct
31 Correct 2 ms 8792 KB Output is correct
32 Correct 3 ms 8792 KB Output is correct
33 Correct 2 ms 8792 KB Output is correct
34 Correct 2 ms 8792 KB Output is correct
35 Correct 2 ms 8792 KB Output is correct
36 Correct 3 ms 8792 KB Output is correct
37 Correct 2 ms 8792 KB Output is correct
38 Correct 2 ms 8792 KB Output is correct
39 Correct 2 ms 8792 KB Output is correct
40 Correct 2 ms 8792 KB Output is correct
41 Correct 2 ms 8804 KB Output is correct
42 Correct 2 ms 8792 KB Output is correct
43 Correct 380 ms 13776 KB Output is correct
44 Correct 594 ms 15696 KB Output is correct
45 Correct 552 ms 15748 KB Output is correct
46 Correct 554 ms 15744 KB Output is correct
47 Correct 466 ms 13768 KB Output is correct
48 Correct 640 ms 15756 KB Output is correct
49 Correct 596 ms 15752 KB Output is correct
50 Correct 581 ms 15756 KB Output is correct
51 Correct 255 ms 9048 KB Output is correct
52 Correct 659 ms 9048 KB Output is correct
53 Correct 572 ms 9048 KB Output is correct
54 Correct 542 ms 9048 KB Output is correct
55 Correct 628 ms 21760 KB Output is correct
56 Correct 639 ms 21764 KB Output is correct
57 Correct 627 ms 21756 KB Output is correct
58 Correct 487 ms 21780 KB Output is correct
59 Correct 657 ms 26388 KB Output is correct
60 Correct 605 ms 26380 KB Output is correct
61 Correct 364 ms 9048 KB Output is correct
62 Correct 561 ms 9048 KB Output is correct
63 Correct 570 ms 9300 KB Output is correct
64 Correct 534 ms 9304 KB Output is correct
65 Correct 552 ms 9304 KB Output is correct
66 Correct 613 ms 9304 KB Output is correct
67 Correct 538 ms 9304 KB Output is correct
68 Correct 526 ms 9304 KB Output is correct
69 Correct 561 ms 9304 KB Output is correct
70 Correct 596 ms 9304 KB Output is correct
71 Correct 545 ms 9048 KB Output is correct
72 Correct 571 ms 9304 KB Output is correct
73 Correct 566 ms 9304 KB Output is correct
74 Correct 606 ms 9304 KB Output is correct
75 Correct 545 ms 9304 KB Output is correct
76 Correct 613 ms 9560 KB Output is correct
77 Correct 549 ms 9780 KB Output is correct
78 Correct 574 ms 9784 KB Output is correct
79 Correct 549 ms 9048 KB Output is correct
80 Correct 570 ms 9048 KB Output is correct
81 Correct 524 ms 9048 KB Output is correct
82 Correct 533 ms 9304 KB Output is correct
83 Correct 287 ms 9048 KB Output is correct
84 Correct 525 ms 9048 KB Output is correct
85 Correct 519 ms 9048 KB Output is correct
86 Correct 565 ms 9048 KB Output is correct
87 Correct 2 ms 8792 KB Output is correct
88 Correct 357 ms 21352 KB Output is correct
89 Correct 673 ms 15920 KB Output is correct
90 Correct 580 ms 15680 KB Output is correct
91 Correct 586 ms 21796 KB Output is correct
92 Correct 681 ms 21756 KB Output is correct
93 Correct 685 ms 21824 KB Output is correct
94 Correct 684 ms 21760 KB Output is correct
95 Correct 597 ms 21780 KB Output is correct
96 Correct 551 ms 18128 KB Output is correct
97 Correct 648 ms 17928 KB Output is correct
98 Correct 501 ms 17928 KB Output is correct
99 Correct 683 ms 21764 KB Output is correct
100 Correct 667 ms 19544 KB Output is correct
101 Correct 651 ms 19180 KB Output is correct
102 Correct 603 ms 18008 KB Output is correct
103 Correct 632 ms 26404 KB Output is correct
104 Correct 648 ms 27016 KB Output is correct
105 Correct 596 ms 27036 KB Output is correct
106 Correct 629 ms 16728 KB Output is correct
107 Correct 572 ms 18728 KB Output is correct
108 Correct 608 ms 18524 KB Output is correct
109 Correct 604 ms 18260 KB Output is correct