Submission #799426

# Submission time Handle Problem Language Result Execution time Memory
799426 2023-07-31T14:10:18 Z JakobZorz Digital Circuit (IOI22_circuit) C++17
89 / 100
3000 ms 23940 KB
#include"circuit.h"
#include<vector>
#include<iostream>
using namespace std;
typedef long long ll;

const int MOD=1000002022;
const int TREE_SIZE=1<<18;

int parents[200000];
ll sub_mul[200000];
vector<int>children[200000];
int n,m;
ll vals[100000];

struct SegTree{
    vector<int>tree;
    vector<int>tree_val;
    vector<bool>lazy;
    
    void init_tree(int node,int l,int r){
        int m=(l+r)/2;
        if(m==l)
            return;
        
        init_tree(2*node,l,m);
        init_tree(2*node+1,m,r);
        tree[node]=tree[2*node]+tree[2*node+1];
        tree[node]%=MOD;
    }
    
    SegTree(ll*arr,int size){
        tree.resize(2*TREE_SIZE);
        tree_val.resize(2*TREE_SIZE);
        lazy.resize(2*TREE_SIZE);
        for(int i=0;i<size;i++)
            tree[TREE_SIZE+i]=arr[i];
        init_tree(1,0,TREE_SIZE);
    }
    
    int get(){
        return tree_val[1];
    }
    
    void push(int node,int l,int r){
        if(lazy[node]){
            lazy[node]=false;
            tree_val[node]=tree[node]+MOD-tree_val[node];
            tree_val[node]%=MOD;
            if(l<r-1){
                lazy[2*node]=!lazy[2*node];
                lazy[2*node+1]=!lazy[2*node+1];
            }
        }
    }
    
    void toggle(int node,int rl,int rr,int l,int r){
        push(node,l,r);
        
        if(rr<=l||r<=rl)
            return;
        
        if(rl<=l&&r<=rr){
            lazy[node]=true;
            push(node,l,r);
            return;
        }
        
        int m=(l+r)/2;
        toggle(2*node,rl,rr,l,m);
        toggle(2*node+1,rl,rr,m,r);
        
        tree_val[node]=tree_val[2*node]+tree_val[2*node+1];
        tree_val[node]%=MOD;
    }
};

SegTree*segtree;

void dfs2(int node){
    if(children[node].empty()){
        sub_mul[node]=1;
        return;
    }
    
    sub_mul[node]=children[node].size();
    for(int ch:children[node]){
        dfs2(ch);
        sub_mul[node]*=sub_mul[ch];
        sub_mul[node]%=MOD;
    }
}

void dfs3(int node,ll val){
    if(children[node].empty()){
        vals[node-n]=val;
        return;
    }
    
    for(int ch:children[node]){
        ll val2=val;
        for(int ch2:children[node]){
            if(ch2!=ch){
                val2*=sub_mul[ch2];
                val2%=MOD;
            }
        }
        dfs3(ch,val2);
    }
}

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    n=N;
    m=M;
    for(int i=0;i<n+m;i++){
        parents[i]=P[i];
        if(parents[i]!=-1)
            children[parents[i]].push_back(i);
    }
    
    dfs2(0);
    dfs3(0,1);
    
    segtree=new SegTree(vals,m);
    
    for(int i=0;i<(int)A.size();i++)
        if(A[i]==1)
            segtree->toggle(1,i,i+1,0,TREE_SIZE);
}

