Submission #777635

# Submission time Handle Problem Language Result Execution time Memory
777635 2023-07-09T11:40:39 Z alexander707070 Digital Circuit (IOI22_circuit) C++17
89 / 100
3000 ms 37544 KB
#include<bits/stdc++.h>
#define MAXN 800007
using namespace std;

const long long mod=1000002022;

int n,m,maxdep,pw;
long long st[MAXN],total,diff,zeros,ans,a[MAXN];
long long pref[MAXN],pr,sz[MAXN];
vector<int> v[MAXN];

long long power(long long x,int y){
    if(y==0)return 1;
    if(y==1)return x;
    if(y==2)return (x*x)%mod;
    if(y%2==0)return power(power(x,y/2),2);
    return (power(power(x,y/2),2)*x)%mod;
}

void calc(int x){
    if(v[x].size()==0){
        sz[x]=1; return;
    }

    sz[x]=int(v[x].size());
    for(int i=0;i<v[x].size();i++){
        calc(v[x][i]);
        sz[x]*=sz[v[x][i]]; 
        sz[x]%=mod;
    }
}

void dfs(int x,long long curr){
    if(v[x].size()==0){
        st[x]=curr;
        return;
    }

    long long t;
    for(int i=0;i<v[x].size();i++){
        t=1;
        for(int f=0;f<v[x].size();f++){
            if(i==f)continue;
            t*=sz[v[x][f]]; t%=mod;
        }
        dfs(v[x][i],(curr*t)%mod);
    }
}

long long tree[MAXN],lazy[MAXN];

long long sum(int l,int r){
    if(l==0)return pref[r];
    return (pref[r]-pref[l-1]+mod)%mod;
}

void psh(int v,int l,int r){
    if(lazy[v]==0)return;
    int tt=(l+r)/2;

    tree[2*v]=(sum(l,tt)-tree[2*v]+mod)%mod;
    lazy[2*v]^=1; 
    
    tree[2*v+1]=(sum(tt+1,r)-tree[2*v+1]+mod)%mod;
    lazy[2*v+1]^=1;

    lazy[v]=0;
}

void update(int v,int l,int r,int ll,int rr){
    if(ll>rr)return;
    if(l==ll and r==rr){
        tree[v]=(sum(l,r)-tree[v]+mod)%mod;
        lazy[v]^=1;
    }else{
        int tt=(l+r)/2;
        psh(v,l,r);

        update(2*v,l,tt,ll,min(tt,rr));
        update(2*v+1,tt+1,r,max(tt+1,ll),rr);

        tree[v]=(tree[2*v]+tree[2*v+1])%mod;
    }
}

void init(int N, int M,vector<int> P,vector<int> A){
    n=N; m=M;

    for(int i=1;i<N+M;i++){
        v[P[i]].push_back(i);
    }    

    calc(0);
    dfs(0,1);

    for(int i=0;i<m;i++){
        pref[i]=st[i+N];
        if(i>0)pref[i]+=pref[i-1];
        pref[i]%=mod;
    }

    for(int i=0;i<m;i++){
        if(A[i]==1)update(1,0,m-1,i,i);
    }
}

int count_ways(int L, int R){
    L-=n; R-=n;
    update(1,0,m-1,L,R);

    return tree[1];
}

/*
int main(){
    init(3,4, {-1,0,1,1,2,2,0}, {0,0,0,0});
    cout<<count_ways(3,5)<<"\n";
}
*/

Compilation message

