답안 #1025171

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025171 2024-07-16T17:01:05 Z vjudge1 디지털 회로 (IOI22_circuit) C++17
46 / 100
883 ms 2097152 KB
#include "circuit.h"
#include <bits/stdc++.h>

using namespace std;

#define rall(s) s.rbegin(), s.rend()
#define all(s) s.begin(), s.end()
#define sz(s) (int) s.size()
#define s second 
#define f first 

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int N = 5e5, mod = 1000002022;

int n, m, is = 1;
vector<int> g[N], a(N);

vector<ll> pr[N], sf[N], val(N);

void calc(int u) {
    for (int to: g[u]) {
        calc(to);
    }
    int M = sz(g[u]);
    if (!M) {
        val[u] = 1;
        return;
    }
    pr[u].resize(m);
    sf[u].resize(m);
    for (int i = 0; i < M; i++) {
        if (i) pr[u][i] = pr[u][i - 1];
        else pr[u][i] = 1;
        pr[u][i] = (pr[u][i] * val[g[u][i]]) % mod;
    }
    for (int i = M - 1; i >= 0; i--) {
        if (i < M - 1) sf[u][i] = sf[u][i + 1];
        else sf[u][i] = 1;
        sf[u][i] = (sf[u][i] * val[g[u][i]]) % mod; 
    }
    val[u] = (pr[u][M - 1] * M) % mod;
}

ll vl[N];

void dfs(int u, int x) {
    int M = sz(g[u]);
    if (!M) {
        vl[u - n] = x;
        return;
    }
    for (int i = 0; i < M; i++) {
        dfs(g[u][i], (((x * (i ? pr[u][i - 1] : 1ll)) % mod) * (i < M - 1 ? sf[u][i + 1] : 1ll)) % mod);
    }
}

pll t[4 * N];
int swp[4 * N];

void bld(int u = 1, int tl = 0, int tr = m - 1) {
    if (tl == tr) {
        if (a[tl]) t[u].f = vl[tl];
        else t[u].s = vl[tl];
        return;
    }
    int mid = (tl + tr) / 2;
    bld(u * 2, tl, mid);
    bld(u * 2 + 1, mid + 1, tr);
    t[u].f = (t[u * 2].f + t[u  * 2 + 1].f) % mod;
    t[u].s = (t[u * 2].s + t[u  * 2 + 1].s) % mod;
}

void push(int u, int tl, int tr) {
    if (!swp[u]) return;
    swap(t[u].f, t[u].s);
    if (tl < tr) {
        swp[u * 2] ^= 1;
        swp[u * 2 + 1] ^= 1;
    }
    swp[u] = 0;
}

void upd(int l, int r, int u = 1, int tl = 0, int tr = m - 1) {
    push(u, tl, tr);
    if (tl > r || tr < l) return;
    if (tl >= l && tr <= r) {
        swp[u] = 1;
        push(u, tl, tr);
        return;
    }
    int mid = (tl + tr) / 2;
    upd(l, r, u * 2, tl, mid);
    upd(l, r, u * 2 + 1, mid + 1, tr);    
    t[u].f = (t[u * 2].f + t[u  * 2 + 1].f) % mod;
    t[u].s = (t[u * 2].s + t[u  * 2 + 1].s) % mod;
}


void init(int nn, int M, vector<int> P, vector<int> A) {
    n = nn, m = M;
    for (int i = 0; i < m; i++) a[i] = A[i];
    for (int i = 1; i < n + m; i++) g[P[i]].push_back(i);
    calc(0), dfs(0, 1), bld();
}

