답안 #777639

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
777639 2023-07-09T11:46:20 Z alexander707070 디지털 회로 (IOI22_circuit) C++17
100 / 100
988 ms 85304 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<long long> v[MAXN],prefs[MAXN],suffs[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());
    prefs[x].resize(v[x].size());
    suffs[x].resize(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;

        prefs[x][i]=sz[v[x][i]];
        if(i>0)prefs[x][i]*=prefs[x][i-1];
        prefs[x][i]%=mod;
    }

    for(int i=v[x].size()-1;i>=0;i--){
        suffs[x][i]=sz[v[x][i]];
        if(i<v[x].size()-1)suffs[x][i]*=suffs[x][i+1];
        suffs[x][i]%=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++){
        if(v[x].size()==1){
            t=1;
        }else if(i==0){
            t=suffs[x][i+1];
        }else if(i==v[x].size()-1){
            t=prefs[x][i-1];
        }else{
            t=(prefs[x][i-1]*suffs[x][i+1])%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,6)<<"\n";
}
*/









Compilation message

circuit.cpp: In function 'void calc(int)':
circuit.cpp:29:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
circuit.cpp:41:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |         if(i<v[x].size()-1)suffs[x][i]*=suffs[x][i+1];
      |            ~^~~~~~~~~~~~~~