int count_ways(int L, int R) {
    L-=n;
    R-=n;
    segtree->toggle(1,L,R+1,0,TREE_SIZE);
    
    /*for(int i=0;i<m;i++)
        cout<<active[i]<<" ";
    cout<<"\n";
    for(int i=0;i<m;i++)
        cout<<vals[i]<<" ";
    cout<<"\n";*/
    
    
    return segtree->get();
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9168 KB Output is correct
2 Correct 6 ms 9196 KB Output is correct
3 Correct 9 ms 9168 KB Output is correct
4 Correct 9 ms 9168 KB Output is correct
5 Correct 10 ms 9168 KB Output is correct
6 Correct 9 ms 9168 KB Output is correct
7 Correct 9 ms 9168 KB Output is correct
8 Correct 9 ms 9148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9168 KB Output is correct
2 Correct 7 ms 9296 KB Output is correct
3 Correct 6 ms 9168 KB Output is correct
4 Correct 5 ms 9168 KB Output is correct
5 Correct 5 ms 9168 KB Output is correct
6 Correct 6 ms 9168 KB Output is correct
7 Correct 5 ms 9168 KB Output is correct
8 Correct 5 ms 9284 KB Output is correct
9 Correct 5 ms 9168 KB Output is correct
10 Correct 5 ms 9296 KB Output is correct
11 Correct 5 ms 9296 KB Output is correct
12 Correct 6 ms 9164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9168 KB Output is correct
2 Correct 6 ms 9196 KB Output is correct
3 Correct 9 ms 9168 KB Output is correct
4 Correct 9 ms 9168 KB Output is correct
5 Correct 10 ms 9168 KB Output is correct
6 Correct 9 ms 9168 KB Output is correct
7 Correct 9 ms 9168 KB Output is correct
8 Correct 9 ms 9148 KB Output is correct
9 Correct 5 ms 9168 KB Output is correct
10 Correct 7 ms 9296 KB Output is correct
11 Correct 6 ms 9168 KB Output is correct
12 Correct 5 ms 9168 KB Output is correct
13 Correct 5 ms 9168 KB Output is correct
14 Correct 6 ms 9168 KB Output is correct
15 Correct 5 ms 9168 KB Output is correct
16 Correct 5 ms 9284 KB Output is correct
17 Correct 5 ms 9168 KB Output is correct
18 Correct 5 ms 9296 KB Output is correct
19 Correct 5 ms 9296 KB Output is correct
20 Correct 6 ms 9164 KB Output is correct
21 Correct 5 ms 9168 KB Output is correct
22 Correct 5 ms 9216 KB Output is correct
23 Correct 5 ms 9168 KB Output is correct
24 Correct 5 ms 9168 KB Output is correct
25 Correct 5 ms 9168 KB Output is correct
26 Correct 7 ms 9288 KB Output is correct
27 Correct 6 ms 9168 KB Output is correct
28 Correct 5 ms 9168 KB Output is correct
29 Correct 9 ms 9240 KB Output is correct
30 Correct 10 ms 9168 KB Output is correct
31 Correct 5 ms 9296 KB Output is correct
32 Correct 5 ms 9168 KB Output is correct
33 Correct 6 ms 9168 KB Output is correct
34 Correct 6 ms 9132 KB Output is correct
35 Correct 6 ms 9168 KB Output is correct
36 Correct 5 ms 9296 KB Output is correct
37 Correct 9 ms 9232 KB Output is correct
38 Correct 10 ms 9296 KB Output is correct
39 Correct 5 ms 9168 KB Output is correct
40 Correct 5 ms 9168 KB Output is correct
41 Correct 5 ms 9168 KB Output is correct
42 Correct 5 ms 9168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 508 ms 11936 KB Output is correct
2 Correct 654 ms 14792 KB Output is correct
3 Correct 723 ms 14740 KB Output is correct
4 Correct 646 ms 14792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 508 ms 11936 KB Output is correct
2 Correct 654 ms 14792 KB Output is correct
3 Correct 723 ms 14740 KB Output is correct
4 Correct 646 ms 14792 KB Output is correct
5 Correct 672 ms 12024 KB Output is correct
6 Correct 613 ms 14724 KB Output is correct
7 Correct 776 ms 14732 KB Output is correct
8 Correct 715 ms 14772 KB Output is correct
9 Correct 402 ms 9304 KB Output is correct
10 Correct 693 ms 9552 KB Output is correct
11 Correct 846 ms 9424 KB Output is correct
12 Correct 765 ms 9424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9168 KB Output is correct
2 Correct 7 ms 9296 KB Output is correct
3 Correct 6 ms 9168 KB Output is correct
4 Correct 5 ms 9168 KB Output is correct
5 Correct 5 ms 9168 KB Output is correct
6 Correct 6 ms 9168 KB Output is correct
7 Correct 5 ms 9168 KB Output is correct
8 Correct 5 ms 9284 KB Output is correct
9 Correct 5 ms 9168 KB Output is correct
10 Correct 5 ms 9296 KB Output is correct
11 Correct 5 ms 9296 KB Output is correct
12 Correct 6 ms 9164 KB Output is correct
13 Correct 508 ms 11936 KB Output is correct
14 Correct 654 ms 14792 KB Output is correct
15 Correct 723 ms 14740 KB Output is correct
16 Correct 646 ms 14792 KB Output is correct
17 Correct 672 ms 12024 KB Output is correct
18 Correct 613 ms 14724 KB Output is correct
19 Correct 776 ms 14732 KB Output is correct
20 Correct 715 ms 14772 KB Output is correct
21 Correct 402 ms 9304 KB Output is correct
22 Correct 693 ms 9552 KB Output is correct
23 Correct 846 ms 9424 KB Output is correct
24 Correct 765 ms 9424 KB Output is correct
25 Correct 804 ms 17544 KB Output is correct
26 Correct 790 ms 17736 KB Output is correct
27 Correct 778 ms 17780 KB Output is correct
28 Correct 751 ms 17688 KB Output is correct
29 Correct 848 ms 23940 KB Output is correct
30 Correct 622 ms 23940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9168 KB Output is correct
2 Correct 6 ms 9196 KB Output is correct
3 Correct 9 ms 9168 KB Output is correct
4 Correct 9 ms 9168 KB Output is correct
5 Correct 10 ms 9168 KB Output is correct
6 Correct 9 ms 9168 KB Output is correct
7 Correct 9 ms 9168 KB Output is correct
8 Correct 9 ms 9148 KB Output is correct
9 Correct 5 ms 9168 KB Output is correct
10 Correct 7 ms 9296 KB Output is correct
11 Correct 6 ms 9168 KB Output is correct
12 Correct 5 ms 9168 KB Output is correct
13 Correct 5 ms 9168 KB Output is correct
14 Correct 6 ms 9168 KB Output is correct
15 Correct 5 ms 9168 KB Output is correct
16 Correct 5 ms 9284 KB Output is correct
17 Correct 5 ms 9168 KB Output is correct
18 Correct 5 ms 9296 KB Output is correct
19 Correct 5 ms 9296 KB Output is correct
20 Correct 6 ms 9164 KB Output is correct
21 Correct 5 ms 9168 KB Output is correct
22 Correct 5 ms 9216 KB Output is correct
23 Correct 5 ms 9168 KB Output is correct
24 Correct 5 ms 9168 KB Output is correct
25 Correct 5 ms 9168 KB Output is correct
26 Correct 7 ms 9288 KB Output is correct
27 Correct 6 ms 9168 KB Output is correct
28 Correct 5 ms 9168 KB Output is correct
29 Correct 9 ms 9240 KB Output is correct
30 Correct 10 ms 9168 KB Output is correct
31 Correct 5 ms 9296 KB Output is correct
32 Correct 5 ms 9168 KB Output is correct
33 Correct 6 ms 9168 KB Output is correct
34 Correct 6 ms 9132 KB Output is correct
35 Correct 6 ms 9168 KB Output is correct
36 Correct 5 ms 9296 KB Output is correct
37 Correct 9 ms 9232 KB Output is correct
38 Correct 10 ms 9296 KB Output is correct
39 Correct 5 ms 9168 KB Output is correct
40 Correct 5 ms 9168 KB Output is correct
41 Correct 5 ms 9168 KB Output is correct
42 Correct 5 ms 9168 KB Output is correct
43 Correct 405 ms 9424 KB Output is correct
44 Correct 676 ms 9424 KB Output is correct
45 Correct 752 ms 9424 KB Output is correct
46 Correct 783 ms 9552 KB Output is correct
47 Correct 765 ms 9552 KB Output is correct
48 Correct 743 ms 9552 KB Output is correct
49 Correct 729 ms 9552 KB Output is correct
50 Correct 727 ms 9620 KB Output is correct
51 Correct 864 ms 9288 KB Output is correct
52 Correct 803 ms 9284 KB Output is correct
53 Correct 687 ms 9760 KB Output is correct
54 Correct 856 ms 9608 KB Output is correct
55 Correct 747 ms 9424 KB Output is correct
56 Correct 632 ms 9424 KB Output is correct
57 Correct 767 ms 9296 KB Output is correct
58 Correct 564 ms 9808 KB Output is correct
59 Correct 938 ms 9848 KB Output is correct
60 Correct 895 ms 9928 KB Output is correct
61 Correct 851 ms 9424 KB Output is correct
62 Correct 676 ms 9424 KB Output is correct
63 Correct 668 ms 9296 KB Output is correct
64 Correct 788 ms 9296 KB Output is correct
65 Correct 369 ms 9296 KB Output is correct
66 Correct 727 ms 9480 KB Output is correct
67 Correct 669 ms 9424 KB Output is correct
68 Correct 712 ms 9488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 9168 KB Output is correct
2 Correct 6 ms 9196 KB Output is correct
3 Correct 9 ms 9168 KB Output is correct
4 Correct 9 ms 9168 KB Output is correct
5 Correct 10 ms 9168 KB Output is correct
6 Correct 9 ms 9168 KB Output is correct
7 Correct 9 ms 9168 KB Output is correct
8 Correct 9 ms 9148 KB Output is correct
9 Correct 5 ms 9168 KB Output is correct
10 Correct 7 ms 9296 KB Output is correct
11 Correct 6 ms 9168 KB Output is correct
12 Correct 5 ms 9168 KB Output is correct
13 Correct 5 ms 9168 KB Output is correct
14 Correct 6 ms 9168 KB Output is correct
15 Correct 5 ms 9168 KB Output is correct
16 Correct 5 ms 9284 KB Output is correct
17 Correct 5 ms 9168 KB Output is correct
18 Correct 5 ms 9296 KB Output is correct
19 Correct 5 ms 9296 KB Output is correct
20 Correct 6 ms 9164 KB Output is correct
21 Correct 5 ms 9168 KB Output is correct
22 Correct 5 ms 9216 KB Output is correct
23 Correct 5 ms 9168 KB Output is correct
24 Correct 5 ms 9168 KB Output is correct
25 Correct 5 ms 9168 KB Output is correct
26 Correct 7 ms 9288 KB Output is correct
27 Correct 6 ms 9168 KB Output is correct
28 Correct 5 ms 9168 KB Output is correct
29 Correct 9 ms 9240 KB Output is correct
30 Correct 10 ms 9168 KB Output is correct
31 Correct 5 ms 9296 KB Output is correct
32 Correct 5 ms 9168 KB Output is correct
33 Correct 6 ms 9168 KB Output is correct
34 Correct 6 ms 9132 KB Output is correct
35 Correct 6 ms 9168 KB Output is correct
36 Correct 5 ms 9296 KB Output is correct
37 Correct 9 ms 9232 KB Output is correct
38 Correct 10 ms 9296 KB Output is correct
39 Correct 5 ms 9168 KB Output is correct
40 Correct 5 ms 9168 KB Output is correct
41 Correct 5 ms 9168 KB Output is correct
42 Correct 5 ms 9168 KB Output is correct
43 Correct 508 ms 11936 KB Output is correct
44 Correct 654 ms 14792 KB Output is correct
45 Correct 723 ms 14740 KB Output is correct
46 Correct 646 ms 14792 KB Output is correct
47 Correct 672 ms 12024 KB Output is correct
48 Correct 613 ms 14724 KB Output is correct
49 Correct 776 ms 14732 KB Output is correct
50 Correct 715 ms 14772 KB Output is correct
51 Correct 402 ms 9304 KB Output is correct
52 Correct 693 ms 9552 KB Output is correct
53 Correct 846 ms 9424 KB Output is correct
54 Correct 765 ms 9424 KB Output is correct
55 Correct 804 ms 17544 KB Output is correct
56 Correct 790 ms 17736 KB Output is correct
57 Correct 778 ms 17780 KB Output is correct
58 Correct 751 ms 17688 KB Output is correct
59 Correct 848 ms 23940 KB Output is correct
60 Correct 622 ms 23940 KB Output is correct
61 Correct 405 ms 9424 KB Output is correct
62 Correct 676 ms 9424 KB Output is correct
63 Correct 752 ms 9424 KB Output is correct
64 Correct 783 ms 9552 KB Output is correct
65 Correct 765 ms 9552 KB Output is correct
66 Correct 743 ms 9552 KB Output is correct
67 Correct 729 ms 9552 KB Output is correct
68 Correct 727 ms 9620 KB Output is correct
69 Correct 864 ms 9288 KB Output is correct
70 Correct 803 ms 9284 KB Output is correct
71 Correct 687 ms 9760 KB Output is correct
72 Correct 856 ms 9608 KB Output is correct
73 Correct 747 ms 9424 KB Output is correct
74 Correct 632 ms 9424 KB Output is correct
75 Correct 767 ms 9296 KB Output is correct
76 Correct 564 ms 9808 KB Output is correct
77 Correct 938 ms 9848 KB Output is correct
78 Correct 895 ms 9928 KB Output is correct
79 Correct 851 ms 9424 KB Output is correct
80 Correct 676 ms 9424 KB Output is correct
81 Correct 668 ms 9296 KB Output is correct
82 Correct 788 ms 9296 KB Output is correct
83 Correct 369 ms 9296 KB Output is correct
84 Correct 727 ms 9480 KB Output is correct
85 Correct 669 ms 9424 KB Output is correct
86 Correct 712 ms 9488 KB Output is correct
87 Correct 5 ms 9168 KB Output is correct
88 Correct 604 ms 16896 KB Output is correct
89 Correct 678 ms 14916 KB Output is correct
90 Correct 945 ms 14636 KB Output is correct
91 Correct 751 ms 17780 KB Output is correct
92 Correct 887 ms 17784 KB Output is correct
93 Correct 864 ms 17784 KB Output is correct
94 Correct 943 ms 17784 KB Output is correct
95 Correct 882 ms 17828 KB Output is correct
96 Execution timed out 3016 ms 8432 KB Time limit exceeded
97 Halted 0 ms 0 KB -