Submission #653496

# Submission time Handle Problem Language Result Execution time Memory
653496 2022-10-27T02:14:10 Z Lobo Digital Circuit (IOI22_circuit) C++17
100 / 100
1127 ms 44312 KB
#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()

const int maxn = 2e5+10;
const int mod = 1000002022;
int n, m, p[maxn], a[maxn];
vector<int> g[maxn];
int c[maxn], pw2[maxn], prd[maxn];
int tr0[4*maxn],tr1[4*maxn],lz[4*maxn];

void build(int no, int l, int r) {
    if(l == r) {
        tr0[no] = prd[l];
        tr1[no] = 0;
        return;
    }
    int f1=2*no,f2=2*no+1,mid=(l+r)>>1;
    build(f1,l,mid);
    build(f2,mid+1,r);
    tr0[no] = (tr0[f1]+tr0[f2])%mod;
    tr1[no] = (tr1[f1]+tr1[f2])%mod;
}

void flush(int no, int l, int r) {
    if(lz[no] == 0) return;
    swap(tr0[no],tr1[no]);
    if(l != r) {
        int f1=2*no,f2=2*no+1,mid=(l+r)>>1;
        lz[f1]^= 1;
        lz[f2]^= 1;
    }
    lz[no] = 0;
}

void att(int no, int l, int r, int L, int R) {
    flush(no,l,r);
    if(l > R || r < L) return;
    if(l >= L && r <= R) {
        lz[no] = 1;
        flush(no,l,r);
        return;
    }
    int f1=2*no,f2=2*no+1,mid=(l+r)>>1;
    att(f1,l,mid,L,R);
    att(f2,mid+1,r,L,R);
    tr0[no] = (tr0[f1]+tr0[f2])%mod;
    tr1[no] = (tr1[f1]+tr1[f2])%mod;
}

void dfssz(int u) {
    c[u] = g[u].size();
    if(u >= n) c[u] = 1;
    if(u >= n) return;
    for(auto v : g[u]) {
        dfssz(v);
        c[u] = c[u]*c[v]%mod;
    }
}

void dfs(int u) {
    vector<int> pf(g[u].size()+1), sf(g[u].size()+1);

    for(int i = 0; i < (int) g[u].size(); i++) {
        int v = g[u][i];
        pf[i] = c[v];
        if(i!=0) pf[i] = pf[i]*pf[i-1]%mod;
    }
    for(int i = (int) g[u].size()-1; i >= 0; i--) {
        int v = g[u][i];
        sf[i] = c[v];
        if(i != (int) g[u].size()-1) sf[i] = sf[i]*sf[i+1]%mod;
    }

    for(int i = 0; i < (int) g[u].size(); i++) {
        int v = g[u][i];
        prd[v] = prd[u];
        if(i != 0) prd[v] = prd[v]*pf[i-1]%mod;
        if(i != (int) g[u].size()-1) prd[v] = prd[v]*sf[i+1]%mod;
    }

    for(auto v : g[u]) {
        dfs(v);
    }
}

int ans = 0;
void init(int32_t N, int32_t M, vector<int32_t> P, vector<int32_t> A) {
    n = N;
    m = M;
    for(int i = 1; i < n+m; i++) {
        p[i] = P[i];
        g[p[i]].pb(i);
    }
    for(int i = 0; i < m; i++) {
        a[i] = A[i];
    }
    pw2[0] = 1;
    for(int i = 1; i <= n+m; i++) {
        pw2[i] = pw2[i-1]*2%mod;
    }
    dfssz(0);
    prd[0] = 1;
    dfs(0);
    build(1,n,n+m-1);
    for(int i = n; i < n+m; i++) {
        if(a[i-n] == 1) att(1,n,n+m-1,i,i);
    }
    for(int i = n; i < n+m; i++) ans+= a[i-n]*prd[i];
    for(int i = 0; i < n+m; i++) {
        // cout << i << " =  " << c[i] << " " << prd[i] << " " << tr0[1] << " " << tr1[1] << endl;
    }
}
int32_t count_ways(int32_t L, int32_t R) {
    att(1,n,n+m-1,L,R);
    return tr1[1];
    for(int i = L; i <= R; i++) {
        ans-= a[i-n]*prd[i]; ans%=mod; ans+= mod; ans%= mod;
        a[i-n]^=1;
        ans+= a[i-n]*prd[i]; ans%=mod;
    }
    return ans;
}

Compilation message

circuit.cpp: In function 'void flush(long long int, long long int, long long int)':
circuit.cpp:37:31: warning: unused variable 'mid' [-Wunused-variable]
   37 |         int f1=2*no,f2=2*no+1,mid=(l+r)>>1;
      |                               ^~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 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 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 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 3 ms 5200 KB Output is correct
