답안 #1025175

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1025175 2024-07-16T17:05:46 Z mansur 디지털 회로 (IOI22_circuit) C++17
46 / 100
901 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 = 1e6, 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 14 ms 88408 KB Output is correct
2 Correct 14 ms 88404 KB Output is correct
3 Correct 17 ms 88408 KB Output is correct
4 Correct 13 ms 88408 KB Output is correct
5 Correct 14 ms 88516 KB Output is correct
6 Correct 13 ms 88408 KB Output is correct
7 Correct 13 ms 88520 KB Output is correct
8 Correct 13 ms 88408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 88408 KB Output is correct
2 Correct 14 ms 89580 KB Output is correct
3 Correct 15 ms 92504 KB Output is correct
4 Correct 15 ms 92652 KB Output is correct
5 Correct 16 ms 92504 KB Output is correct
6 Correct 19 ms 96856 KB Output is correct
7 Correct 20 ms 104276 KB Output is correct
8 Correct 20 ms 104280 KB Output is correct
9 Correct 19 ms 104280 KB Output is correct
10 Correct 20 ms 104280 KB Output is correct
11 Correct 20 ms 104280 KB Output is correct
12 Correct 19 ms 99776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 88408 KB Output is correct
2 Correct 14 ms 88404 KB Output is correct
3 Correct 17 ms 88408 KB Output is correct
4 Correct 13 ms 88408 KB Output is correct
5 Correct 14 ms 88516 KB Output is correct
6 Correct 13 ms 88408 KB Output is correct
7 Correct 13 ms 88520 KB Output is correct
8 Correct 13 ms 88408 KB Output is correct
9 Correct 13 ms 88408 KB Output is correct
10 Correct 14 ms 89580 KB Output is correct
11 Correct 15 ms 92504 KB Output is correct
12 Correct 15 ms 92652 KB Output is correct
13 Correct 16 ms 92504 KB Output is correct
14 Correct 19 ms 96856 KB Output is correct
15 Correct 20 ms 104276 KB Output is correct
16 Correct 20 ms 104280 KB Output is correct
17 Correct 19 ms 104280 KB Output is correct
18 Correct 20 ms 104280 KB Output is correct
19 Correct 20 ms 104280 KB Output is correct
20 Correct 19 ms 99776 KB Output is correct
21 Correct 18 ms 99160 KB Output is correct
22 Correct 16 ms 94468 KB Output is correct
23 Correct 16 ms 94040 KB Output is correct
24 Correct 20 ms 104280 KB Output is correct
25 Correct 20 ms 104280 KB Output is correct
26 Correct 23 ms 104248 KB Output is correct
27 Correct 20 ms 104280 KB Output is correct
28 Correct 20 ms 104260 KB Output is correct
29 Correct 16 ms 88408 KB Output is correct
30 Correct 14 ms 88408 KB Output is correct
31 Correct 15 ms 88664 KB Output is correct
32 Correct 21 ms 104280 KB Output is correct
33 Correct 17 ms 96344 KB Output is correct
34 Correct 15 ms 92248 KB Output is correct
35 Correct 14 ms 88408 KB Output is correct
36 Correct 20 ms 104280 KB Output is correct
37 Correct 20 ms 104280 KB Output is correct
38 Correct 21 ms 104280 KB Output is correct
39 Correct 15 ms 93176 KB Output is correct
40 Correct 16 ms 95064 KB Output is correct
41 Correct 15 ms 93528 KB Output is correct
42 Correct 15 ms 89176 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 846 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 846 ms 2097152 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 88408 KB Output is correct
2 Correct 14 ms 89580 KB Output is correct
3 Correct 15 ms 92504 KB Output is correct
4 Correct 15 ms 92652 KB Output is correct
5 Correct 16 ms 92504 KB Output is correct
6 Correct 19 ms 96856 KB Output is correct
7 Correct 20 ms 104276 KB Output is correct
8 Correct 20 ms 104280 KB Output is correct
9 Correct 19 ms 104280 KB Output is correct
10 Correct 20 ms 104280 KB Output is correct
11 Correct 20 ms 104280 KB Output is correct
12 Correct 19 ms 99776 KB Output is correct
13 Runtime error 846 ms 2097152 KB Execution killed with signal 9
14 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 88408 KB Output is correct
2 Correct 14 ms 88404 KB Output is correct
3 Correct 17 ms 88408 KB Output is correct
4 Correct 13 ms 88408 KB Output is correct
5 Correct 14 ms 88516 KB Output is correct
6 Correct 13 ms 88408 KB Output is correct
7 Correct 13 ms 88520 KB Output is correct
8 Correct 13 ms 88408 KB Output is correct
9 Correct 13 ms 88408 KB Output is correct
10 Correct 14 ms 89580 KB Output is correct
11 Correct 15 ms 92504 KB Output is correct
12 Correct 15 ms 92652 KB Output is correct
13 Correct 16 ms 92504 KB Output is correct
14 Correct 19 ms 96856 KB Output is correct
15 Correct 20 ms 104276 KB Output is correct
16 Correct 20 ms 104280 KB Output is correct
17 Correct 19 ms 104280 KB Output is correct
18 Correct 20 ms 104280 KB Output is correct
19 Correct 20 ms 104280 KB Output is correct
20 Correct 19 ms 99776 KB Output is correct
21 Correct 18 ms 99160 KB Output is correct
22 Correct 16 ms 94468 KB Output is correct
23 Correct 16 ms 94040 KB Output is correct
24 Correct 20 ms 104280 KB Output is correct
25 Correct 20 ms 104280 KB Output is correct
26 Correct 23 ms 104248 KB Output is correct
27 Correct 20 ms 104280 KB Output is correct
28 Correct 20 ms 104260 KB Output is correct
29 Correct 16 ms 88408 KB Output is correct
30 Correct 14 ms 88408 KB Output is correct
31 Correct 15 ms 88664 KB Output is correct
32 Correct 21 ms 104280 KB Output is correct
33 Correct 17 ms 96344 KB Output is correct
34 Correct 15 ms 92248 KB Output is correct
35 Correct 14 ms 88408 KB Output is correct
36 Correct 20 ms 104280 KB Output is correct
37 Correct 20 ms 104280 KB Output is correct
38 Correct 21 ms 104280 KB Output is correct
39 Correct 15 ms 93176 KB Output is correct
40 Correct 16 ms 95064 KB Output is correct
41 Correct 15 ms 93528 KB Output is correct
42 Correct 15 ms 89176 KB Output is correct
43 Correct 544 ms 215640 KB Output is correct
44 Correct 762 ms 249784 KB Output is correct
45 Correct 776 ms 241304 KB Output is correct
46 Correct 816 ms 480408 KB Output is correct
47 Correct 855 ms 480412 KB Output is correct
48 Correct 843 ms 480412 KB Output is correct
49 Correct 847 ms 480412 KB Output is correct
50 Correct 848 ms 480372 KB Output is correct
51 Correct 614 ms 88756 KB Output is correct
52 Correct 664 ms 88804 KB Output is correct
53 Correct 593 ms 89360 KB Output is correct
54 Correct 852 ms 480344 KB Output is correct
55 Correct 782 ms 284388 KB Output is correct
56 Correct 745 ms 186484 KB Output is correct
57 Correct 679 ms 90372 KB Output is correct
58 Correct 901 ms 480720 KB Output is correct
59 Correct 887 ms 480776 KB Output is correct
60 Correct 831 ms 480728 KB Output is correct
61 Correct 717 ms 234436 KB Output is correct
62 Correct 807 ms 205584 KB Output is correct
63 Correct 680 ms 178920 KB Output is correct
64 Correct 728 ms 96452 KB Output is correct
65 Correct 422 ms 154348 KB Output is correct
66 Correct 843 ms 351508 KB Output is correct
67 Correct 850 ms 351500 KB Output is correct
68 Correct 803 ms 351484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 88408 KB Output is correct
2 Correct 14 ms 88404 KB Output is correct
3 Correct 17 ms 88408 KB Output is correct
4 Correct 13 ms 88408 KB Output is correct
5 Correct 14 ms 88516 KB Output is correct
6 Correct 13 ms 88408 KB Output is correct
7 Correct 13 ms 88520 KB Output is correct
8 Correct 13 ms 88408 KB Output is correct
9 Correct 13 ms 88408 KB Output is correct
10 Correct 14 ms 89580 KB Output is correct
11 Correct 15 ms 92504 KB Output is correct
12 Correct 15 ms 92652 KB Output is correct
13 Correct 16 ms 92504 KB Output is correct
14 Correct 19 ms 96856 KB Output is correct
15 Correct 20 ms 104276 KB Output is correct
16 Correct 20 ms 104280 KB Output is correct
17 Correct 19 ms 104280 KB Output is correct
18 Correct 20 ms 104280 KB Output is correct
19 Correct 20 ms 104280 KB Output is correct
20 Correct 19 ms 99776 KB Output is correct
21 Correct 18 ms 99160 KB Output is correct
22 Correct 16 ms 94468 KB Output is correct
23 Correct 16 ms 94040 KB Output is correct
24 Correct 20 ms 104280 KB Output is correct
25 Correct 20 ms 104280 KB Output is correct
26 Correct 23 ms 104248 KB Output is correct
27 Correct 20 ms 104280 KB Output is correct
28 Correct 20 ms 104260 KB Output is correct
29 Correct 16 ms 88408 KB Output is correct
30 Correct 14 ms 88408 KB Output is correct
31 Correct 15 ms 88664 KB Output is correct
32 Correct 21 ms 104280 KB Output is correct
33 Correct 17 ms 96344 KB Output is correct
34 Correct 15 ms 92248 KB Output is correct
35 Correct 14 ms 88408 KB Output is correct
36 Correct 20 ms 104280 KB Output is correct
37 Correct 20 ms 104280 KB Output is correct
38 Correct 21 ms 104280 KB Output is correct
39 Correct 15 ms 93176 KB Output is correct
40 Correct 16 ms 95064 KB Output is correct
41 Correct 15 ms 93528 KB Output is correct
42 Correct 15 ms 89176 KB Output is correct
43 Runtime error 846 ms 2097152 KB Execution killed with signal 9
44 Halted 0 ms 0 KB -