Submission #1075124

# Submission time Handle Problem Language Result Execution time Memory
1075124 2024-08-25T18:47:08 Z c2zi6 Digital Circuit (IOI22_circuit) C++17
46 / 100
3000 ms 4696 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "circuit.h"

const ll MOD = 1000002022;

VL contr;
struct SEGTREE {
    int n;
    VL tree1, tree2;
    VI lazy;
    SEGTREE(){}
    SEGTREE(VI val) {
        n = 1;
        while (n < val.size()) n *= 2;
        tree1 = tree2 = VL(2*n);
        lazy = VI(2*n);
        rep(i, val.size()) {
            if (val[i]) tree1[i + n-1] = contr[i];
            else tree2[i + n-1] = contr[i];
        }
        build(0, 0, n-1);
    }
    void build(int N, int L, int R) {
        if (L == R) return;
        int M = (L + R) / 2;
        build(2*N+1, L, M);
        build(2*N+2, M+1, R);
        tree1[N] = (tree1[2*N+1] + tree1[2*N+2]) % MOD;
        tree2[N] = (tree2[2*N+1] + tree2[2*N+2]) % MOD;
    }
    void push(int N) {
        if (lazy[N]%2) swap(tree1[N], tree2[N]);
        if (2*N+2 < 2*n) {
            lazy[2*N+1] += lazy[N];
            lazy[2*N+2] += lazy[N];
        }
        lazy[N] = 0;
    }
    void upd(int N, int L, int R, int l, int r) {
        push(N);
        if (R < l || L > r) return;
        if (l <= L && R <= r) {
            lazy[N]++;
            push(N);
            return;
        }
        int M = (L + R) / 2;
        upd(2*N+1, L, M, l, r);
        upd(2*N+2, M+1, R, l, r);
        tree1[N] = (tree1[2*N+1] + tree1[2*N+2]) % MOD;
        tree2[N] = (tree2[2*N+1] + tree2[2*N+2]) % MOD;
    }
    void upd(int l, int r) {
        upd(0, 0, n-1, l, r);
    }
    ll get() {
        return tree1[0];
    }
} seg;

int n;
VVI gp;
VI val;

void init(int N, int M, VI par, VI A) {
    n = N + M;
    gp = VVI(n);
    rep(u, n) if (u) gp[par[u]].pb(u);
    val = VI(n);
    rep(u, M) val[u+N] = A[u];
    contr = VL(n);
    rep(l, n) if (gp[l].size() == 0) {
        VI vis(n);
        int cur = l;
        while (cur != -1) {
            vis[cur] = true;
            cur = par[cur];
        }
        contr[l] = 1;
        rep(u, n) if (!vis[u]) {
            contr[l] *= max((ll)gp[u].size(), 1ll);
            contr[l] %= MOD;
        }
    }
    seg = SEGTREE(val);
}

int count_ways(int L, int R) {
    seg.upd(L, R);
    return seg.get();
}


Compilation message

circuit.cpp: In constructor 'SEGTREE::SEGTREE(VI)':
circuit.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         while (n < val.size()) n *= 2;
      |                ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 6 ms 492 KB Output is correct
