Submission #767423

# Submission time Handle Problem Language Result Execution time Memory
767423 2023-06-26T18:23:26 Z t6twotwo Digital Circuit (IOI22_circuit) C++17
34 / 100
865 ms 5024 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int mod = 1000002022;
int add(int x, int y) {
    int z = x + y;
    if (z >= mod) {
        z -= mod;
    }
    return z;
}
int sub(int x, int y) {
    int z = x - y;
    if (z < 0) {
        z += mod;
    }
    return z;
}
int mul(int x, int y) {
    return (ll)x * y % mod;
}
int N, M;
vector<int> P, A, tot, dp, lazy;
void apply(int p, int v) {
    if (v) {
        dp[p] = sub(tot[p], dp[p]);
    }
    lazy[p] ^= v;
}
void push(int p) {
    apply(p * 2 + 1, lazy[p]);
    apply(p * 2 + 2, lazy[p]);
    lazy[p] = 0;
}
void pull(int p) {
    dp[p] = add(mul(dp[p * 2 + 1], tot[p * 2 + 2]), mul(dp[p * 2 + 2], tot[p * 2 + 1]));
}
void init(int n, int m, vector<int> p, vector<int> a) {
    N = n, M = m;
    P = p, A = a;
    if (M == N + 1 && (1 << __lg(M)) == M) {
        tot.resize(N + M);
        dp.resize(N + M);
        lazy.resize(N + M);
        for (int i = 0; i < M; i++) {
            dp[i + N] = A[i];
            tot[i + N] = 1;
        }
        for (int i = N - 1; i >= 0; i--) {
            int x = i * 2 + 1;
            int y = i * 2 + 2;
            pull(i);
            tot[i] = mul(2, mul(tot[x], tot[y]));
        }
    }
}
void update(int p, int l, int r, int L, int R) {
    if (R <= l || r <= L) {
        return;
    }
    if (L <= l && r <= R) {
        apply(p, 1);
        return;
    }
    int m = (l + r + 1) / 2;
    push(p);
    update(p * 2 + 1, l, m, L, R);
    update(p * 2 + 2, m, r, L, R);
    pull(p);
}
int count_ways(int L, int R) {
    if (N <= 1000 && M <= 1000) {
        vector dp(N, vector{1});
        vector<int> on(N + M), off(N + M), tot(N + M, 1);
        for (int i = L; i <= R; i++) {
            A[i - N] ^= 1;
        }
        for (int i = N + M - 1; i >= 0; i--) {
            if (i >= N) {
                on[i] = A[i - N];
                off[i] = tot[i] - on[i];
            } else {
                int sum = 0;
                for (int j = dp[i].size() - 1; j; j--) {
                    sum = add(sum, dp[i][j]);
                    on[i] = add(on[i], sum);
                }
                tot[i] = mul(tot[i], (int)dp[i].size() - 1);
                off[i] = sub(tot[i], on[i]);
            }
            if (i) {
                int K = dp[P[i]].size();
                dp[P[i]].resize(K + 1);
                for (int j = K; j; j--) {
                    dp[P[i]][j] = add(mul(dp[P[i]][j], off[i]), mul(dp[P[i]][j - 1], on[i]));
                }
                dp[P[i]][0] = mul(dp[P[i]][0], off[i]);
                tot[P[i]] = mul(tot[P[i]], tot[i]);
            }
        }
        return on[0];
    }
    update(0, 0, M, L - N, R - N + 1);
    return dp[0];
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 10 ms 208 KB Output is correct
4 Correct 10 ms 208 KB Output is correct
5 Correct 10 ms 208 KB Output is correct
6 Correct 10 ms 208 KB Output is correct
7 Correct 10 ms 332 KB Output is correct
8 Correct 10 ms 328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 10 ms 208 KB Output is correct
4 Correct 10 ms 208 KB Output is correct
5 Correct 10 ms 208 KB Output is correct
6 Correct 10 ms 208 KB Output is correct
7 Correct 10 ms 332 KB Output is correct
8 Correct 10 ms 328 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 400 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 10 ms 332 KB Output is correct
30 Correct 10 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 3 ms 208 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 11 ms 400 KB Output is correct
38 Correct 11 ms 400 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 523 ms 2236 KB Output is correct
2 Correct 567 ms 4136 KB Output is correct
3 Correct 718 ms 4124 KB Output is correct
4 Correct 670 ms 4216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 523 ms 2236 KB Output is correct
2 Correct 567 ms 4136 KB Output is correct
3 Correct 718 ms 4124 KB Output is correct
4 Correct 670 ms 4216 KB Output is correct
5 Correct 629 ms 2256 KB Output is correct
6 Correct 781 ms 4044 KB Output is correct
7 Correct 865 ms 4172 KB Output is correct
8 Correct 752 ms 4120 KB Output is correct
9 Correct 436 ms 400 KB Output is correct
10 Correct 785 ms 512 KB Output is correct
11 Correct 732 ms 516 KB Output is correct
12 Correct 558 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 523 ms 2236 KB Output is correct
14 Correct 567 ms 4136 KB Output is correct
15 Correct 718 ms 4124 KB Output is correct
16 Correct 670 ms 4216 KB Output is correct
17 Correct 629 ms 2256 KB Output is correct
18 Correct 781 ms 4044 KB Output is correct
19 Correct 865 ms 4172 KB Output is correct
20 Correct 752 ms 4120 KB Output is correct
21 Correct 436 ms 400 KB Output is correct
22 Correct 785 ms 512 KB Output is correct
23 Correct 732 ms 516 KB Output is correct
24 Correct 558 ms 512 KB Output is correct
25 Runtime error 21 ms 5024 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 10 ms 208 KB Output is correct
4 Correct 10 ms 208 KB Output is correct
5 Correct 10 ms 208 KB Output is correct
6 Correct 10 ms 208 KB Output is correct
7 Correct 10 ms 332 KB Output is correct
8 Correct 10 ms 328 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 400 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 10 ms 332 KB Output is correct
30 Correct 10 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 3 ms 208 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 11 ms 400 KB Output is correct
38 Correct 11 ms 400 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Runtime error 1 ms 592 KB Execution killed with signal 11
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 10 ms 208 KB Output is correct
4 Correct 10 ms 208 KB Output is correct
5 Correct 10 ms 208 KB Output is correct
6 Correct 10 ms 208 KB Output is correct
7 Correct 10 ms 332 KB Output is correct
8 Correct 10 ms 328 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 336 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 400 KB Output is correct
28 Correct 2 ms 336 KB Output is correct
29 Correct 10 ms 332 KB Output is correct
30 Correct 10 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 3 ms 208 KB Output is correct
36 Correct 1 ms 336 KB Output is correct
37 Correct 11 ms 400 KB Output is correct
38 Correct 11 ms 400 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 523 ms 2236 KB Output is correct
44 Correct 567 ms 4136 KB Output is correct
45 Correct 718 ms 4124 KB Output is correct
46 Correct 670 ms 4216 KB Output is correct
47 Correct 629 ms 2256 KB Output is correct
48 Correct 781 ms 4044 KB Output is correct
49 Correct 865 ms 4172 KB Output is correct
50 Correct 752 ms 4120 KB Output is correct
51 Correct 436 ms 400 KB Output is correct
52 Correct 785 ms 512 KB Output is correct
53 Correct 732 ms 516 KB Output is correct
54 Correct 558 ms 512 KB Output is correct
55 Runtime error 21 ms 5024 KB Execution killed with signal 11
56 Halted 0 ms 0 KB -