circuit.cpp: In function 'void calc(int)':
circuit.cpp:26:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   26 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
circuit.cpp: In function 'void dfs(int, long long int)':
circuit.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
circuit.cpp:42:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |         for(int f=0;f<v[x].size();f++){
      |                     ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19024 KB Output is correct
2 Correct 9 ms 19024 KB Output is correct
3 Correct 15 ms 19152 KB Output is correct
4 Correct 14 ms 19152 KB Output is correct
5 Correct 13 ms 19152 KB Output is correct
6 Correct 13 ms 19152 KB Output is correct
7 Correct 14 ms 19148 KB Output is correct
8 Correct 13 ms 19088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 19024 KB Output is correct
2 Correct 9 ms 19068 KB Output is correct
3 Correct 9 ms 19152 KB Output is correct
4 Correct 9 ms 19152 KB Output is correct
5 Correct 10 ms 19152 KB Output is correct
6 Correct 12 ms 19152 KB Output is correct
7 Correct 13 ms 19156 KB Output is correct
8 Correct 13 ms 19172 KB Output is correct
9 Correct 12 ms 19152 KB Output is correct
10 Correct 10 ms 19176 KB Output is correct
11 Correct 10 ms 19280 KB Output is correct
12 Correct 10 ms 19152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19024 KB Output is correct
2 Correct 9 ms 19024 KB Output is correct
3 Correct 15 ms 19152 KB Output is correct
4 Correct 14 ms 19152 KB Output is correct
5 Correct 13 ms 19152 KB Output is correct
6 Correct 13 ms 19152 KB Output is correct
7 Correct 14 ms 19148 KB Output is correct
8 Correct 13 ms 19088 KB Output is correct
9 Correct 8 ms 19024 KB Output is correct
10 Correct 9 ms 19068 KB Output is correct
11 Correct 9 ms 19152 KB Output is correct
12 Correct 9 ms 19152 KB Output is correct
13 Correct 10 ms 19152 KB Output is correct
14 Correct 12 ms 19152 KB Output is correct
15 Correct 13 ms 19156 KB Output is correct
16 Correct 13 ms 19172 KB Output is correct
17 Correct 12 ms 19152 KB Output is correct
18 Correct 10 ms 19176 KB Output is correct
19 Correct 10 ms 19280 KB Output is correct
20 Correct 10 ms 19152 KB Output is correct
21 Correct 10 ms 19164 KB Output is correct
22 Correct 9 ms 19152 KB Output is correct
23 Correct 9 ms 19084 KB Output is correct
24 Correct 10 ms 19180 KB Output is correct
25 Correct 11 ms 19112 KB Output is correct
26 Correct 12 ms 19164 KB Output is correct
27 Correct 11 ms 19152 KB Output is correct
28 Correct 11 ms 19152 KB Output is correct
29 Correct 13 ms 19092 KB Output is correct
30 Correct 13 ms 19152 KB Output is correct
31 Correct 10 ms 19152 KB Output is correct
32 Correct 9 ms 19200 KB Output is correct
33 Correct 9 ms 19152 KB Output is correct
34 Correct 9 ms 19152 KB Output is correct
35 Correct 11 ms 19124 KB Output is correct
36 Correct 10 ms 19280 KB Output is correct
37 Correct 16 ms 19248 KB Output is correct
38 Correct 14 ms 19184 KB Output is correct
39 Correct 10 ms 19164 KB Output is correct
40 Correct 10 ms 19152 KB Output is correct
41 Correct 10 ms 19152 KB Output is correct
42 Correct 9 ms 19152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 528 ms 22648 KB Output is correct
2 Correct 744 ms 26260 KB Output is correct
3 Correct 921 ms 26256 KB Output is correct
4 Correct 755 ms 25536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 528 ms 22648 KB Output is correct
2 Correct 744 ms 26260 KB Output is correct
3 Correct 921 ms 26256 KB Output is correct
4 Correct 755 ms 25536 KB Output is correct
5 Correct 586 ms 22728 KB Output is correct
6 Correct 744 ms 26276 KB Output is correct
7 Correct 878 ms 26184 KB Output is correct
8 Correct 676 ms 26276 KB Output is correct
9 Correct 421 ms 19344 KB Output is correct
10 Correct 700 ms 19584 KB Output is correct
11 Correct 663 ms 19536 KB Output is correct
12 Correct 636 ms 19468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 19024 KB Output is correct
2 Correct 9 ms 19068 KB Output is correct
3 Correct 9 ms 19152 KB Output is correct
4 Correct 9 ms 19152 KB Output is correct
5 Correct 10 ms 19152 KB Output is correct
6 Correct 12 ms 19152 KB Output is correct
7 Correct 13 ms 19156 KB Output is correct
8 Correct 13 ms 19172 KB Output is correct
9 Correct 12 ms 19152 KB Output is correct
10 Correct 10 ms 19176 KB Output is correct
11 Correct 10 ms 19280 KB Output is correct
12 Correct 10 ms 19152 KB Output is correct
13 Correct 528 ms 22648 KB Output is correct
14 Correct 744 ms 26260 KB Output is correct
15 Correct 921 ms 26256 KB Output is correct
16 Correct 755 ms 25536 KB Output is correct
17 Correct 586 ms 22728 KB Output is correct
18 Correct 744 ms 26276 KB Output is correct
19 Correct 878 ms 26184 KB Output is correct
20 Correct 676 ms 26276 KB Output is correct
21 Correct 421 ms 19344 KB Output is correct
22 Correct 700 ms 19584 KB Output is correct
23 Correct 663 ms 19536 KB Output is correct
24 Correct 636 ms 19468 KB Output is correct
25 Correct 670 ms 31148 KB Output is correct
26 Correct 902 ms 31304 KB Output is correct
27 Correct 861 ms 31228 KB Output is correct
28 Correct 678 ms 31248 KB Output is correct
29 Correct 826 ms 37544 KB Output is correct
30 Correct 778 ms 37516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19024 KB Output is correct
2 Correct 9 ms 19024 KB Output is correct
3 Correct 15 ms 19152 KB Output is correct
4 Correct 14 ms 19152 KB Output is correct
5 Correct 13 ms 19152 KB Output is correct
6 Correct 13 ms 19152 KB Output is correct
7 Correct 14 ms 19148 KB Output is correct
8 Correct 13 ms 19088 KB Output is correct
9 Correct 8 ms 19024 KB Output is correct
10 Correct 9 ms 19068 KB Output is correct
11 Correct 9 ms 19152 KB Output is correct
12 Correct 9 ms 19152 KB Output is correct
13 Correct 10 ms 19152 KB Output is correct
14 Correct 12 ms 19152 KB Output is correct
15 Correct 13 ms 19156 KB Output is correct
16 Correct 13 ms 19172 KB Output is correct
17 Correct 12 ms 19152 KB Output is correct
18 Correct 10 ms 19176 KB Output is correct
19 Correct 10 ms 19280 KB Output is correct
20 Correct 10 ms 19152 KB Output is correct
21 Correct 10 ms 19164 KB Output is correct
22 Correct 9 ms 19152 KB Output is correct
23 Correct 9 ms 19084 KB Output is correct
24 Correct 10 ms 19180 KB Output is correct
25 Correct 11 ms 19112 KB Output is correct
26 Correct 12 ms 19164 KB Output is correct
27 Correct 11 ms 19152 KB Output is correct
28 Correct 11 ms 19152 KB Output is correct
29 Correct 13 ms 19092 KB Output is correct
30 Correct 13 ms 19152 KB Output is correct
31 Correct 10 ms 19152 KB Output is correct
32 Correct 9 ms 19200 KB Output is correct
33 Correct 9 ms 19152 KB Output is correct
34 Correct 9 ms 19152 KB Output is correct
35 Correct 11 ms 19124 KB Output is correct
36 Correct 10 ms 19280 KB Output is correct
37 Correct 16 ms 19248 KB Output is correct
38 Correct 14 ms 19184 KB Output is correct
39 Correct 10 ms 19164 KB Output is correct
40 Correct 10 ms 19152 KB Output is correct
41 Correct 10 ms 19152 KB Output is correct
42 Correct 9 ms 19152 KB Output is correct
43 Correct 531 ms 19408 KB Output is correct
44 Correct 576 ms 19536 KB Output is correct
45 Correct 690 ms 19476 KB Output is correct
46 Correct 718 ms 19728 KB Output is correct
47 Correct 648 ms 19916 KB Output is correct
48 Correct 826 ms 19816 KB Output is correct
49 Correct 820 ms 19792 KB Output is correct
50 Correct 807 ms 19716 KB Output is correct
51 Correct 819 ms 19536 KB Output is correct
52 Correct 890 ms 19616 KB Output is correct
53 Correct 675 ms 19632 KB Output is correct
54 Correct 842 ms 19732 KB Output is correct
55 Correct 748 ms 19588 KB Output is correct
56 Correct 676 ms 19652 KB Output is correct
57 Correct 775 ms 19476 KB Output is correct
58 Correct 844 ms 20104 KB Output is correct
59 Correct 926 ms 20156 KB Output is correct
60 Correct 865 ms 20140 KB Output is correct
61 Correct 741 ms 19556 KB Output is correct
62 Correct 768 ms 19476 KB Output is correct
63 Correct 860 ms 19408 KB Output is correct
64 Correct 798 ms 19516 KB Output is correct
65 Correct 346 ms 19244 KB Output is correct
66 Correct 785 ms 19524 KB Output is correct
67 Correct 945 ms 19468 KB Output is correct
68 Correct 725 ms 19536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 19024 KB Output is correct
2 Correct 9 ms 19024 KB Output is correct
3 Correct 15 ms 19152 KB Output is correct
4 Correct 14 ms 19152 KB Output is correct
5 Correct 13 ms 19152 KB Output is correct
6 Correct 13 ms 19152 KB Output is correct
7 Correct 14 ms 19148 KB Output is correct
8 Correct 13 ms 19088 KB Output is correct
9 Correct 8 ms 19024 KB Output is correct
10 Correct 9 ms 19068 KB Output is correct
11 Correct 9 ms 19152 KB Output is correct
12 Correct 9 ms 19152 KB Output is correct
13 Correct 10 ms 19152 KB Output is correct
14 Correct 12 ms 19152 KB Output is correct
15 Correct 13 ms 19156 KB Output is correct
16 Correct 13 ms 19172 KB Output is correct
17 Correct 12 ms 19152 KB Output is correct
18 Correct 10 ms 19176 KB Output is correct
19 Correct 10 ms 19280 KB Output is correct
20 Correct 10 ms 19152 KB Output is correct
21 Correct 10 ms 19164 KB Output is correct
22 Correct 9 ms 19152 KB Output is correct
23 Correct 9 ms 19084 KB Output is correct
24 Correct 10 ms 19180 KB Output is correct
25 Correct 11 ms 19112 KB Output is correct
26 Correct 12 ms 19164 KB Output is correct
27 Correct 11 ms 19152 KB Output is correct
28 Correct 11 ms 19152 KB Output is correct
29 Correct 13 ms 19092 KB Output is correct
30 Correct 13 ms 19152 KB Output is correct
31 Correct 10 ms 19152 KB Output is correct
32 Correct 9 ms 19200 KB Output is correct
33 Correct 9 ms 19152 KB Output is correct
34 Correct 9 ms 19152 KB Output is correct
35 Correct 11 ms 19124 KB Output is correct
36 Correct 10 ms 19280 KB Output is correct
37 Correct 16 ms 19248 KB Output is correct
38 Correct 14 ms 19184 KB Output is correct
39 Correct 10 ms 19164 KB Output is correct
40 Correct 10 ms 19152 KB Output is correct
41 Correct 10 ms 19152 KB Output is correct
42 Correct 9 ms 19152 KB Output is correct
43 Correct 528 ms 22648 KB Output is correct
44 Correct 744 ms 26260 KB Output is correct
45 Correct 921 ms 26256 KB Output is correct
46 Correct 755 ms 25536 KB Output is correct
47 Correct 586 ms 22728 KB Output is correct
48 Correct 744 ms 26276 KB Output is correct
49 Correct 878 ms 26184 KB Output is correct
50 Correct 676 ms 26276 KB Output is correct
51 Correct 421 ms 19344 KB Output is correct
52 Correct 700 ms 19584 KB Output is correct
53 Correct 663 ms 19536 KB Output is correct
54 Correct 636 ms 19468 KB Output is correct
55 Correct 670 ms 31148 KB Output is correct
56 Correct 902 ms 31304 KB Output is correct
57 Correct 861 ms 31228 KB Output is correct
58 Correct 678 ms 31248 KB Output is correct
59 Correct 826 ms 37544 KB Output is correct
60 Correct 778 ms 37516 KB Output is correct
61 Correct 531 ms 19408 KB Output is correct
62 Correct 576 ms 19536 KB Output is correct
63 Correct 690 ms 19476 KB Output is correct
64 Correct 718 ms 19728 KB Output is correct
65 Correct 648 ms 19916 KB Output is correct
66 Correct 826 ms 19816 KB Output is correct
67 Correct 820 ms 19792 KB Output is correct
68 Correct 807 ms 19716 KB Output is correct
69 Correct 819 ms 19536 KB Output is correct
70 Correct 890 ms 19616 KB Output is correct
71 Correct 675 ms 19632 KB Output is correct
72 Correct 842 ms 19732 KB Output is correct
73 Correct 748 ms 19588 KB Output is correct
74 Correct 676 ms 19652 KB Output is correct
75 Correct 775 ms 19476 KB Output is correct
76 Correct 844 ms 20104 KB Output is correct
77 Correct 926 ms 20156 KB Output is correct
78 Correct 865 ms 20140 KB Output is correct
79 Correct 741 ms 19556 KB Output is correct
80 Correct 768 ms 19476 KB Output is correct
81 Correct 860 ms 19408 KB Output is correct
82 Correct 798 ms 19516 KB Output is correct
83 Correct 346 ms 19244 KB Output is correct
84 Correct 785 ms 19524 KB Output is correct
85 Correct 945 ms 19468 KB Output is correct
86 Correct 725 ms 19536 KB Output is correct
87 Correct 9 ms 19064 KB Output is correct
88 Correct 588 ms 30280 KB Output is correct
89 Correct 722 ms 26516 KB Output is correct
90 Correct 934 ms 26212 KB Output is correct
91 Correct 967 ms 31336 KB Output is correct
92 Correct 1010 ms 31400 KB Output is correct
93 Correct 996 ms 30776 KB Output is correct
94 Correct 957 ms 31400 KB Output is correct
95 Correct 818 ms 31360 KB Output is correct
96 Execution timed out 3044 ms 22016 KB Time limit exceeded
97 Halted 0 ms 0 KB -