4 Correct 7 ms 492 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Correct 7 ms 488 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 7 ms 600 KB Output is correct
7 Correct 13 ms 600 KB Output is correct
8 Correct 13 ms 600 KB Output is correct
9 Correct 13 ms 564 KB Output is correct
10 Correct 12 ms 596 KB Output is correct
11 Correct 13 ms 560 KB Output is correct
12 Correct 10 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 6 ms 492 KB Output is correct
4 Correct 7 ms 492 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Correct 7 ms 488 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 7 ms 600 KB Output is correct
15 Correct 13 ms 600 KB Output is correct
16 Correct 13 ms 600 KB Output is correct
17 Correct 13 ms 564 KB Output is correct
18 Correct 12 ms 596 KB Output is correct
19 Correct 13 ms 560 KB Output is correct
20 Correct 10 ms 600 KB Output is correct
21 Correct 11 ms 600 KB Output is correct
22 Correct 4 ms 344 KB Output is correct
23 Correct 5 ms 516 KB Output is correct
24 Correct 13 ms 604 KB Output is correct
25 Correct 13 ms 564 KB Output is correct
26 Correct 13 ms 600 KB Output is correct
27 Correct 13 ms 600 KB Output is correct
28 Correct 13 ms 560 KB Output is correct
29 Correct 7 ms 344 KB Output is correct
30 Correct 7 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 13 ms 600 KB Output is correct
33 Correct 10 ms 524 KB Output is correct
34 Correct 8 ms 344 KB Output is correct
35 Correct 6 ms 344 KB Output is correct
36 Correct 12 ms 600 KB Output is correct
37 Correct 9 ms 600 KB Output is correct
38 Correct 10 ms 568 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 7 ms 344 KB Output is correct
41 Correct 7 ms 508 KB Output is correct
42 Correct 6 ms 488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3035 ms 4696 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3035 ms 4696 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 464 KB Output is correct
3 Correct 4 ms 344 KB Output is correct
4 Correct 4 ms 344 KB Output is correct
5 Correct 4 ms 344 KB Output is correct
6 Correct 7 ms 600 KB Output is correct
7 Correct 13 ms 600 KB Output is correct
8 Correct 13 ms 600 KB Output is correct
9 Correct 13 ms 564 KB Output is correct
10 Correct 12 ms 596 KB Output is correct
11 Correct 13 ms 560 KB Output is correct
12 Correct 10 ms 600 KB Output is correct
13 Execution timed out 3035 ms 4696 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 6 ms 492 KB Output is correct
4 Correct 7 ms 492 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Correct 7 ms 488 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 7 ms 600 KB Output is correct
15 Correct 13 ms 600 KB Output is correct
16 Correct 13 ms 600 KB Output is correct
17 Correct 13 ms 564 KB Output is correct
18 Correct 12 ms 596 KB Output is correct
19 Correct 13 ms 560 KB Output is correct
20 Correct 10 ms 600 KB Output is correct
21 Correct 11 ms 600 KB Output is correct
22 Correct 4 ms 344 KB Output is correct
23 Correct 5 ms 516 KB Output is correct
24 Correct 13 ms 604 KB Output is correct
25 Correct 13 ms 564 KB Output is correct
26 Correct 13 ms 600 KB Output is correct
27 Correct 13 ms 600 KB Output is correct
28 Correct 13 ms 560 KB Output is correct
29 Correct 7 ms 344 KB Output is correct
30 Correct 7 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 13 ms 600 KB Output is correct
33 Correct 10 ms 524 KB Output is correct
34 Correct 8 ms 344 KB Output is correct
35 Correct 6 ms 344 KB Output is correct
36 Correct 12 ms 600 KB Output is correct
37 Correct 9 ms 600 KB Output is correct
38 Correct 10 ms 568 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 7 ms 344 KB Output is correct
41 Correct 7 ms 508 KB Output is correct
42 Correct 6 ms 488 KB Output is correct
43 Correct 578 ms 1136 KB Output is correct
44 Correct 753 ms 1204 KB Output is correct
45 Correct 835 ms 1172 KB Output is correct
46 Correct 1022 ms 1748 KB Output is correct
47 Correct 1018 ms 1748 KB Output is correct
48 Correct 1000 ms 1748 KB Output is correct
49 Correct 1004 ms 1744 KB Output is correct
50 Correct 1018 ms 1752 KB Output is correct
51 Correct 839 ms 1068 KB Output is correct
52 Correct 829 ms 1064 KB Output is correct
53 Correct 601 ms 1136 KB Output is correct
54 Correct 960 ms 1736 KB Output is correct
55 Correct 940 ms 1220 KB Output is correct
56 Correct 897 ms 1156 KB Output is correct
57 Correct 839 ms 1048 KB Output is correct
58 Correct 964 ms 1736 KB Output is correct
59 Correct 913 ms 1792 KB Output is correct
60 Correct 897 ms 1796 KB Output is correct
61 Correct 777 ms 1204 KB Output is correct
62 Correct 795 ms 1112 KB Output is correct
63 Correct 787 ms 1072 KB Output is correct
64 Correct 875 ms 1104 KB Output is correct
65 Correct 384 ms 932 KB Output is correct
66 Correct 904 ms 1360 KB Output is correct
67 Correct 898 ms 1292 KB Output is correct
68 Correct 916 ms 1296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 6 ms 492 KB Output is correct
4 Correct 7 ms 492 KB Output is correct
5 Correct 7 ms 344 KB Output is correct
6 Correct 7 ms 488 KB Output is correct
7 Correct 7 ms 344 KB Output is correct
8 Correct 7 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 4 ms 344 KB Output is correct
12 Correct 4 ms 344 KB Output is correct
13 Correct 4 ms 344 KB Output is correct
14 Correct 7 ms 600 KB Output is correct
15 Correct 13 ms 600 KB Output is correct
16 Correct 13 ms 600 KB Output is correct
17 Correct 13 ms 564 KB Output is correct
18 Correct 12 ms 596 KB Output is correct
19 Correct 13 ms 560 KB Output is correct
20 Correct 10 ms 600 KB Output is correct
21 Correct 11 ms 600 KB Output is correct
22 Correct 4 ms 344 KB Output is correct
23 Correct 5 ms 516 KB Output is correct
24 Correct 13 ms 604 KB Output is correct
25 Correct 13 ms 564 KB Output is correct
26 Correct 13 ms 600 KB Output is correct
27 Correct 13 ms 600 KB Output is correct
28 Correct 13 ms 560 KB Output is correct
29 Correct 7 ms 344 KB Output is correct
30 Correct 7 ms 344 KB Output is correct
31 Correct 0 ms 344 KB Output is correct
32 Correct 13 ms 600 KB Output is correct
33 Correct 10 ms 524 KB Output is correct
34 Correct 8 ms 344 KB Output is correct
35 Correct 6 ms 344 KB Output is correct
36 Correct 12 ms 600 KB Output is correct
37 Correct 9 ms 600 KB Output is correct
38 Correct 10 ms 568 KB Output is correct
39 Correct 3 ms 504 KB Output is correct
40 Correct 7 ms 344 KB Output is correct
41 Correct 7 ms 508 KB Output is correct
42 Correct 6 ms 488 KB Output is correct
43 Execution timed out 3035 ms 4696 KB Time limit exceeded
44 Halted 0 ms 0 KB -