circuit.cpp: In function 'void dfs(int, long long int)':
circuit.cpp:53:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |     for(int i=0;i<v[x].size();i++){
      |                 ~^~~~~~~~~~~~
circuit.cpp:58:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |         }else if(i==v[x].size()-1){
      |                  ~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 56656 KB Output is correct
2 Correct 24 ms 56636 KB Output is correct
3 Correct 23 ms 56728 KB Output is correct
4 Correct 23 ms 56748 KB Output is correct
5 Correct 24 ms 56696 KB Output is correct
6 Correct 24 ms 56684 KB Output is correct
7 Correct 32 ms 56648 KB Output is correct
8 Correct 23 ms 56748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 56608 KB Output is correct
2 Correct 23 ms 56656 KB Output is correct
3 Correct 24 ms 56752 KB Output is correct
4 Correct 23 ms 56784 KB Output is correct
5 Correct 25 ms 56656 KB Output is correct
6 Correct 25 ms 56784 KB Output is correct
7 Correct 25 ms 56856 KB Output is correct
8 Correct 26 ms 56796 KB Output is correct
9 Correct 27 ms 56856 KB Output is correct
10 Correct 27 ms 56804 KB Output is correct
11 Correct 26 ms 56884 KB Output is correct
12 Correct 23 ms 56768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 56656 KB Output is correct
2 Correct 24 ms 56636 KB Output is correct
3 Correct 23 ms 56728 KB Output is correct
4 Correct 23 ms 56748 KB Output is correct
5 Correct 24 ms 56696 KB Output is correct
6 Correct 24 ms 56684 KB Output is correct
7 Correct 32 ms 56648 KB Output is correct
8 Correct 23 ms 56748 KB Output is correct
9 Correct 26 ms 56608 KB Output is correct
10 Correct 23 ms 56656 KB Output is correct
11 Correct 24 ms 56752 KB Output is correct
12 Correct 23 ms 56784 KB Output is correct
13 Correct 25 ms 56656 KB Output is correct
14 Correct 25 ms 56784 KB Output is correct
15 Correct 25 ms 56856 KB Output is correct
16 Correct 26 ms 56796 KB Output is correct
17 Correct 27 ms 56856 KB Output is correct
18 Correct 27 ms 56804 KB Output is correct
19 Correct 26 ms 56884 KB Output is correct
20 Correct 23 ms 56768 KB Output is correct
21 Correct 24 ms 56732 KB Output is correct
22 Correct 23 ms 56728 KB Output is correct
23 Correct 28 ms 56788 KB Output is correct
24 Correct 26 ms 56780 KB Output is correct
25 Correct 25 ms 56784 KB Output is correct
26 Correct 25 ms 56764 KB Output is correct
27 Correct 26 ms 56784 KB Output is correct
28 Correct 25 ms 56784 KB Output is correct
29 Correct 25 ms 56784 KB Output is correct
30 Correct 25 ms 56648 KB Output is correct
31 Correct 26 ms 56784 KB Output is correct
32 Correct 25 ms 56792 KB Output is correct
33 Correct 25 ms 56756 KB Output is correct
34 Correct 32 ms 56764 KB Output is correct
35 Correct 25 ms 56784 KB Output is correct
36 Correct 25 ms 56848 KB Output is correct
37 Correct 33 ms 56916 KB Output is correct
38 Correct 26 ms 56888 KB Output is correct
39 Correct 25 ms 56784 KB Output is correct
40 Correct 25 ms 56776 KB Output is correct
41 Correct 26 ms 56776 KB Output is correct
42 Correct 25 ms 56784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 568 ms 62264 KB Output is correct
2 Correct 664 ms 67908 KB Output is correct
3 Correct 875 ms 67940 KB Output is correct
4 Correct 873 ms 67188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 568 ms 62264 KB Output is correct
2 Correct 664 ms 67908 KB Output is correct
3 Correct 875 ms 67940 KB Output is correct
4 Correct 873 ms 67188 KB Output is correct
5 Correct 702 ms 62296 KB Output is correct
6 Correct 988 ms 67916 KB Output is correct
7 Correct 969 ms 67944 KB Output is correct
8 Correct 707 ms 67956 KB Output is correct
9 Correct 463 ms 56936 KB Output is correct
10 Correct 729 ms 57424 KB Output is correct
11 Correct 830 ms 57424 KB Output is correct
12 Correct 735 ms 57288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 56608 KB Output is correct
2 Correct 23 ms 56656 KB Output is correct
3 Correct 24 ms 56752 KB Output is correct
4 Correct 23 ms 56784 KB Output is correct
5 Correct 25 ms 56656 KB Output is correct
6 Correct 25 ms 56784 KB Output is correct
7 Correct 25 ms 56856 KB Output is correct
8 Correct 26 ms 56796 KB Output is correct
9 Correct 27 ms 56856 KB Output is correct
10 Correct 27 ms 56804 KB Output is correct
11 Correct 26 ms 56884 KB Output is correct
12 Correct 23 ms 56768 KB Output is correct
13 Correct 568 ms 62264 KB Output is correct
14 Correct 664 ms 67908 KB Output is correct
15 Correct 875 ms 67940 KB Output is correct
16 Correct 873 ms 67188 KB Output is correct
17 Correct 702 ms 62296 KB Output is correct
18 Correct 988 ms 67916 KB Output is correct
19 Correct 969 ms 67944 KB Output is correct
20 Correct 707 ms 67956 KB Output is correct
21 Correct 463 ms 56936 KB Output is correct
22 Correct 729 ms 57424 KB Output is correct
23 Correct 830 ms 57424 KB Output is correct
24 Correct 735 ms 57288 KB Output is correct
25 Correct 770 ms 74784 KB Output is correct
26 Correct 803 ms 75092 KB Output is correct
27 Correct 901 ms 75124 KB Output is correct
28 Correct 688 ms 75056 KB Output is correct
29 Correct 915 ms 82948 KB Output is correct
30 Correct 829 ms 82924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 56656 KB Output is correct
2 Correct 24 ms 56636 KB Output is correct
3 Correct 23 ms 56728 KB Output is correct
4 Correct 23 ms 56748 KB Output is correct
5 Correct 24 ms 56696 KB Output is correct
6 Correct 24 ms 56684 KB Output is correct
7 Correct 32 ms 56648 KB Output is correct
8 Correct 23 ms 56748 KB Output is correct
9 Correct 26 ms 56608 KB Output is correct
10 Correct 23 ms 56656 KB Output is correct
11 Correct 24 ms 56752 KB Output is correct
12 Correct 23 ms 56784 KB Output is correct
13 Correct 25 ms 56656 KB Output is correct
14 Correct 25 ms 56784 KB Output is correct
15 Correct 25 ms 56856 KB Output is correct
16 Correct 26 ms 56796 KB Output is correct
17 Correct 27 ms 56856 KB Output is correct
18 Correct 27 ms 56804 KB Output is correct
19 Correct 26 ms 56884 KB Output is correct
20 Correct 23 ms 56768 KB Output is correct
21 Correct 24 ms 56732 KB Output is correct
22 Correct 23 ms 56728 KB Output is correct
23 Correct 28 ms 56788 KB Output is correct
24 Correct 26 ms 56780 KB Output is correct
25 Correct 25 ms 56784 KB Output is correct
26 Correct 25 ms 56764 KB Output is correct
27 Correct 26 ms 56784 KB Output is correct
28 Correct 25 ms 56784 KB Output is correct
29 Correct 25 ms 56784 KB Output is correct
30 Correct 25 ms 56648 KB Output is correct
31 Correct 26 ms 56784 KB Output is correct
32 Correct 25 ms 56792 KB Output is correct
33 Correct 25 ms 56756 KB Output is correct
34 Correct 32 ms 56764 KB Output is correct
35 Correct 25 ms 56784 KB Output is correct
36 Correct 25 ms 56848 KB Output is correct
37 Correct 33 ms 56916 KB Output is correct
38 Correct 26 ms 56888 KB Output is correct
39 Correct 25 ms 56784 KB Output is correct
40 Correct 25 ms 56776 KB Output is correct
41 Correct 26 ms 56776 KB Output is correct
42 Correct 25 ms 56784 KB Output is correct
43 Correct 561 ms 57168 KB Output is correct
44 Correct 735 ms 57328 KB Output is correct
45 Correct 877 ms 57296 KB Output is correct
46 Correct 839 ms 57672 KB Output is correct
47 Correct 614 ms 57672 KB Output is correct
48 Correct 688 ms 57628 KB Output is correct
49 Correct 736 ms 57692 KB Output is correct
50 Correct 570 ms 57680 KB Output is correct
51 Correct 703 ms 57256 KB Output is correct
52 Correct 746 ms 57276 KB Output is correct
53 Correct 738 ms 57552 KB Output is correct
54 Correct 786 ms 57596 KB Output is correct
55 Correct 693 ms 57412 KB Output is correct
56 Correct 691 ms 57236 KB Output is correct
57 Correct 728 ms 57288 KB Output is correct
58 Correct 584 ms 58064 KB Output is correct
59 Correct 730 ms 58192 KB Output is correct
60 Correct 813 ms 58192 KB Output is correct
61 Correct 663 ms 57424 KB Output is correct
62 Correct 819 ms 57168 KB Output is correct
63 Correct 699 ms 57168 KB Output is correct
64 Correct 711 ms 57160 KB Output is correct
65 Correct 383 ms 57004 KB Output is correct
66 Correct 659 ms 57404 KB Output is correct
67 Correct 727 ms 57428 KB Output is correct
68 Correct 737 ms 57296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 56656 KB Output is correct
2 Correct 24 ms 56636 KB Output is correct
3 Correct 23 ms 56728 KB Output is correct
4 Correct 23 ms 56748 KB Output is correct
5 Correct 24 ms 56696 KB Output is correct
6 Correct 24 ms 56684 KB Output is correct
7 Correct 32 ms 56648 KB Output is correct
8 Correct 23 ms 56748 KB Output is correct
9 Correct 26 ms 56608 KB Output is correct
10 Correct 23 ms 56656 KB Output is correct
11 Correct 24 ms 56752 KB Output is correct
12 Correct 23 ms 56784 KB Output is correct
13 Correct 25 ms 56656 KB Output is correct
14 Correct 25 ms 56784 KB Output is correct
15 Correct 25 ms 56856 KB Output is correct
16 Correct 26 ms 56796 KB Output is correct
17 Correct 27 ms 56856 KB Output is correct
18 Correct 27 ms 56804 KB Output is correct
19 Correct 26 ms 56884 KB Output is correct
20 Correct 23 ms 56768 KB Output is correct
21 Correct 24 ms 56732 KB Output is correct
22 Correct 23 ms 56728 KB Output is correct
23 Correct 28 ms 56788 KB Output is correct
24 Correct 26 ms 56780 KB Output is correct
25 Correct 25 ms 56784 KB Output is correct
26 Correct 25 ms 56764 KB Output is correct
27 Correct 26 ms 56784 KB Output is correct
28 Correct 25 ms 56784 KB Output is correct
29 Correct 25 ms 56784 KB Output is correct
30 Correct 25 ms 56648 KB Output is correct
31 Correct 26 ms 56784 KB Output is correct
32 Correct 25 ms 56792 KB Output is correct
33 Correct 25 ms 56756 KB Output is correct
34 Correct 32 ms 56764 KB Output is correct
35 Correct 25 ms 56784 KB Output is correct
36 Correct 25 ms 56848 KB Output is correct
37 Correct 33 ms 56916 KB Output is correct
38 Correct 26 ms 56888 KB Output is correct
39 Correct 25 ms 56784 KB Output is correct
40 Correct 25 ms 56776 KB Output is correct
41 Correct 26 ms 56776 KB Output is correct
42 Correct 25 ms 56784 KB Output is correct
43 Correct 568 ms 62264 KB Output is correct
44 Correct 664 ms 67908 KB Output is correct
45 Correct 875 ms 67940 KB Output is correct
46 Correct 873 ms 67188 KB Output is correct
47 Correct 702 ms 62296 KB Output is correct
48 Correct 988 ms 67916 KB Output is correct
49 Correct 969 ms 67944 KB Output is correct
50 Correct 707 ms 67956 KB Output is correct
51 Correct 463 ms 56936 KB Output is correct
52 Correct 729 ms 57424 KB Output is correct
53 Correct 830 ms 57424 KB Output is correct
54 Correct 735 ms 57288 KB Output is correct
55 Correct 770 ms 74784 KB Output is correct
56 Correct 803 ms 75092 KB Output is correct
57 Correct 901 ms 75124 KB Output is correct
58 Correct 688 ms 75056 KB Output is correct
59 Correct 915 ms 82948 KB Output is correct
60 Correct 829 ms 82924 KB Output is correct
61 Correct 561 ms 57168 KB Output is correct
62 Correct 735 ms 57328 KB Output is correct
63 Correct 877 ms 57296 KB Output is correct
64 Correct 839 ms 57672 KB Output is correct
65 Correct 614 ms 57672 KB Output is correct
66 Correct 688 ms 57628 KB Output is correct
67 Correct 736 ms 57692 KB Output is correct
68 Correct 570 ms 57680 KB Output is correct
69 Correct 703 ms 57256 KB Output is correct
70 Correct 746 ms 57276 KB Output is correct
71 Correct 738 ms 57552 KB Output is correct
72 Correct 786 ms 57596 KB Output is correct
73 Correct 693 ms 57412 KB Output is correct
74 Correct 691 ms 57236 KB Output is correct
75 Correct 728 ms 57288 KB Output is correct
76 Correct 584 ms 58064 KB Output is correct
77 Correct 730 ms 58192 KB Output is correct
78 Correct 813 ms 58192 KB Output is correct
79 Correct 663 ms 57424 KB Output is correct
80 Correct 819 ms 57168 KB Output is correct
81 Correct 699 ms 57168 KB Output is correct
82 Correct 711 ms 57160 KB Output is correct
83 Correct 383 ms 57004 KB Output is correct
84 Correct 659 ms 57404 KB Output is correct
85 Correct 727 ms 57428 KB Output is correct
86 Correct 737 ms 57296 KB Output is correct
87 Correct 25 ms 56644 KB Output is correct
88 Correct 607 ms 74640 KB Output is correct
89 Correct 849 ms 68924 KB Output is correct
90 Correct 764 ms 68400 KB Output is correct
91 Correct 949 ms 76360 KB Output is correct
92 Correct 871 ms 76256 KB Output is correct
93 Correct 781 ms 75644 KB Output is correct
94 Correct 881 ms 76240 KB Output is correct
95 Correct 856 ms 76272 KB Output is correct
96 Correct 782 ms 66596 KB Output is correct
97 Correct 796 ms 66664 KB Output is correct
98 Correct 577 ms 75332 KB Output is correct
99 Correct 947 ms 75124 KB Output is correct
100 Correct 882 ms 70472 KB Output is correct
101 Correct 863 ms 68936 KB Output is correct
102 Correct 815 ms 66628 KB Output is correct
103 Correct 756 ms 82988 KB Output is correct
104 Correct 812 ms 85228 KB Output is correct
105 Correct 654 ms 85304 KB Output is correct
106 Correct 902 ms 70416 KB Output is correct
107 Correct 711 ms 67856 KB Output is correct
108 Correct 761 ms 67784 KB Output is correct
109 Correct 744 ms 66772 KB Output is correct