Submission #634515

# Submission time Handle Problem Language Result Execution time Memory
634515 2022-08-24T13:54:15 Z mosiashvililuka Digital Circuit (IOI22_circuit) C++17
100 / 100
1373 ms 29288 KB
#include<bits/stdc++.h>
#include "circuit.h"
using namespace std;
long long a,b,c,d,e,i,j,ii,jj,zx,xc,msh[200009],f[200009],K[800009],mod=1000002022LL,pas,DP[200009],DP2[200009],DP3[200009],jm[800009],seg[800009],seg2[800009],l,r,z,za;
vector <long long> v[200009];
void dfs(long long q, long long w){
    if(v[q].size()==0){
        DP[q]=1;
        return;
    }
    DP[q]=v[q].size();
    for(vector <long long>::iterator it=v[q].begin(); it!=v[q].end(); it++){
        dfs((*it),q);
        DP[q]*=DP[(*it)];DP[q]%=mod;
    }
    zx=1;
    for(vector <long long>::iterator it=v[q].begin(); it!=v[q].end(); it++){
        DP2[(*it)]=zx;
        zx*=DP[(*it)];zx%=mod;
    }
    vector <long long>::iterator it=v[q].end();it--;
    zx=1;
    while(1){
        DP2[(*it)]*=zx;DP2[(*it)]%=mod;
        zx*=DP[(*it)];zx%=mod;
        if(it==v[q].begin()) break;
        it--;
    }
}
void dfs2(int q, int w){
    DP3[q]*=DP2[q];DP3[q]%=mod;
    for(vector <long long>::iterator it=v[q].begin(); it!=v[q].end(); it++){
        DP3[(*it)]=DP3[q];
        dfs2((*it),q);
    }
}
void bld(long long q, long long w, long long rr){
    if(q==w){
        if(f[q]==1){
            seg[rr]=K[q];
        }
        return;
    }
    bld(q,(q+w)/2,rr*2);
    bld((q+w)/2+1,w,rr*2+1);
    seg[rr]=seg[rr*2]+seg[rr*2+1];seg[rr]%=mod;
}
void init(int NN, int MM, std::vector<int> PP, std::vector<int> AA) {
    a=NN+MM;
    for(i=1; i<a; i++){
        msh[i+1]=PP[i]+1;
        v[msh[i+1]].push_back(i+1);
    }
    for(i=NN+1; i<=a; i++){
        f[i]=AA[i-NN-1];
    }
    DP2[1]=1;DP3[1]=1;
    dfs(1,0);
    dfs2(1,0);
    for(i=NN+1; i<=a; i++){
        K[i]=DP3[i];
    }
    za=1;
    while(za<a) za*=2;
    for(i=1; i<=za; i++){
        jm[i]=jm[i-1]+K[i];jm[i]%=mod;
    }
    bld(1,za,1);
}
void pushdown(long long q, long long w, long long rr){
    if(q!=w){
        seg2[rr*2]^=seg2[rr];
        seg2[rr*2+1]^=seg2[rr];
    }
    if(seg2[rr]!=0){
        seg[rr]=(jm[w]-jm[q-1]+mod)-seg[rr]+mod;
        seg[rr]%=mod;
    }
    seg2[rr]=0;
}
void upd(long long q, long long w, long long rr){
    pushdown(q,w,rr);
    if(q>r||w<l) return;
    if(q>=l&&w<=r){
        seg2[rr]=z;
        pushdown(q,w,rr);
        return;
    }
    upd(q,(q+w)/2,rr*2);
    upd((q+w)/2+1,w,rr*2+1);
    seg[rr]=seg[rr*2]+seg[rr*2+1];seg[rr]%=mod;
}
void read(long long q, long long w, long long rr){
    pushdown(q,w,rr);
    if(q>r||w<l) return;
    if(q>=l&&w<=r){
        z+=seg[rr];z%=mod;
        return;
    }
    read(q,(q+w)/2,rr*2);
    read((q+w)/2+1,w,rr*2+1);
}
int count_ways(int L, int R) {
    L++;R++;
    l=L;r=R;z=1;
    upd(1,za,1);
    pushdown(1,za,1);
    l=1;r=a;z=0;
    read(1,za,1);
    return z;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5072 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5184 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 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 5072 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 5200 KB Output is correct
7 Correct 4 ms 5200 KB Output is correct
8 Correct 5 ms 5268 KB Output is correct
9 Correct 4 ms 5200 KB Output is correct
10 Correct 4 ms 5312 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 3 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5072 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5184 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 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5200 KB Output is correct
15 Correct 4 ms 5200 KB Output is correct
16 Correct 5 ms 5268 KB Output is correct
17 Correct 4 ms 5200 KB Output is correct
18 Correct 4 ms 5312 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5200 KB Output is correct
21 Correct 3 ms 5200 KB Output is correct
22 Correct 3 ms 5200 KB Output is correct
23 Correct 3 ms 5200 KB Output is correct
24 Correct 3 ms 5200 KB Output is correct
25 Correct 3 ms 5200 KB Output is correct
26 Correct 3 ms 5200 KB Output is correct
27 Correct 3 ms 5200 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5200 KB Output is correct
33 Correct 3 ms 5200 KB Output is correct
34 Correct 3 ms 5200 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5200 KB Output is correct
40 Correct 4 ms 5200 KB Output is correct
41 Correct 5 ms 5200 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 662 ms 10868 KB Output is correct
2 Correct 881 ms 16648 KB Output is correct
3 Correct 793 ms 16664 KB Output is correct
4 Correct 1008 ms 16640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 662 ms 10868 KB Output is correct
2 Correct 881 ms 16648 KB Output is correct
3 Correct 793 ms 16664 KB Output is correct
4 Correct 1008 ms 16640 KB Output is correct
5 Correct 918 ms 10868 KB Output is correct
6 Correct 1094 ms 16644 KB Output is correct
7 Correct 1075 ms 16636 KB Output is correct
8 Correct 931 ms 16328 KB Output is correct
9 Correct 512 ms 5456 KB Output is correct
10 Correct 922 ms 5840 KB Output is correct
11 Correct 758 ms 5840 KB Output is correct
12 Correct 1002 ms 5712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 5072 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 5200 KB Output is correct
7 Correct 4 ms 5200 KB Output is correct
8 Correct 5 ms 5268 KB Output is correct
9 Correct 4 ms 5200 KB Output is correct
10 Correct 4 ms 5312 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 3 ms 5200 KB Output is correct
13 Correct 662 ms 10868 KB Output is correct
14 Correct 881 ms 16648 KB Output is correct
15 Correct 793 ms 16664 KB Output is correct
16 Correct 1008 ms 16640 KB Output is correct
17 Correct 918 ms 10868 KB Output is correct
18 Correct 1094 ms 16644 KB Output is correct
19 Correct 1075 ms 16636 KB Output is correct
20 Correct 931 ms 16328 KB Output is correct
21 Correct 512 ms 5456 KB Output is correct
22 Correct 922 ms 5840 KB Output is correct
23 Correct 758 ms 5840 KB Output is correct
24 Correct 1002 ms 5712 KB Output is correct
25 Correct 1022 ms 23432 KB Output is correct
26 Correct 1125 ms 23660 KB Output is correct
27 Correct 1057 ms 23660 KB Output is correct
28 Correct 861 ms 23188 KB Output is correct
29 Correct 1118 ms 28252 KB Output is correct
30 Correct 994 ms 27848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5072 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5184 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 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5200 KB Output is correct
15 Correct 4 ms 5200 KB Output is correct
16 Correct 5 ms 5268 KB Output is correct
17 Correct 4 ms 5200 KB Output is correct
18 Correct 4 ms 5312 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5200 KB Output is correct
21 Correct 3 ms 5200 KB Output is correct
22 Correct 3 ms 5200 KB Output is correct
23 Correct 3 ms 5200 KB Output is correct
24 Correct 3 ms 5200 KB Output is correct
25 Correct 3 ms 5200 KB Output is correct
26 Correct 3 ms 5200 KB Output is correct
27 Correct 3 ms 5200 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5200 KB Output is correct
33 Correct 3 ms 5200 KB Output is correct
34 Correct 3 ms 5200 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5200 KB Output is correct
40 Correct 4 ms 5200 KB Output is correct
41 Correct 5 ms 5200 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 580 ms 5584 KB Output is correct
44 Correct 863 ms 5712 KB Output is correct
45 Correct 772 ms 5712 KB Output is correct
46 Correct 840 ms 6072 KB Output is correct
47 Correct 978 ms 6096 KB Output is correct
48 Correct 932 ms 6152 KB Output is correct
49 Correct 836 ms 6152 KB Output is correct
50 Correct 757 ms 6052 KB Output is correct
51 Correct 852 ms 5664 KB Output is correct
52 Correct 1108 ms 5724 KB Output is correct
53 Correct 899 ms 5764 KB Output is correct
54 Correct 1043 ms 6092 KB Output is correct
55 Correct 1048 ms 5840 KB Output is correct
56 Correct 915 ms 5764 KB Output is correct
57 Correct 935 ms 5640 KB Output is correct
58 Correct 1214 ms 6276 KB Output is correct
59 Correct 1053 ms 6452 KB Output is correct
60 Correct 1067 ms 6388 KB Output is correct
61 Correct 1006 ms 5712 KB Output is correct
62 Correct 945 ms 5624 KB Output is correct
63 Correct 1029 ms 5584 KB Output is correct
64 Correct 1042 ms 5648 KB Output is correct
65 Correct 532 ms 5456 KB Output is correct
66 Correct 949 ms 5768 KB Output is correct
67 Correct 1119 ms 5840 KB Output is correct
68 Correct 964 ms 5768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5072 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5184 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 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5200 KB Output is correct
15 Correct 4 ms 5200 KB Output is correct
16 Correct 5 ms 5268 KB Output is correct
17 Correct 4 ms 5200 KB Output is correct
18 Correct 4 ms 5312 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5200 KB Output is correct
21 Correct 3 ms 5200 KB Output is correct
22 Correct 3 ms 5200 KB Output is correct
23 Correct 3 ms 5200 KB Output is correct
24 Correct 3 ms 5200 KB Output is correct
25 Correct 3 ms 5200 KB Output is correct
26 Correct 3 ms 5200 KB Output is correct
27 Correct 3 ms 5200 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5200 KB Output is correct
33 Correct 3 ms 5200 KB Output is correct
34 Correct 3 ms 5200 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5200 KB Output is correct
40 Correct 4 ms 5200 KB Output is correct
41 Correct 5 ms 5200 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 662 ms 10868 KB Output is correct
44 Correct 881 ms 16648 KB Output is correct
45 Correct 793 ms 16664 KB Output is correct
46 Correct 1008 ms 16640 KB Output is correct
47 Correct 918 ms 10868 KB Output is correct
48 Correct 1094 ms 16644 KB Output is correct
49 Correct 1075 ms 16636 KB Output is correct
50 Correct 931 ms 16328 KB Output is correct
51 Correct 512 ms 5456 KB Output is correct
52 Correct 922 ms 5840 KB Output is correct
53 Correct 758 ms 5840 KB Output is correct
54 Correct 1002 ms 5712 KB Output is correct
55 Correct 1022 ms 23432 KB Output is correct
56 Correct 1125 ms 23660 KB Output is correct
57 Correct 1057 ms 23660 KB Output is correct
58 Correct 861 ms 23188 KB Output is correct
59 Correct 1118 ms 28252 KB Output is correct
60 Correct 994 ms 27848 KB Output is correct
61 Correct 580 ms 5584 KB Output is correct
62 Correct 863 ms 5712 KB Output is correct
63 Correct 772 ms 5712 KB Output is correct
64 Correct 840 ms 6072 KB Output is correct
65 Correct 978 ms 6096 KB Output is correct
66 Correct 932 ms 6152 KB Output is correct
67 Correct 836 ms 6152 KB Output is correct
68 Correct 757 ms 6052 KB Output is correct
69 Correct 852 ms 5664 KB Output is correct
70 Correct 1108 ms 5724 KB Output is correct
71 Correct 899 ms 5764 KB Output is correct
72 Correct 1043 ms 6092 KB Output is correct
73 Correct 1048 ms 5840 KB Output is correct
74 Correct 915 ms 5764 KB Output is correct
75 Correct 935 ms 5640 KB Output is correct
76 Correct 1214 ms 6276 KB Output is correct
77 Correct 1053 ms 6452 KB Output is correct
78 Correct 1067 ms 6388 KB Output is correct
79 Correct 1006 ms 5712 KB Output is correct
80 Correct 945 ms 5624 KB Output is correct
81 Correct 1029 ms 5584 KB Output is correct
82 Correct 1042 ms 5648 KB Output is correct
83 Correct 532 ms 5456 KB Output is correct
84 Correct 949 ms 5768 KB Output is correct
85 Correct 1119 ms 5840 KB Output is correct
86 Correct 964 ms 5768 KB Output is correct
87 Correct 3 ms 4944 KB Output is correct
88 Correct 788 ms 22356 KB Output is correct
89 Correct 1098 ms 16232 KB Output is correct
90 Correct 1161 ms 16444 KB Output is correct
91 Correct 1141 ms 24320 KB Output is correct
92 Correct 1286 ms 24280 KB Output is correct
93 Correct 1373 ms 24300 KB Output is correct
94 Correct 1365 ms 24288 KB Output is correct
95 Correct 1373 ms 23752 KB Output is correct
96 Correct 990 ms 15008 KB Output is correct
97 Correct 983 ms 15884 KB Output is correct
98 Correct 1048 ms 18828 KB Output is correct
99 Correct 1165 ms 23660 KB Output is correct
100 Correct 1020 ms 21356 KB Output is correct
101 Correct 937 ms 18060 KB Output is correct
102 Correct 1087 ms 15936 KB Output is correct
103 Correct 917 ms 28356 KB Output is correct
104 Correct 1060 ms 29288 KB Output is correct
105 Correct 942 ms 28824 KB Output is correct
106 Correct 921 ms 16704 KB Output is correct
107 Correct 1099 ms 15388 KB Output is correct
108 Correct 930 ms 16036 KB Output is correct
109 Correct 1034 ms 16100 KB Output is correct