Submission #1029333

# Submission time Handle Problem Language Result Execution time Memory
1029333 2024-07-20T16:57:29 Z vjudge1 Digital Circuit (IOI22_circuit) C++17
100 / 100
766 ms 36028 KB
#include "circuit.h"
#include <bits/stdc++.h>

#define ll long long
#define sz(s) (int)s.size()
#define pb push_back

using namespace std;

const int MAX=2e5+10;
const int mod=1000002022;

int n,m;
vector<int> a;
vector<int> g[MAX];
int c[MAX];

struct segtree{
    int t[4*MAX],s[4*MAX],add[4*MAX];

    void build(int v,int tl,int tr){
        add[v]=0;
        if(tl==tr){
            t[v]=a[tl]*c[tl];
            s[v]=c[tl];
            return;
        }
        int tm=(tl+tr)/2;
        build(2*v,tl,tm);
        build(2*v+1,tm+1,tr);
        t[v]=(t[2*v]+t[2*v+1])%mod;
        s[v]=(s[2*v]+s[2*v+1])%mod;
    }

    void upd(int v){
        add[v]^=1;
        t[v]=(s[v]-t[v]+mod)%mod;
    }

    void push(int v){
        if(add[v]){
            upd(2*v);
            upd(2*v+1);
            add[v]=0;
        }
    }

    void update(int v,int tl,int tr,int l,int r){
        if(l>r||tl>r||l>tr)return;
        if(l<=tl&&tr<=r){
            upd(v);
            return;
        }
        int tm=(tl+tr)/2;
        push(v);
        update(2*v,tl,tm,l,r);
        update(2*v+1,tm+1,tr,l,r);
        t[v]=(t[2*v]+t[2*v+1])%mod;
        s[v]=(s[2*v]+s[2*v+1])%mod;
    }
}T;

int pr[MAX];

void calc(int v){
    pr[v]=sz(g[v]);
    if(g[v].empty())pr[v]=1;
    for(auto to:g[v]){
        calc(to);
        pr[v]=pr[v]*1ll*pr[to]%mod;
    }
}


void dfs(int v,int s){
    if(g[v].empty()){
        c[v-n]=s;
        return;
    }
    vector<int> pref(sz(g[v]),0),suf(sz(g[v]),0);
    pref[0]=pr[g[v][0]];
    for(int i=1;i<sz(g[v]);i++){
        pref[i]=pref[i-1]*1ll*pr[g[v][i]]%mod;
    }
    suf[sz(g[v])-1]=pr[g[v][sz(g[v])-1]];
    for(int i=sz(g[v])-2;i>=0;i--){
        suf[i]=suf[i+1]*1ll*pr[g[v][i]]%mod;
    }
    for(int i=0;i<sz(g[v]);i++){
        int to=g[v][i];
        int f=s*1ll*(i-1>=0?pref[i-1]:1)%mod*(i+1<sz(g[v])?suf[i+1]:1)%mod;
        dfs(to,f);
    }
}

void init(int N, int M,vector<int> P,vector<int> A) {
    n=N;
    m=M;
    a=A;
    for(int i=1;i<N+M;i++){
        g[P[i]].pb(i);
    }
    calc(0);
    dfs(0,1);
    T.build(1,0,M-1);
}