8 Correct 4 ms 5200 KB Output is correct
9 Correct 4 ms 5200 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 5 ms 5228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 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 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 4 ms 5072 KB Output is correct
13 Correct 4 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5200 KB Output is correct
16 Correct 4 ms 5200 KB Output is correct
17 Correct 4 ms 5200 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 5 ms 5228 KB Output is correct
21 Correct 4 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 4 ms 5200 KB Output is correct
25 Correct 4 ms 5200 KB Output is correct
26 Correct 3 ms 5220 KB Output is correct
27 Correct 3 ms 5200 KB Output is correct
28 Correct 4 ms 5212 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 4 ms 5200 KB Output is correct
33 Correct 3 ms 5200 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 4 ms 5328 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 4 ms 5328 KB Output is correct
39 Correct 4 ms 5072 KB Output is correct
40 Correct 4 ms 5072 KB Output is correct
41 Correct 5 ms 5104 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 619 ms 10344 KB Output is correct
2 Correct 902 ms 15748 KB Output is correct
3 Correct 938 ms 15744 KB Output is correct
4 Correct 852 ms 15204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 619 ms 10344 KB Output is correct
2 Correct 902 ms 15748 KB Output is correct
3 Correct 938 ms 15744 KB Output is correct
4 Correct 852 ms 15204 KB Output is correct
5 Correct 860 ms 10448 KB Output is correct
6 Correct 918 ms 15800 KB Output is correct
7 Correct 932 ms 15752 KB Output is correct
8 Correct 1034 ms 15816 KB Output is correct
9 Correct 465 ms 5328 KB Output is correct
10 Correct 830 ms 5712 KB Output is correct
11 Correct 690 ms 5636 KB Output is correct
12 Correct 856 ms 5644 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 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 3 ms 5200 KB Output is correct
8 Correct 4 ms 5200 KB Output is correct
9 Correct 4 ms 5200 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 5 ms 5228 KB Output is correct
13 Correct 619 ms 10344 KB Output is correct
14 Correct 902 ms 15748 KB Output is correct
15 Correct 938 ms 15744 KB Output is correct
16 Correct 852 ms 15204 KB Output is correct
17 Correct 860 ms 10448 KB Output is correct
18 Correct 918 ms 15800 KB Output is correct
19 Correct 932 ms 15752 KB Output is correct
20 Correct 1034 ms 15816 KB Output is correct
21 Correct 465 ms 5328 KB Output is correct
22 Correct 830 ms 5712 KB Output is correct
23 Correct 690 ms 5636 KB Output is correct
24 Correct 856 ms 5644 KB Output is correct
25 Correct 887 ms 22856 KB Output is correct
26 Correct 1097 ms 23188 KB Output is correct
27 Correct 1127 ms 23160 KB Output is correct
28 Correct 763 ms 23156 KB Output is correct
29 Correct 875 ms 43424 KB Output is correct
30 Correct 1062 ms 43520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 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 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 4 ms 5072 KB Output is correct
13 Correct 4 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5200 KB Output is correct
16 Correct 4 ms 5200 KB Output is correct
17 Correct 4 ms 5200 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 5 ms 5228 KB Output is correct
21 Correct 4 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 4 ms 5200 KB Output is correct
25 Correct 4 ms 5200 KB Output is correct
26 Correct 3 ms 5220 KB Output is correct
27 Correct 3 ms 5200 KB Output is correct
28 Correct 4 ms 5212 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 4 ms 5200 KB Output is correct
33 Correct 3 ms 5200 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 4 ms 5328 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 4 ms 5328 KB Output is correct
39 Correct 4 ms 5072 KB Output is correct
40 Correct 4 ms 5072 KB Output is correct
41 Correct 5 ms 5104 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 615 ms 5584 KB Output is correct
44 Correct 833 ms 5584 KB Output is correct
45 Correct 857 ms 5584 KB Output is correct
46 Correct 743 ms 5968 KB Output is correct
47 Correct 1014 ms 6096 KB Output is correct
48 Correct 928 ms 5968 KB Output is correct
49 Correct 881 ms 6096 KB Output is correct
50 Correct 683 ms 6096 KB Output is correct
51 Correct 876 ms 5816 KB Output is correct
52 Correct 687 ms 5840 KB Output is correct
53 Correct 927 ms 6352 KB Output is correct
54 Correct 945 ms 6004 KB Output is correct
55 Correct 877 ms 5928 KB Output is correct
56 Correct 918 ms 5764 KB Output is correct
57 Correct 1055 ms 5764 KB Output is correct
58 Correct 1018 ms 6992 KB Output is correct
59 Correct 858 ms 7120 KB Output is correct
60 Correct 935 ms 7120 KB Output is correct
61 Correct 918 ms 5768 KB Output is correct
62 Correct 948 ms 5584 KB Output is correct
63 Correct 923 ms 5584 KB Output is correct
64 Correct 593 ms 5760 KB Output is correct
65 Correct 354 ms 5328 KB Output is correct
66 Correct 1024 ms 5616 KB Output is correct
67 Correct 649 ms 5712 KB Output is correct
68 Correct 810 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 4944 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 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 4 ms 5072 KB Output is correct
13 Correct 4 ms 5072 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5200 KB Output is correct
16 Correct 4 ms 5200 KB Output is correct
17 Correct 4 ms 5200 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 5 ms 5228 KB Output is correct
21 Correct 4 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 4 ms 5200 KB Output is correct
25 Correct 4 ms 5200 KB Output is correct
26 Correct 3 ms 5220 KB Output is correct
27 Correct 3 ms 5200 KB Output is correct
28 Correct 4 ms 5212 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 4 ms 5200 KB Output is correct
33 Correct 3 ms 5200 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 4 ms 5328 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 4 ms 5328 KB Output is correct
39 Correct 4 ms 5072 KB Output is correct
40 Correct 4 ms 5072 KB Output is correct
41 Correct 5 ms 5104 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 619 ms 10344 KB Output is correct
44 Correct 902 ms 15748 KB Output is correct
45 Correct 938 ms 15744 KB Output is correct
46 Correct 852 ms 15204 KB Output is correct
47 Correct 860 ms 10448 KB Output is correct
48 Correct 918 ms 15800 KB Output is correct
49 Correct 932 ms 15752 KB Output is correct
50 Correct 1034 ms 15816 KB Output is correct
51 Correct 465 ms 5328 KB Output is correct
52 Correct 830 ms 5712 KB Output is correct
53 Correct 690 ms 5636 KB Output is correct
54 Correct 856 ms 5644 KB Output is correct
55 Correct 887 ms 22856 KB Output is correct
56 Correct 1097 ms 23188 KB Output is correct
57 Correct 1127 ms 23160 KB Output is correct
58 Correct 763 ms 23156 KB Output is correct
59 Correct 875 ms 43424 KB Output is correct
60 Correct 1062 ms 43520 KB Output is correct
61 Correct 615 ms 5584 KB Output is correct
62 Correct 833 ms 5584 KB Output is correct
63 Correct 857 ms 5584 KB Output is correct
64 Correct 743 ms 5968 KB Output is correct
65 Correct 1014 ms 6096 KB Output is correct
66 Correct 928 ms 5968 KB Output is correct
67 Correct 881 ms 6096 KB Output is correct
68 Correct 683 ms 6096 KB Output is correct
69 Correct 876 ms 5816 KB Output is correct
70 Correct 687 ms 5840 KB Output is correct
71 Correct 927 ms 6352 KB Output is correct
72 Correct 945 ms 6004 KB Output is correct
73 Correct 877 ms 5928 KB Output is correct
74 Correct 918 ms 5764 KB Output is correct
75 Correct 1055 ms 5764 KB Output is correct
76 Correct 1018 ms 6992 KB Output is correct
77 Correct 858 ms 7120 KB Output is correct
78 Correct 935 ms 7120 KB Output is correct
79 Correct 918 ms 5768 KB Output is correct
80 Correct 948 ms 5584 KB Output is correct
81 Correct 923 ms 5584 KB Output is correct
82 Correct 593 ms 5760 KB Output is correct
83 Correct 354 ms 5328 KB Output is correct
84 Correct 1024 ms 5616 KB Output is correct
85 Correct 649 ms 5712 KB Output is correct
86 Correct 810 ms 5712 KB Output is correct
87 Correct 2 ms 4944 KB Output is correct
88 Correct 689 ms 22132 KB Output is correct
89 Correct 990 ms 16072 KB Output is correct
90 Correct 984 ms 16072 KB Output is correct
91 Correct 939 ms 23756 KB Output is correct
92 Correct 990 ms 23752 KB Output is correct
93 Correct 1124 ms 23216 KB Output is correct
94 Correct 1052 ms 23872 KB Output is correct
95 Correct 1014 ms 23796 KB Output is correct
96 Correct 770 ms 17072 KB Output is correct
97 Correct 971 ms 17052 KB Output is correct
98 Correct 862 ms 32400 KB Output is correct
99 Correct 1041 ms 23164 KB Output is correct
100 Correct 1062 ms 20680 KB Output is correct
101 Correct 898 ms 19172 KB Output is correct
102 Correct 980 ms 17096 KB Output is correct
103 Correct 1070 ms 43520 KB Output is correct
104 Correct 1081 ms 44312 KB Output is correct
105 Correct 992 ms 44276 KB Output is correct
106 Correct 1040 ms 20216 KB Output is correct
107 Correct 1077 ms 17476 KB Output is correct
108 Correct 1090 ms 17864 KB Output is correct
109 Correct 1012 ms 17396 KB Output is correct