Submission #632419

# Submission time Handle Problem Language Result Execution time Memory
632419 2022-08-20T02:54:47 Z skittles1412 Digital Circuit (IOI22_circuit) C++17
46 / 100
3000 ms 10844 KB
#include "bits/extc++.h"

using namespace std;

template <typename T>
void dbgh(const T& t) {
    cerr << t << endl;
}

template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
    cerr << t << " | ";
    dbgh(u...);
}

#ifdef DEBUG
#define dbg(...)                                           \
    cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
         << ": ";                                          \
    dbgh(__VA_ARGS__)
#else
#define cerr   \
    if (false) \
    cerr
#define dbg(...)
#endif

#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())

const int maxn = 2e5 + 5;
const long mod = 1e9 + 2022;

int n;
vector<int> arr, graph[maxn];
long ways[maxn], contrib[maxn];

void pdfs(int u) {
    ways[u] = 1;
    for (auto& v : graph[u]) {
        pdfs(v);
        ways[u] = (ways[u] * ways[v]) % mod;
    }
    if (sz(graph[u])) {
        ways[u] = (ways[u] * sz(graph[u])) % mod;
    }
    dbg(u, ways[u]);
}

void dfs(int u, long x = 1) {
    int m = sz(graph[u]);
    if (!m) {
        dbg(u, x);
        contrib[u] = x;
        return;
    }
    long psum[m + 1], ssum[m + 1];
    psum[0] = ssum[m] = 1;
    for (int i = 0; i < m; i++) {
        psum[i + 1] = (psum[i] * ways[graph[u][i]]) % mod;
    }
    for (int i = m - 1; i >= 0; i--) {
        ssum[i] = (ssum[i + 1] * ways[graph[u][i]]) % mod;
    }
    for (int i = 0; i < m; i++) {
        dfs(graph[u][i], x * psum[i] % mod * ssum[i + 1] % mod);
    }
}

void init(int _n, int m, vector<int> p, vector<int> _arr) {
    n = _n;
    arr = _arr;
    for (int i = 1; i < n + m; i++) {
        graph[p[i]].push_back(i);
    }
    pdfs(0);
    dfs(0);
    copy(contrib + n, contrib + n + m, contrib);
}

int count_ways(int l, int r) {
    l -= n;
    r -= n;
    for (int i = l; i <= r; i++) {
        arr[i] ^= 1;
    }
    long ans = 0;
    for (int i = 0; i < sz(arr); i++) {
        ans += arr[i] * contrib[i];
    }
    return int(ans % mod);
}
# 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 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 4944 KB Output is correct
7 Correct 4 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 2 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5008 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 4 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 4944 KB Output is correct
3 Correct 3 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 4944 KB Output is correct
7 Correct 4 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 2 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5008 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 4 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 4944 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 2 ms 4944 KB Output is correct
30 Correct 3 ms 5040 KB Output is correct
31 Correct 4 ms 5072 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 4944 KB Output is correct
34 Correct 3 ms 4944 KB Output is correct
35 Correct 3 ms 4944 KB Output is correct
36 Correct 3 ms 5120 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 4944 KB Output is correct
41 Correct 3 ms 4944 KB Output is correct
42 Correct 3 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2455 ms 7936 KB Output is correct
2 Execution timed out 3084 ms 10844 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2455 ms 7936 KB Output is correct
2 Execution timed out 3084 ms 10844 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 2 ms 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5008 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 2455 ms 7936 KB Output is correct
14 Execution timed out 3084 ms 10844 KB Time limit exceeded
15 Halted 0 ms 0 KB -
# 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 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 4944 KB Output is correct
7 Correct 4 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 2 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5008 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 4 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 4944 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 2 ms 4944 KB Output is correct
30 Correct 3 ms 5040 KB Output is correct
31 Correct 4 ms 5072 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 4944 KB Output is correct
34 Correct 3 ms 4944 KB Output is correct
35 Correct 3 ms 4944 KB Output is correct
36 Correct 3 ms 5120 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 4944 KB Output is correct
41 Correct 3 ms 4944 KB Output is correct
42 Correct 3 ms 4944 KB Output is correct
43 Correct 827 ms 5200 KB Output is correct
44 Correct 1098 ms 5200 KB Output is correct
45 Correct 1106 ms 5200 KB Output is correct
46 Correct 1259 ms 5456 KB Output is correct
47 Correct 1288 ms 5420 KB Output is correct
48 Correct 1278 ms 5456 KB Output is correct
49 Correct 1475 ms 5456 KB Output is correct
50 Correct 1399 ms 5456 KB Output is correct
51 Correct 1187 ms 5200 KB Output is correct
52 Correct 1317 ms 5200 KB Output is correct
53 Correct 821 ms 5888 KB Output is correct
54 Correct 1123 ms 5436 KB Output is correct
55 Correct 1356 ms 5200 KB Output is correct
56 Correct 1336 ms 5200 KB Output is correct
57 Correct 1282 ms 5200 KB Output is correct
58 Correct 1267 ms 6224 KB Output is correct
59 Correct 1183 ms 6192 KB Output is correct
60 Correct 1223 ms 6184 KB Output is correct
61 Correct 1014 ms 5456 KB Output is correct
62 Correct 1276 ms 5200 KB Output is correct
63 Correct 1121 ms 5200 KB Output is correct
64 Correct 1351 ms 5200 KB Output is correct
65 Correct 594 ms 5072 KB Output is correct
66 Correct 1177 ms 5248 KB Output is correct
67 Correct 1256 ms 5248 KB Output is correct
68 Correct 1336 ms 5328 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 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 4944 KB Output is correct
7 Correct 4 ms 4944 KB Output is correct
8 Correct 3 ms 4944 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 2 ms 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5008 KB Output is correct
16 Correct 3 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 4 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 4944 KB Output is correct
23 Correct 3 ms 4944 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 3 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 3 ms 5072 KB Output is correct
29 Correct 2 ms 4944 KB Output is correct
30 Correct 3 ms 5040 KB Output is correct
31 Correct 4 ms 5072 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 4944 KB Output is correct
34 Correct 3 ms 4944 KB Output is correct
35 Correct 3 ms 4944 KB Output is correct
36 Correct 3 ms 5120 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 3 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 4944 KB Output is correct
41 Correct 3 ms 4944 KB Output is correct
42 Correct 3 ms 4944 KB Output is correct
43 Correct 2455 ms 7936 KB Output is correct
44 Execution timed out 3084 ms 10844 KB Time limit exceeded
45 Halted 0 ms 0 KB -