int count_ways(int L, int R){
    L-=n;
    R-=n;
    // cout<<L<<" "<<R<<"\n";
    T.update(1,0,m-1,L,R);
    return T.t[1];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 5028 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 5180 KB Output is correct
4 Correct 2 ms 5208 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
9 Correct 3 ms 5208 KB Output is correct
10 Correct 2 ms 5208 KB Output is correct
11 Correct 2 ms 5208 KB Output is correct
12 Correct 4 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 5028 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 2 ms 5180 KB Output is correct
12 Correct 2 ms 5208 KB Output is correct
13 Correct 3 ms 5208 KB Output is correct
14 Correct 2 ms 5208 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 2 ms 5208 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 2 ms 5208 KB Output is correct
19 Correct 2 ms 5208 KB Output is correct
20 Correct 4 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 2 ms 5208 KB Output is correct
23 Correct 3 ms 5208 KB Output is correct
24 Correct 2 ms 5208 KB Output is correct
25 Correct 2 ms 5208 KB Output is correct
26 Correct 3 ms 5220 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 2 ms 5208 KB Output is correct
29 Correct 2 ms 5208 KB Output is correct
30 Correct 2 ms 5208 KB Output is correct
31 Correct 2 ms 5240 KB Output is correct
32 Correct 3 ms 5208 KB Output is correct
33 Correct 2 ms 5236 KB Output is correct
34 Correct 3 ms 5208 KB Output is correct
35 Correct 2 ms 5208 KB Output is correct
36 Correct 4 ms 5464 KB Output is correct
37 Correct 2 ms 5464 KB Output is correct
38 Correct 3 ms 5464 KB Output is correct
39 Correct 3 ms 5040 KB Output is correct
40 Correct 2 ms 5208 KB Output is correct
41 Correct 2 ms 5208 KB Output is correct
42 Correct 2 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 430 ms 8024 KB Output is correct
2 Correct 657 ms 11352 KB Output is correct
3 Correct 668 ms 11352 KB Output is correct
4 Correct 708 ms 11084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 430 ms 8024 KB Output is correct
2 Correct 657 ms 11352 KB Output is correct
3 Correct 668 ms 11352 KB Output is correct
4 Correct 708 ms 11084 KB Output is correct
5 Correct 507 ms 8024 KB Output is correct
6 Correct 625 ms 11308 KB Output is correct
7 Correct 723 ms 11096 KB Output is correct
8 Correct 636 ms 11352 KB Output is correct
9 Correct 280 ms 5208 KB Output is correct
10 Correct 583 ms 5464 KB Output is correct
11 Correct 662 ms 5464 KB Output is correct
12 Correct 625 ms 5464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 5180 KB Output is correct
4 Correct 2 ms 5208 KB Output is correct
5 Correct 3 ms 5208 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 3 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
9 Correct 3 ms 5208 KB Output is correct
10 Correct 2 ms 5208 KB Output is correct
11 Correct 2 ms 5208 KB Output is correct
12 Correct 4 ms 5208 KB Output is correct
13 Correct 430 ms 8024 KB Output is correct
14 Correct 657 ms 11352 KB Output is correct
15 Correct 668 ms 11352 KB Output is correct
16 Correct 708 ms 11084 KB Output is correct
17 Correct 507 ms 8024 KB Output is correct
18 Correct 625 ms 11308 KB Output is correct
19 Correct 723 ms 11096 KB Output is correct
20 Correct 636 ms 11352 KB Output is correct
21 Correct 280 ms 5208 KB Output is correct
22 Correct 583 ms 5464 KB Output is correct
23 Correct 662 ms 5464 KB Output is correct
24 Correct 625 ms 5464 KB Output is correct
25 Correct 703 ms 14924 KB Output is correct
26 Correct 766 ms 15432 KB Output is correct
27 Correct 724 ms 15184 KB Output is correct
28 Correct 605 ms 15184 KB Output is correct
29 Correct 707 ms 35408 KB Output is correct
30 Correct 683 ms 35524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 5028 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 2 ms 5180 KB Output is correct
12 Correct 2 ms 5208 KB Output is correct
13 Correct 3 ms 5208 KB Output is correct
14 Correct 2 ms 5208 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 2 ms 5208 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 2 ms 5208 KB Output is correct
19 Correct 2 ms 5208 KB Output is correct
20 Correct 4 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 2 ms 5208 KB Output is correct
23 Correct 3 ms 5208 KB Output is correct
24 Correct 2 ms 5208 KB Output is correct
25 Correct 2 ms 5208 KB Output is correct
26 Correct 3 ms 5220 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 2 ms 5208 KB Output is correct
29 Correct 2 ms 5208 KB Output is correct
30 Correct 2 ms 5208 KB Output is correct
31 Correct 2 ms 5240 KB Output is correct
32 Correct 3 ms 5208 KB Output is correct
33 Correct 2 ms 5236 KB Output is correct
34 Correct 3 ms 5208 KB Output is correct
35 Correct 2 ms 5208 KB Output is correct
36 Correct 4 ms 5464 KB Output is correct
37 Correct 2 ms 5464 KB Output is correct
38 Correct 3 ms 5464 KB Output is correct
39 Correct 3 ms 5040 KB Output is correct
40 Correct 2 ms 5208 KB Output is correct
41 Correct 2 ms 5208 KB Output is correct
42 Correct 2 ms 5208 KB Output is correct
43 Correct 456 ms 5464 KB Output is correct
44 Correct 612 ms 5464 KB Output is correct
45 Correct 553 ms 5464 KB Output is correct
46 Correct 526 ms 5464 KB Output is correct
47 Correct 586 ms 5464 KB Output is correct
48 Correct 645 ms 5720 KB Output is correct
49 Correct 674 ms 5720 KB Output is correct
50 Correct 626 ms 5720 KB Output is correct
51 Correct 610 ms 5464 KB Output is correct
52 Correct 628 ms 5464 KB Output is correct
53 Correct 560 ms 6232 KB Output is correct
54 Correct 633 ms 5464 KB Output is correct
55 Correct 651 ms 5464 KB Output is correct
56 Correct 578 ms 5464 KB Output is correct
57 Correct 601 ms 5464 KB Output is correct
58 Correct 622 ms 6488 KB Output is correct
59 Correct 596 ms 6744 KB Output is correct
60 Correct 623 ms 6744 KB Output is correct
61 Correct 615 ms 5720 KB Output is correct
62 Correct 651 ms 5208 KB Output is correct
63 Correct 645 ms 5208 KB Output is correct
64 Correct 663 ms 5464 KB Output is correct
65 Correct 316 ms 5208 KB Output is correct
66 Correct 632 ms 5464 KB Output is correct
67 Correct 610 ms 5464 KB Output is correct
68 Correct 575 ms 5464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 2 ms 5208 KB Output is correct
4 Correct 2 ms 5028 KB Output is correct
5 Correct 2 ms 5208 KB Output is correct
6 Correct 2 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 2 ms 5208 KB Output is correct
9 Correct 2 ms 4952 KB Output is correct
10 Correct 2 ms 4952 KB Output is correct
11 Correct 2 ms 5180 KB Output is correct
12 Correct 2 ms 5208 KB Output is correct
13 Correct 3 ms 5208 KB Output is correct
14 Correct 2 ms 5208 KB Output is correct
15 Correct 3 ms 5208 KB Output is correct
16 Correct 2 ms 5208 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 2 ms 5208 KB Output is correct
19 Correct 2 ms 5208 KB Output is correct
20 Correct 4 ms 5208 KB Output is correct
21 Correct 3 ms 5208 KB Output is correct
22 Correct 2 ms 5208 KB Output is correct
23 Correct 3 ms 5208 KB Output is correct
24 Correct 2 ms 5208 KB Output is correct
25 Correct 2 ms 5208 KB Output is correct
26 Correct 3 ms 5220 KB Output is correct
27 Correct 3 ms 5208 KB Output is correct
28 Correct 2 ms 5208 KB Output is correct
29 Correct 2 ms 5208 KB Output is correct
30 Correct 2 ms 5208 KB Output is correct
31 Correct 2 ms 5240 KB Output is correct
32 Correct 3 ms 5208 KB Output is correct
33 Correct 2 ms 5236 KB Output is correct
34 Correct 3 ms 5208 KB Output is correct
35 Correct 2 ms 5208 KB Output is correct
36 Correct 4 ms 5464 KB Output is correct
37 Correct 2 ms 5464 KB Output is correct
38 Correct 3 ms 5464 KB Output is correct
39 Correct 3 ms 5040 KB Output is correct
40 Correct 2 ms 5208 KB Output is correct
41 Correct 2 ms 5208 KB Output is correct
42 Correct 2 ms 5208 KB Output is correct
43 Correct 430 ms 8024 KB Output is correct
44 Correct 657 ms 11352 KB Output is correct
45 Correct 668 ms 11352 KB Output is correct
46 Correct 708 ms 11084 KB Output is correct
47 Correct 507 ms 8024 KB Output is correct
48 Correct 625 ms 11308 KB Output is correct
49 Correct 723 ms 11096 KB Output is correct
50 Correct 636 ms 11352 KB Output is correct
51 Correct 280 ms 5208 KB Output is correct
52 Correct 583 ms 5464 KB Output is correct
53 Correct 662 ms 5464 KB Output is correct
54 Correct 625 ms 5464 KB Output is correct
55 Correct 703 ms 14924 KB Output is correct
56 Correct 766 ms 15432 KB Output is correct
57 Correct 724 ms 15184 KB Output is correct
58 Correct 605 ms 15184 KB Output is correct
59 Correct 707 ms 35408 KB Output is correct
60 Correct 683 ms 35524 KB Output is correct
61 Correct 456 ms 5464 KB Output is correct
62 Correct 612 ms 5464 KB Output is correct
63 Correct 553 ms 5464 KB Output is correct
64 Correct 526 ms 5464 KB Output is correct
65 Correct 586 ms 5464 KB Output is correct
66 Correct 645 ms 5720 KB Output is correct
67 Correct 674 ms 5720 KB Output is correct
68 Correct 626 ms 5720 KB Output is correct
69 Correct 610 ms 5464 KB Output is correct
70 Correct 628 ms 5464 KB Output is correct
71 Correct 560 ms 6232 KB Output is correct
72 Correct 633 ms 5464 KB Output is correct
73 Correct 651 ms 5464 KB Output is correct
74 Correct 578 ms 5464 KB Output is correct
75 Correct 601 ms 5464 KB Output is correct
76 Correct 622 ms 6488 KB Output is correct
77 Correct 596 ms 6744 KB Output is correct
78 Correct 623 ms 6744 KB Output is correct
79 Correct 615 ms 5720 KB Output is correct
80 Correct 651 ms 5208 KB Output is correct
81 Correct 645 ms 5208 KB Output is correct
82 Correct 663 ms 5464 KB Output is correct
83 Correct 316 ms 5208 KB Output is correct
84 Correct 632 ms 5464 KB Output is correct
85 Correct 610 ms 5464 KB Output is correct
86 Correct 575 ms 5464 KB Output is correct
87 Correct 2 ms 4952 KB Output is correct
88 Correct 451 ms 14560 KB Output is correct
89 Correct 585 ms 11344 KB Output is correct
90 Correct 701 ms 10972 KB Output is correct
91 Correct 661 ms 15212 KB Output is correct
92 Correct 730 ms 15224 KB Output is correct
93 Correct 709 ms 15212 KB Output is correct
94 Correct 721 ms 15364 KB Output is correct
95 Correct 726 ms 15372 KB Output is correct
96 Correct 644 ms 11456 KB Output is correct
97 Correct 635 ms 11456 KB Output is correct
98 Correct 571 ms 29784 KB Output is correct
99 Correct 689 ms 15280 KB Output is correct
100 Correct 755 ms 12884 KB Output is correct
101 Correct 685 ms 12368 KB Output is correct
102 Correct 704 ms 11352 KB Output is correct
103 Correct 716 ms 35492 KB Output is correct
104 Correct 693 ms 35776 KB Output is correct
105 Correct 632 ms 36028 KB Output is correct
106 Correct 660 ms 15440 KB Output is correct
107 Correct 699 ms 11848 KB Output is correct
108 Correct 674 ms 11600 KB Output is correct
109 Correct 597 ms 11608 KB Output is correct