답안 #627509

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
627509 2022-08-12T15:58:42 Z Kaitokid 디지털 회로 (IOI22_circuit) C++17
100 / 100
1130 ms 25448 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int mod=1000002022;
vector<int>ch[200009];
int sz[200009], f[200009],n,m;
void dfs(int x)
{
    if(ch[x].empty()){sz[x]=1;return;}
    sz[x]=ch[x].size();
    for(int i=0;i<ch[x].size();i++){dfs(ch[x][i]);sz[x]=(sz[x]*1LL*sz[ch[x][i]])%mod;}
   // cout<<55<<" "<<x<<" "<<sz[x]<<endl;
}

void go(int x,int prd)
{
    //cout<<66<<" "<<x<<" "<<prd<<endl;
    if(ch[x].empty()){f[x-n]=prd;return;}
    int w=ch[x].size();
    vector<int>suf(w+1);
    suf[w]=1;
    for(int i=w-1;i>=0;i--)suf[i]=(suf[i+1]*1LL*sz[ch[x][i]])%mod;
    int d=1;
    for(int i=0;i<w;i++)
    {
        int r=(d*1LL*suf[i+1])%mod;
        go(ch[x][i],(r*1LL*prd)%mod);
        d=(d*1LL*sz[ch[x][i]])%mod;
    }

}
int sg[400009][2];
int lz[400009];
vector<int>onn;
void build(int x=1,int st=0,int en=m-1)
{
    if(st==en){sg[x][0]=f[st];sg[x][1]=f[st]*onn[st];return;}
    int mid=(st+en)>>1;
    build((x<<1),st,mid);
    build((x<<1)|1,mid+1,en);
    sg[x][0]=(sg[(x<<1)][0]+sg[(x<<1)|1][0])%mod;
    sg[x][1]=(sg[(x<<1)][1]+sg[(x<<1)|1][1])%mod;


}
void psh(int x,int st,int en)
{
    if(lz[x]==0)return;
    sg[x][1]=(sg[x][0]-sg[x][1]+mod)%mod;
    lz[x]=0;
    if(en>st)
    {
        lz[(x<<1)]=1-lz[(x<<1)];
        lz[(x<<1)|1]=1-lz[(x<<1)|1];

    }
}
void upd(int l,int r,int x=1,int st=0,int en=m-1)
{
    psh(x,st,en);
    if(l>en||st>r)return;
    if(st>=l && en<=r){lz[x]=1;psh(x,st,en);return ;}
    int mid=(st+en)>>1;
    upd(l,r,(x<<1),st,mid);
    upd(l,r,(x<<1)|1,mid+1,en);
    sg[x][0]=(sg[(x<<1)][0]+sg[(x<<1)|1][0])%mod;
    sg[x][1]=(sg[(x<<1)][1]+sg[(x<<1)|1][1])%mod;

}
void init(int N,int M,vector<int> P,vector<int> A)
{
    n=N;
    m=M;
    onn=A;
    for(int i=1;i<n+m;i++)
        ch[P[i]].push_back(i);
    dfs(0);
    go(0,1);
    build();
   /* for(int i=0;i<m;i++)cout<<f[i]<<" "<<sz[i]<<endl;
    cout<<endl;

    cout<<sg[1][0]<<" "<<sg[1][1]<<endl;*/
}
int count_ways(int L,int R)
{
    upd(L-n,R-n);
    return sg[1][1];
}

Compilation message

circuit.cpp: In function 'void dfs(int)':
circuit.cpp:11:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   11 |     for(int i=0;i<ch[x].size();i++){dfs(ch[x][i]);sz[x]=(sz[x]*1LL*sz[ch[x][i]])%mod;}
      |                 ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 5072 KB Output is correct
