답안 #746567

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
746567 2023-05-22T19:33:27 Z Rafi22 디지털 회로 (IOI22_circuit) C++17
100 / 100
1304 ms 43896 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000002022;
int inf=1000000007;
ll infl=1000000000000000007;

const int N=200007,pot=1<<17;

bool is[N];
vector<int>G[N];
ll ile[N];
vector<ll>P[N];
vector<ll>S[N];

ll seg[2][2*pot+7];
bool lzy[2*pot+7];

void ins(int v,int a,int b,int l,int r)
{
    if(a<=l&&b>=r)
    {
        swap(seg[0][v],seg[1][v]);
        lzy[v]^=1;
        return ;
    }
    if(r<a||l>b) return ;
    if(lzy[v])
    {
        swap(seg[0][2*v],seg[1][2*v]);
        swap(seg[0][2*v+1],seg[1][2*v+1]);
        lzy[2*v]^=1;
        lzy[2*v+1]^=1;
        lzy[v]=0;
    }

    ins(2*v,a,b,l,(l+r)/2);
    ins(2*v+1,a,b,(l+r)/2+1,r);
    seg[0][v]=seg[0][2*v]+seg[0][2*v+1];
    seg[1][v]=seg[1][2*v]+seg[1][2*v+1];
}

int n,m;

void dfs(int v)
{
    ile[v]=max(1,sz(G[v]));
    for(auto u:G[v])
    {
        dfs(u);
        ile[v]=ile[v]*ile[u]%mod;
    }
}

void dfs1(int v,ll c)
{
    if(sz(G[v])==0)
    {
        seg[is[v]][v-n+1+pot-1]=c;
        return ;
    }
    P[v].resize(sz(G[v])+2,1);
    for(int i=0;i<sz(G[v]);i++) P[v][i+1]=P[v][i]*ile[G[v][i]]%mod;
    S[v].resize(sz(G[v])+2,1);
    for(int i=sz(G[v])-1;i>=0;i--) S[v][i+1]=S[v][i+2]*ile[G[v][i]]%mod;
    for(int i=0;i<sz(G[v]);i++)
    {
        dfs1(G[v][i],c*P[v][i]%mod*S[v][i+2]%mod);
    }
}

void init(int N,int M,vector<int>p,vector<int>a)
{
    n=N,m=M;
    for(int i=0;i<m;i++) is[i+n]=a[i];
    for(int i=1;i<n+m;i++) G[p[i]].pb(i);
    dfs(0);
    dfs1(0,1);
    for(int i=pot-1;i>0;i--)
    {
        seg[0][i]=(seg[0][2*i]+seg[0][2*i+1])%mod;
        seg[1][i]=(seg[1][2*i]+seg[1][2*i+1])%mod;
    }
}

int count_ways(int l,int r)
{
    ins(1,l-n+1,r-n+1,1,pot);
    return seg[1][1]%mod;
}

/*int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    init(3, 4, {-1, 0, 1, 2, 1, 1, 0}, {1, 0, 1, 0});
    cout<<count_ways(3, 4)<<endl;
    cout<<count_ways(4, 5)<<endl;
    cout<<count_ways(3, 6)<<endl;
    return 0;
}*/

# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16464 KB Output is correct
2 Correct 11 ms 16388 KB Output is correct
3 Correct 12 ms 16464 KB Output is correct
4 Correct 11 ms 16464 KB Output is correct
5 Correct 10 ms 16460 KB Output is correct
6 Correct 11 ms 16464 KB Output is correct
7 Correct 12 ms 16436 KB Output is correct
8 Correct 11 ms 16532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 16464 KB Output is correct
2 Correct 10 ms 16516 KB Output is correct
3 Correct 10 ms 16464 KB Output is correct
4 Correct 10 ms 16500 KB Output is correct
5 Correct 11 ms 16464 KB Output is correct
6 Correct 10 ms 16592 KB Output is correct
7 Correct 10 ms 16592 KB Output is correct
8 Correct 10 ms 16592 KB Output is correct
9 Correct 10 ms 16592 KB Output is correct
10 Correct 11 ms 16720 KB Output is correct
11 Correct 13 ms 16720 KB Output is correct
12 Correct 11 ms 16592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16464 KB Output is correct
2 Correct 11 ms 16388 KB Output is correct
3 Correct 12 ms 16464 KB Output is correct
4 Correct 11 ms 16464 KB Output is correct
5 Correct 10 ms 16460 KB Output is correct
6 Correct 11 ms 16464 KB Output is correct
7 Correct 12 ms 16436 KB Output is correct
8 Correct 11 ms 16532 KB Output is correct
9 Correct 12 ms 16464 KB Output is correct
10 Correct 10 ms 16516 KB Output is correct
11 Correct 10 ms 16464 KB Output is correct
12 Correct 10 ms 16500 KB Output is correct
13 Correct 11 ms 16464 KB Output is correct
14 Correct 10 ms 16592 KB Output is correct
15 Correct 10 ms 16592 KB Output is correct
16 Correct 10 ms 16592 KB Output is correct
17 Correct 10 ms 16592 KB Output is correct
18 Correct 11 ms 16720 KB Output is correct
19 Correct 13 ms 16720 KB Output is correct
20 Correct 11 ms 16592 KB Output is correct
21 Correct 11 ms 16592 KB Output is correct
22 Correct 10 ms 16592 KB Output is correct
23 Correct 9 ms 16568 KB Output is correct
24 Correct 11 ms 16592 KB Output is correct
25 Correct 12 ms 16592 KB Output is correct
26 Correct 11 ms 16616 KB Output is correct
27 Correct 12 ms 16560 KB Output is correct
28 Correct 11 ms 16592 KB Output is correct
29 Correct 10 ms 16464 KB Output is correct
30 Correct 11 ms 16552 KB Output is correct
31 Correct 11 ms 16644 KB Output is correct
32 Correct 11 ms 16648 KB Output is correct
33 Correct 12 ms 16496 KB Output is correct
34 Correct 10 ms 16464 KB Output is correct
35 Correct 10 ms 16508 KB Output is correct
36 Correct 11 ms 16720 KB Output is correct
37 Correct 10 ms 16720 KB Output is correct
38 Correct 10 ms 16720 KB Output is correct
39 Correct 10 ms 16612 KB Output is correct
40 Correct 13 ms 16612 KB Output is correct
41 Correct 11 ms 16464 KB Output is correct
42 Correct 11 ms 16464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 692 ms 22312 KB Output is correct
2 Correct 896 ms 28236 KB Output is correct
3 Correct 627 ms 27792 KB Output is correct
4 Correct 1010 ms 27820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 692 ms 22312 KB Output is correct
2 Correct 896 ms 28236 KB Output is correct
3 Correct 627 ms 27792 KB Output is correct
4 Correct 1010 ms 27820 KB Output is correct
5 Correct 887 ms 22324 KB Output is correct
6 Correct 938 ms 28224 KB Output is correct
7 Correct 1094 ms 28356 KB Output is correct
8 Correct 965 ms 28212 KB Output is correct
9 Correct 499 ms 16848 KB Output is correct
10 Correct 899 ms 17208 KB Output is correct
11 Correct 1035 ms 17204 KB Output is correct
12 Correct 977 ms 17144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 16464 KB Output is correct
2 Correct 10 ms 16516 KB Output is correct
3 Correct 10 ms 16464 KB Output is correct
4 Correct 10 ms 16500 KB Output is correct
5 Correct 11 ms 16464 KB Output is correct
6 Correct 10 ms 16592 KB Output is correct
7 Correct 10 ms 16592 KB Output is correct
8 Correct 10 ms 16592 KB Output is correct
9 Correct 10 ms 16592 KB Output is correct
10 Correct 11 ms 16720 KB Output is correct
11 Correct 13 ms 16720 KB Output is correct
12 Correct 11 ms 16592 KB Output is correct
13 Correct 692 ms 22312 KB Output is correct
14 Correct 896 ms 28236 KB Output is correct
15 Correct 627 ms 27792 KB Output is correct
16 Correct 1010 ms 27820 KB Output is correct
17 Correct 887 ms 22324 KB Output is correct
18 Correct 938 ms 28224 KB Output is correct
19 Correct 1094 ms 28356 KB Output is correct
20 Correct 965 ms 28212 KB Output is correct
21 Correct 499 ms 16848 KB Output is correct
22 Correct 899 ms 17208 KB Output is correct
23 Correct 1035 ms 17204 KB Output is correct
24 Correct 977 ms 17144 KB Output is correct
25 Correct 1183 ms 34228 KB Output is correct
26 Correct 1010 ms 34484 KB Output is correct
27 Correct 1304 ms 34480 KB Output is correct
28 Correct 793 ms 34476 KB Output is correct
29 Correct 892 ms 43868 KB Output is correct
30 Correct 1028 ms 43824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16464 KB Output is correct
2 Correct 11 ms 16388 KB Output is correct
3 Correct 12 ms 16464 KB Output is correct
4 Correct 11 ms 16464 KB Output is correct
5 Correct 10 ms 16460 KB Output is correct
6 Correct 11 ms 16464 KB Output is correct
7 Correct 12 ms 16436 KB Output is correct
8 Correct 11 ms 16532 KB Output is correct
9 Correct 12 ms 16464 KB Output is correct
10 Correct 10 ms 16516 KB Output is correct
11 Correct 10 ms 16464 KB Output is correct
12 Correct 10 ms 16500 KB Output is correct
13 Correct 11 ms 16464 KB Output is correct
14 Correct 10 ms 16592 KB Output is correct
15 Correct 10 ms 16592 KB Output is correct
16 Correct 10 ms 16592 KB Output is correct
17 Correct 10 ms 16592 KB Output is correct
18 Correct 11 ms 16720 KB Output is correct
19 Correct 13 ms 16720 KB Output is correct
20 Correct 11 ms 16592 KB Output is correct
21 Correct 11 ms 16592 KB Output is correct
22 Correct 10 ms 16592 KB Output is correct
23 Correct 9 ms 16568 KB Output is correct
24 Correct 11 ms 16592 KB Output is correct
25 Correct 12 ms 16592 KB Output is correct
26 Correct 11 ms 16616 KB Output is correct
27 Correct 12 ms 16560 KB Output is correct
28 Correct 11 ms 16592 KB Output is correct
29 Correct 10 ms 16464 KB Output is correct
30 Correct 11 ms 16552 KB Output is correct
31 Correct 11 ms 16644 KB Output is correct
32 Correct 11 ms 16648 KB Output is correct
33 Correct 12 ms 16496 KB Output is correct
34 Correct 10 ms 16464 KB Output is correct
35 Correct 10 ms 16508 KB Output is correct
36 Correct 11 ms 16720 KB Output is correct
37 Correct 10 ms 16720 KB Output is correct
38 Correct 10 ms 16720 KB Output is correct
39 Correct 10 ms 16612 KB Output is correct
40 Correct 13 ms 16612 KB Output is correct
41 Correct 11 ms 16464 KB Output is correct
42 Correct 11 ms 16464 KB Output is correct
43 Correct 734 ms 16976 KB Output is correct
44 Correct 972 ms 17152 KB Output is correct
45 Correct 972 ms 16924 KB Output is correct
46 Correct 1026 ms 17328 KB Output is correct
47 Correct 1050 ms 17236 KB Output is correct
48 Correct 930 ms 17328 KB Output is correct
49 Correct 923 ms 17280 KB Output is correct
50 Correct 858 ms 17336 KB Output is correct
51 Correct 912 ms 16812 KB Output is correct
52 Correct 737 ms 16812 KB Output is correct
53 Correct 691 ms 17488 KB Output is correct
54 Correct 914 ms 17400 KB Output is correct
55 Correct 730 ms 16976 KB Output is correct
56 Correct 758 ms 16848 KB Output is correct
57 Correct 795 ms 16720 KB Output is correct
58 Correct 784 ms 17744 KB Output is correct
59 Correct 925 ms 17792 KB Output is correct
60 Correct 820 ms 17728 KB Output is correct
61 Correct 742 ms 17104 KB Output is correct
62 Correct 808 ms 16940 KB Output is correct
63 Correct 746 ms 16864 KB Output is correct
64 Correct 693 ms 16720 KB Output is correct
65 Correct 329 ms 16848 KB Output is correct
66 Correct 718 ms 17180 KB Output is correct
67 Correct 858 ms 17176 KB Output is correct
68 Correct 801 ms 17232 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 16464 KB Output is correct
2 Correct 11 ms 16388 KB Output is correct
3 Correct 12 ms 16464 KB Output is correct
4 Correct 11 ms 16464 KB Output is correct
5 Correct 10 ms 16460 KB Output is correct
6 Correct 11 ms 16464 KB Output is correct
7 Correct 12 ms 16436 KB Output is correct
8 Correct 11 ms 16532 KB Output is correct
9 Correct 12 ms 16464 KB Output is correct
10 Correct 10 ms 16516 KB Output is correct
11 Correct 10 ms 16464 KB Output is correct
12 Correct 10 ms 16500 KB Output is correct
13 Correct 11 ms 16464 KB Output is correct
14 Correct 10 ms 16592 KB Output is correct
15 Correct 10 ms 16592 KB Output is correct
16 Correct 10 ms 16592 KB Output is correct
17 Correct 10 ms 16592 KB Output is correct
18 Correct 11 ms 16720 KB Output is correct
19 Correct 13 ms 16720 KB Output is correct
20 Correct 11 ms 16592 KB Output is correct
21 Correct 11 ms 16592 KB Output is correct
22 Correct 10 ms 16592 KB Output is correct
23 Correct 9 ms 16568 KB Output is correct
24 Correct 11 ms 16592 KB Output is correct
25 Correct 12 ms 16592 KB Output is correct
26 Correct 11 ms 16616 KB Output is correct
27 Correct 12 ms 16560 KB Output is correct
28 Correct 11 ms 16592 KB Output is correct
29 Correct 10 ms 16464 KB Output is correct
30 Correct 11 ms 16552 KB Output is correct
31 Correct 11 ms 16644 KB Output is correct
32 Correct 11 ms 16648 KB Output is correct
33 Correct 12 ms 16496 KB Output is correct
34 Correct 10 ms 16464 KB Output is correct
35 Correct 10 ms 16508 KB Output is correct
36 Correct 11 ms 16720 KB Output is correct
37 Correct 10 ms 16720 KB Output is correct
38 Correct 10 ms 16720 KB Output is correct
39 Correct 10 ms 16612 KB Output is correct
40 Correct 13 ms 16612 KB Output is correct
41 Correct 11 ms 16464 KB Output is correct
42 Correct 11 ms 16464 KB Output is correct
43 Correct 692 ms 22312 KB Output is correct
44 Correct 896 ms 28236 KB Output is correct
45 Correct 627 ms 27792 KB Output is correct
46 Correct 1010 ms 27820 KB Output is correct
47 Correct 887 ms 22324 KB Output is correct
48 Correct 938 ms 28224 KB Output is correct
49 Correct 1094 ms 28356 KB Output is correct
50 Correct 965 ms 28212 KB Output is correct
51 Correct 499 ms 16848 KB Output is correct
52 Correct 899 ms 17208 KB Output is correct
53 Correct 1035 ms 17204 KB Output is correct
54 Correct 977 ms 17144 KB Output is correct
55 Correct 1183 ms 34228 KB Output is correct
56 Correct 1010 ms 34484 KB Output is correct
57 Correct 1304 ms 34480 KB Output is correct
58 Correct 793 ms 34476 KB Output is correct
59 Correct 892 ms 43868 KB Output is correct
60 Correct 1028 ms 43824 KB Output is correct
61 Correct 734 ms 16976 KB Output is correct
62 Correct 972 ms 17152 KB Output is correct
63 Correct 972 ms 16924 KB Output is correct
64 Correct 1026 ms 17328 KB Output is correct
65 Correct 1050 ms 17236 KB Output is correct
66 Correct 930 ms 17328 KB Output is correct
67 Correct 923 ms 17280 KB Output is correct
68 Correct 858 ms 17336 KB Output is correct
69 Correct 912 ms 16812 KB Output is correct
70 Correct 737 ms 16812 KB Output is correct
71 Correct 691 ms 17488 KB Output is correct
72 Correct 914 ms 17400 KB Output is correct
73 Correct 730 ms 16976 KB Output is correct
74 Correct 758 ms 16848 KB Output is correct
75 Correct 795 ms 16720 KB Output is correct
76 Correct 784 ms 17744 KB Output is correct
77 Correct 925 ms 17792 KB Output is correct
78 Correct 820 ms 17728 KB Output is correct
79 Correct 742 ms 17104 KB Output is correct
80 Correct 808 ms 16940 KB Output is correct
81 Correct 746 ms 16864 KB Output is correct
82 Correct 693 ms 16720 KB Output is correct
83 Correct 329 ms 16848 KB Output is correct
84 Correct 718 ms 17180 KB Output is correct
85 Correct 858 ms 17176 KB Output is correct
86 Correct 801 ms 17232 KB Output is correct
87 Correct 11 ms 16464 KB Output is correct
88 Correct 689 ms 31720 KB Output is correct
89 Correct 1041 ms 28572 KB Output is correct
90 Correct 1048 ms 27304 KB Output is correct
91 Correct 965 ms 33508 KB Output is correct
92 Correct 1154 ms 32716 KB Output is correct
93 Correct 1104 ms 32808 KB Output is correct
94 Correct 1037 ms 33608 KB Output is correct
95 Correct 965 ms 33592 KB Output is correct
96 Correct 897 ms 22432 KB Output is correct
97 Correct 1035 ms 22452 KB Output is correct
98 Correct 889 ms 36792 KB Output is correct
99 Correct 880 ms 34456 KB Output is correct
100 Correct 941 ms 27448 KB Output is correct
101 Correct 953 ms 25192 KB Output is correct
102 Correct 848 ms 22580 KB Output is correct
103 Correct 845 ms 43896 KB Output is correct
104 Correct 919 ms 42696 KB Output is correct
105 Correct 1065 ms 42732 KB Output is correct
106 Correct 753 ms 29640 KB Output is correct
107 Correct 942 ms 25128 KB Output is correct
108 Correct 908 ms 24372 KB Output is correct
109 Correct 1029 ms 22600 KB Output is correct