int count_ways(int l, int r) {
    upd(l - n, r - n);
    return t[1].f;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 47700 KB Output is correct
2 Correct 7 ms 47448 KB Output is correct
3 Correct 8 ms 47448 KB Output is correct
4 Correct 8 ms 47448 KB Output is correct
5 Correct 8 ms 47444 KB Output is correct
6 Correct 8 ms 47700 KB Output is correct
7 Correct 8 ms 47448 KB Output is correct
8 Correct 10 ms 47448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 47448 KB Output is correct
2 Correct 11 ms 48472 KB Output is correct
3 Correct 9 ms 51544 KB Output is correct
4 Correct 9 ms 51544 KB Output is correct
5 Correct 12 ms 51544 KB Output is correct
6 Correct 12 ms 55640 KB Output is correct
7 Correct 15 ms 63064 KB Output is correct
8 Correct 16 ms 63064 KB Output is correct
9 Correct 15 ms 63064 KB Output is correct
10 Correct 13 ms 63144 KB Output is correct
11 Correct 14 ms 63064 KB Output is correct
12 Correct 13 ms 58712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 47700 KB Output is correct
2 Correct 7 ms 47448 KB Output is correct
3 Correct 8 ms 47448 KB Output is correct
4 Correct 8 ms 47448 KB Output is correct
5 Correct 8 ms 47444 KB Output is correct
6 Correct 8 ms 47700 KB Output is correct
7 Correct 8 ms 47448 KB Output is correct
8 Correct 10 ms 47448 KB Output is correct
9 Correct 7 ms 47448 KB Output is correct
10 Correct 11 ms 48472 KB Output is correct
11 Correct 9 ms 51544 KB Output is correct
12 Correct 9 ms 51544 KB Output is correct
13 Correct 12 ms 51544 KB Output is correct
14 Correct 12 ms 55640 KB Output is correct
15 Correct 15 ms 63064 KB Output is correct
16 Correct 16 ms 63064 KB Output is correct
17 Correct 15 ms 63064 KB Output is correct
18 Correct 13 ms 63144 KB Output is correct
19 Correct 14 ms 63064 KB Output is correct
20 Correct 13 ms 58712 KB Output is correct
21 Correct 17 ms 57944 KB Output is correct
22 Correct 11 ms 53504 KB Output is correct
23 Correct 11 ms 53080 KB Output is correct
24 Correct 17 ms 63064 KB Output is correct
25 Correct 15 ms 63064 KB Output is correct
26 Correct 15 ms 63064 KB Output is correct
27 Correct 14 ms 63064 KB Output is correct
28 Correct 14 ms 63064 KB Output is correct
29 Correct 9 ms 47448 KB Output is correct
30 Correct 11 ms 47448 KB Output is correct
31 Correct 9 ms 47448 KB Output is correct
32 Correct 13 ms 63092 KB Output is correct
33 Correct 12 ms 55128 KB Output is correct
34 Correct 9 ms 51288 KB Output is correct
35 Correct 10 ms 47448 KB Output is correct
36 Correct 13 ms 63064 KB Output is correct
37 Correct 14 ms 63064 KB Output is correct
38 Correct 18 ms 63228 KB Output is correct
39 Correct 9 ms 52056 KB Output is correct
40 Correct 11 ms 53848 KB Output is correct
41 Correct 9 ms 52312 KB Output is correct
42 Correct 9 ms 48420 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 799 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 799 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 47448 KB Output is correct
2 Correct 11 ms 48472 KB Output is correct
3 Correct 9 ms 51544 KB Output is correct
4 Correct 9 ms 51544 KB Output is correct
5 Correct 12 ms 51544 KB Output is correct
6 Correct 12 ms 55640 KB Output is correct
7 Correct 15 ms 63064 KB Output is correct
8 Correct 16 ms 63064 KB Output is correct
9 Correct 15 ms 63064 KB Output is correct
10 Correct 13 ms 63144 KB Output is correct
11 Correct 14 ms 63064 KB Output is correct
12 Correct 13 ms 58712 KB Output is correct
13 Runtime error 799 ms 2097152 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 47700 KB Output is correct
2 Correct 7 ms 47448 KB Output is correct
3 Correct 8 ms 47448 KB Output is correct
4 Correct 8 ms 47448 KB Output is correct
5 Correct 8 ms 47444 KB Output is correct
6 Correct 8 ms 47700 KB Output is correct
7 Correct 8 ms 47448 KB Output is correct
8 Correct 10 ms 47448 KB Output is correct
9 Correct 7 ms 47448 KB Output is correct
10 Correct 11 ms 48472 KB Output is correct
11 Correct 9 ms 51544 KB Output is correct
12 Correct 9 ms 51544 KB Output is correct
13 Correct 12 ms 51544 KB Output is correct
14 Correct 12 ms 55640 KB Output is correct
15 Correct 15 ms 63064 KB Output is correct
16 Correct 16 ms 63064 KB Output is correct
17 Correct 15 ms 63064 KB Output is correct
18 Correct 13 ms 63144 KB Output is correct
19 Correct 14 ms 63064 KB Output is correct
20 Correct 13 ms 58712 KB Output is correct
21 Correct 17 ms 57944 KB Output is correct
22 Correct 11 ms 53504 KB Output is correct
23 Correct 11 ms 53080 KB Output is correct
24 Correct 17 ms 63064 KB Output is correct
25 Correct 15 ms 63064 KB Output is correct
26 Correct 15 ms 63064 KB Output is correct
27 Correct 14 ms 63064 KB Output is correct
28 Correct 14 ms 63064 KB Output is correct
29 Correct 9 ms 47448 KB Output is correct
30 Correct 11 ms 47448 KB Output is correct
31 Correct 9 ms 47448 KB Output is correct
32 Correct 13 ms 63092 KB Output is correct
33 Correct 12 ms 55128 KB Output is correct
34 Correct 9 ms 51288 KB Output is correct
35 Correct 10 ms 47448 KB Output is correct
36 Correct 13 ms 63064 KB Output is correct
37 Correct 14 ms 63064 KB Output is correct
38 Correct 18 ms 63228 KB Output is correct
39 Correct 9 ms 52056 KB Output is correct
40 Correct 11 ms 53848 KB Output is correct
41 Correct 9 ms 52312 KB Output is correct
42 Correct 9 ms 48420 KB Output is correct
43 Correct 465 ms 174584 KB Output is correct
44 Correct 720 ms 208724 KB Output is correct
45 Correct 739 ms 200244 KB Output is correct
46 Correct 790 ms 441396 KB Output is correct
47 Correct 824 ms 441404 KB Output is correct
48 Correct 852 ms 441404 KB Output is correct
49 Correct 847 ms 441408 KB Output is correct
50 Correct 767 ms 441360 KB Output is correct
51 Correct 609 ms 49752 KB Output is correct
52 Correct 640 ms 49788 KB Output is correct
53 Correct 546 ms 48280 KB Output is correct
54 Correct 787 ms 441324 KB Output is correct
55 Correct 735 ms 245376 KB Output is correct
56 Correct 711 ms 147476 KB Output is correct
57 Correct 640 ms 51380 KB Output is correct
58 Correct 831 ms 441712 KB Output is correct
59 Correct 883 ms 441764 KB Output is correct
60 Correct 806 ms 441724 KB Output is correct
61 Correct 728 ms 193380 KB Output is correct
62 Correct 702 ms 166564 KB Output is correct
63 Correct 694 ms 139908 KB Output is correct
64 Correct 681 ms 57452 KB Output is correct
65 Correct 321 ms 113296 KB Output is correct
66 Correct 733 ms 312500 KB Output is correct
67 Correct 791 ms 312496 KB Output is correct
68 Correct 804 ms 312484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 47700 KB Output is correct
2 Correct 7 ms 47448 KB Output is correct
3 Correct 8 ms 47448 KB Output is correct
4 Correct 8 ms 47448 KB Output is correct
5 Correct 8 ms 47444 KB Output is correct
6 Correct 8 ms 47700 KB Output is correct
7 Correct 8 ms 47448 KB Output is correct
8 Correct 10 ms 47448 KB Output is correct
9 Correct 7 ms 47448 KB Output is correct
10 Correct 11 ms 48472 KB Output is correct
11 Correct 9 ms 51544 KB Output is correct
12 Correct 9 ms 51544 KB Output is correct
13 Correct 12 ms 51544 KB Output is correct
14 Correct 12 ms 55640 KB Output is correct
15 Correct 15 ms 63064 KB Output is correct
16 Correct 16 ms 63064 KB Output is correct
17 Correct 15 ms 63064 KB Output is correct
18 Correct 13 ms 63144 KB Output is correct
19 Correct 14 ms 63064 KB Output is correct
20 Correct 13 ms 58712 KB Output is correct
21 Correct 17 ms 57944 KB Output is correct
22 Correct 11 ms 53504 KB Output is correct
23 Correct 11 ms 53080 KB Output is correct
24 Correct 17 ms 63064 KB Output is correct
25 Correct 15 ms 63064 KB Output is correct
26 Correct 15 ms 63064 KB Output is correct
27 Correct 14 ms 63064 KB Output is correct
28 Correct 14 ms 63064 KB Output is correct
29 Correct 9 ms 47448 KB Output is correct
30 Correct 11 ms 47448 KB Output is correct
31 Correct 9 ms 47448 KB Output is correct
32 Correct 13 ms 63092 KB Output is correct
33 Correct 12 ms 55128 KB Output is correct
34 Correct 9 ms 51288 KB Output is correct
35 Correct 10 ms 47448 KB Output is correct
36 Correct 13 ms 63064 KB Output is correct
37 Correct 14 ms 63064 KB Output is correct
38 Correct 18 ms 63228 KB Output is correct
39 Correct 9 ms 52056 KB Output is correct
40 Correct 11 ms 53848 KB Output is correct
41 Correct 9 ms 52312 KB Output is correct
42 Correct 9 ms 48420 KB Output is correct
43 Runtime error 799 ms 2097152 KB Execution killed with signal 9
44 Halted 0 ms 0 KB -