4 Correct 4 ms 5072 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 4 ms 4944 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 5024 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 4 ms 5128 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 5072 KB Output is correct
4 Correct 4 ms 5072 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 4 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 4 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5024 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 4 ms 5128 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5116 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 4 ms 5112 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 4 ms 5072 KB Output is correct
32 Correct 3 ms 5116 KB Output is correct
33 Correct 4 ms 5000 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 4 ms 5072 KB Output is correct
36 Correct 4 ms 5200 KB Output is correct
37 Correct 4 ms 5200 KB Output is correct
38 Correct 5 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 767 ms 7808 KB Output is correct
2 Correct 965 ms 10568 KB Output is correct
3 Correct 861 ms 10624 KB Output is correct
4 Correct 965 ms 10648 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 767 ms 7808 KB Output is correct
2 Correct 965 ms 10568 KB Output is correct
3 Correct 861 ms 10624 KB Output is correct
4 Correct 965 ms 10648 KB Output is correct
5 Correct 662 ms 7808 KB Output is correct
6 Correct 1004 ms 10644 KB Output is correct
7 Correct 888 ms 10604 KB Output is correct
8 Correct 828 ms 10636 KB Output is correct
9 Correct 498 ms 5200 KB Output is correct
10 Correct 920 ms 5328 KB Output is correct
11 Correct 903 ms 5396 KB Output is correct
12 Correct 749 ms 5328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 4 ms 4944 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 5024 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 4 ms 5128 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 767 ms 7808 KB Output is correct
14 Correct 965 ms 10568 KB Output is correct
15 Correct 861 ms 10624 KB Output is correct
16 Correct 965 ms 10648 KB Output is correct
17 Correct 662 ms 7808 KB Output is correct
18 Correct 1004 ms 10644 KB Output is correct
19 Correct 888 ms 10604 KB Output is correct
20 Correct 828 ms 10636 KB Output is correct
21 Correct 498 ms 5200 KB Output is correct
22 Correct 920 ms 5328 KB Output is correct
23 Correct 903 ms 5396 KB Output is correct
24 Correct 749 ms 5328 KB Output is correct
25 Correct 1130 ms 13976 KB Output is correct
26 Correct 998 ms 14216 KB Output is correct
27 Correct 995 ms 14100 KB Output is correct
28 Correct 779 ms 14024 KB Output is correct
29 Correct 844 ms 24960 KB Output is correct
30 Correct 674 ms 24956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 5072 KB Output is correct
4 Correct 4 ms 5072 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 4 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 4 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5024 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 4 ms 5128 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5116 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 4 ms 5112 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 4 ms 5072 KB Output is correct
32 Correct 3 ms 5116 KB Output is correct
33 Correct 4 ms 5000 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 4 ms 5072 KB Output is correct
36 Correct 4 ms 5200 KB Output is correct
37 Correct 4 ms 5200 KB Output is correct
38 Correct 5 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 516 ms 5200 KB Output is correct
44 Correct 882 ms 5328 KB Output is correct
45 Correct 903 ms 5296 KB Output is correct
46 Correct 823 ms 5452 KB Output is correct
47 Correct 758 ms 5456 KB Output is correct
48 Correct 926 ms 5520 KB Output is correct
49 Correct 785 ms 5456 KB Output is correct
50 Correct 965 ms 5456 KB Output is correct
51 Correct 736 ms 5328 KB Output is correct
52 Correct 922 ms 5360 KB Output is correct
53 Correct 792 ms 5712 KB Output is correct
54 Correct 796 ms 5456 KB Output is correct
55 Correct 908 ms 5328 KB Output is correct
56 Correct 908 ms 5328 KB Output is correct
57 Correct 723 ms 5336 KB Output is correct
58 Correct 963 ms 6096 KB Output is correct
59 Correct 630 ms 6096 KB Output is correct
60 Correct 884 ms 6096 KB Output is correct
61 Correct 912 ms 5456 KB Output is correct
62 Correct 943 ms 5200 KB Output is correct
63 Correct 943 ms 5200 KB Output is correct
64 Correct 854 ms 5328 KB Output is correct
65 Correct 393 ms 5200 KB Output is correct
66 Correct 842 ms 5328 KB Output is correct
67 Correct 851 ms 5328 KB Output is correct
68 Correct 726 ms 5328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 5072 KB Output is correct
4 Correct 4 ms 5072 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 4 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 4 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 4 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5024 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 4 ms 5128 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 3 ms 5116 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 4 ms 5112 KB Output is correct
27 Correct 3 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 4 ms 5072 KB Output is correct
32 Correct 3 ms 5116 KB Output is correct
33 Correct 4 ms 5000 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 4 ms 5072 KB Output is correct
36 Correct 4 ms 5200 KB Output is correct
37 Correct 4 ms 5200 KB Output is correct
38 Correct 5 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 767 ms 7808 KB Output is correct
44 Correct 965 ms 10568 KB Output is correct
45 Correct 861 ms 10624 KB Output is correct
46 Correct 965 ms 10648 KB Output is correct
47 Correct 662 ms 7808 KB Output is correct
48 Correct 1004 ms 10644 KB Output is correct
49 Correct 888 ms 10604 KB Output is correct
50 Correct 828 ms 10636 KB Output is correct
51 Correct 498 ms 5200 KB Output is correct
52 Correct 920 ms 5328 KB Output is correct
53 Correct 903 ms 5396 KB Output is correct
54 Correct 749 ms 5328 KB Output is correct
55 Correct 1130 ms 13976 KB Output is correct
56 Correct 998 ms 14216 KB Output is correct
57 Correct 995 ms 14100 KB Output is correct
58 Correct 779 ms 14024 KB Output is correct
59 Correct 844 ms 24960 KB Output is correct
60 Correct 674 ms 24956 KB Output is correct
61 Correct 516 ms 5200 KB Output is correct
62 Correct 882 ms 5328 KB Output is correct
63 Correct 903 ms 5296 KB Output is correct
64 Correct 823 ms 5452 KB Output is correct
65 Correct 758 ms 5456 KB Output is correct
66 Correct 926 ms 5520 KB Output is correct
67 Correct 785 ms 5456 KB Output is correct
68 Correct 965 ms 5456 KB Output is correct
69 Correct 736 ms 5328 KB Output is correct
70 Correct 922 ms 5360 KB Output is correct
71 Correct 792 ms 5712 KB Output is correct
72 Correct 796 ms 5456 KB Output is correct
73 Correct 908 ms 5328 KB Output is correct
74 Correct 908 ms 5328 KB Output is correct
75 Correct 723 ms 5336 KB Output is correct
76 Correct 963 ms 6096 KB Output is correct
77 Correct 630 ms 6096 KB Output is correct
78 Correct 884 ms 6096 KB Output is correct
79 Correct 912 ms 5456 KB Output is correct
80 Correct 943 ms 5200 KB Output is correct
81 Correct 943 ms 5200 KB Output is correct
82 Correct 854 ms 5328 KB Output is correct
83 Correct 393 ms 5200 KB Output is correct
84 Correct 842 ms 5328 KB Output is correct
85 Correct 851 ms 5328 KB Output is correct
86 Correct 726 ms 5328 KB Output is correct
87 Correct 3 ms 4944 KB Output is correct
88 Correct 583 ms 13440 KB Output is correct
89 Correct 912 ms 10832 KB Output is correct
90 Correct 800 ms 10488 KB Output is correct
91 Correct 782 ms 14204 KB Output is correct
92 Correct 1024 ms 14204 KB Output is correct
93 Correct 1070 ms 14208 KB Output is correct
94 Correct 936 ms 14208 KB Output is correct
95 Correct 788 ms 14112 KB Output is correct
96 Correct 1044 ms 10252 KB Output is correct
97 Correct 874 ms 10580 KB Output is correct
98 Correct 787 ms 20248 KB Output is correct
99 Correct 1064 ms 14024 KB Output is correct
100 Correct 1037 ms 12012 KB Output is correct
101 Correct 890 ms 11544 KB Output is correct
102 Correct 1006 ms 10548 KB Output is correct
103 Correct 994 ms 24968 KB Output is correct
104 Correct 900 ms 25448 KB Output is correct
105 Correct 896 ms 25368 KB Output is correct
106 Correct 926 ms 12796 KB Output is correct
107 Correct 1100 ms 11148 KB Output is correct
108 Correct 1040 ms 10900 KB Output is correct
109 Correct 773 ms 10668 KB Output is correct