답안 #1069321

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1069321 2024-08-21T19:28:59 Z mariaclara 디지털 회로 (IOI22_circuit) C++17
100 / 100
816 ms 22740 KB
#include "circuit.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int MOD = 1e9 + 2022;
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second

int n, m;
vector<int> val, tot, a, lazy;
vector<vector<int>> filhos;
vector<ll> seg, sum;

ll calc_tot(int x) {
    if(x >= n) return 1;

    tot[x] = sz(filhos[x]);
    for(int viz : filhos[x]) {
        tot[x] = (tot[x] * calc_tot(viz))%MOD;
    }

    return tot[x];
}

void dfs(int x) {
    ll at = 1;

    if(x >= n) return;
    
    for(auto viz : filhos[x]) {
        val[viz] = (val[x] * at)%MOD;
        if(viz < n) at = (at*tot[viz])%MOD;
    }

    reverse(all(filhos[x]));
    at = 1;

    for(auto viz : filhos[x]) {
        val[viz] = (val[viz] * at)%MOD;
        if(viz < n) at = (at*tot[viz])%MOD;
    }

    for(auto viz : filhos[x]) dfs(viz);
}

void build(int node, int l, int r) {
    if(l == r) {
        seg[node] = val[l+n] * a[l];
        sum[node] = val[l+n];
        return; 
    }

    int mid = (l+r)/2;
    build(2*node, l, mid);
    build(2*node+1, mid+1, r);
    seg[node] = seg[2*node] + seg[2*node+1];
    sum[node] = sum[2*node] + sum[2*node+1];
}

void prop(int node, bool folha) {
    lazy[node] %= 2;
    if(!lazy[node]) return;

    seg[node] = sum[node] - seg[node];
    lazy[node] = 0;

    if(!folha) {
        lazy[2*node]++;
        lazy[2*node+1]++;
    }
}

void update(int node, int l, int r, int p, int q) {
    prop(node, l == r);

    if(r < p or q < l) return;
    if(p <= l and r <= q) {
        lazy[node] = 1;
        prop(node, l == r);
        return;
    }

    int mid = (l+r)/2;
    update(2*node, l, mid, p, q);
    update(2*node+1, mid+1, r, p, q);
    seg[node] = seg[2*node] + seg[2*node+1];
    sum[node] = sum[2*node] + sum[2*node+1];
}

void init(int N, int M, vector<int> P, vector<int> A) {
    val.resize(N+M);
    tot.resize(N);
    filhos.resize(N);
    a = A;
    n = N;
    m = M;
    seg.resize(4*M);
    sum.resize(4*M);
    lazy.resize(4*M);

    for(int i = 1; i < N+M; i++)
        filhos[P[i]].pb(i);

    calc_tot(0);
    val[0] = 1;
    dfs(0);

    build(1, 0, M-1);
}

int count_ways(int L, int R) {
    update(1, 0, m-1, L-n, R-n);
    return seg[1]%MOD;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 436 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 440 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 568 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 5976 KB Output is correct
2 Correct 604 ms 11600 KB Output is correct
3 Correct 588 ms 11608 KB Output is correct
4 Correct 637 ms 11708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 411 ms 5976 KB Output is correct
2 Correct 604 ms 11600 KB Output is correct
3 Correct 588 ms 11608 KB Output is correct
4 Correct 637 ms 11708 KB Output is correct
5 Correct 487 ms 5976 KB Output is correct
6 Correct 663 ms 11608 KB Output is correct
7 Correct 740 ms 11608 KB Output is correct
8 Correct 652 ms 11608 KB Output is correct
9 Correct 289 ms 600 KB Output is correct
10 Correct 690 ms 1136 KB Output is correct
11 Correct 641 ms 1128 KB Output is correct
12 Correct 668 ms 1136 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 600 KB Output is correct
8 Correct 1 ms 600 KB Output is correct
9 Correct 1 ms 600 KB Output is correct
10 Correct 1 ms 600 KB Output is correct
11 Correct 1 ms 600 KB Output is correct
12 Correct 1 ms 436 KB Output is correct
13 Correct 411 ms 5976 KB Output is correct
14 Correct 604 ms 11600 KB Output is correct
15 Correct 588 ms 11608 KB Output is correct
16 Correct 637 ms 11708 KB Output is correct
17 Correct 487 ms 5976 KB Output is correct
18 Correct 663 ms 11608 KB Output is correct
19 Correct 740 ms 11608 KB Output is correct
20 Correct 652 ms 11608 KB Output is correct
21 Correct 289 ms 600 KB Output is correct
22 Correct 690 ms 1136 KB Output is correct
23 Correct 641 ms 1128 KB Output is correct
24 Correct 668 ms 1136 KB Output is correct
25 Correct 756 ms 17232 KB Output is correct
26 Correct 816 ms 17488 KB Output is correct
27 Correct 754 ms 17488 KB Output is correct
28 Correct 608 ms 17488 KB Output is correct
29 Correct 758 ms 22096 KB Output is correct
30 Correct 711 ms 22096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 436 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 440 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 568 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 408 ms 856 KB Output is correct
44 Correct 656 ms 948 KB Output is correct
45 Correct 687 ms 856 KB Output is correct
46 Correct 642 ms 1296 KB Output is correct
47 Correct 641 ms 1292 KB Output is correct
48 Correct 712 ms 1292 KB Output is correct
49 Correct 638 ms 1292 KB Output is correct
50 Correct 637 ms 1296 KB Output is correct
51 Correct 643 ms 992 KB Output is correct
52 Correct 686 ms 988 KB Output is correct
53 Correct 603 ms 988 KB Output is correct
54 Correct 621 ms 1292 KB Output is correct
55 Correct 625 ms 1112 KB Output is correct
56 Correct 677 ms 1060 KB Output is correct
57 Correct 667 ms 948 KB Output is correct
58 Correct 641 ms 1516 KB Output is correct
59 Correct 662 ms 1576 KB Output is correct
60 Correct 673 ms 1580 KB Output is correct
61 Correct 643 ms 856 KB Output is correct
62 Correct 609 ms 856 KB Output is correct
63 Correct 618 ms 856 KB Output is correct
64 Correct 584 ms 960 KB Output is correct
65 Correct 306 ms 600 KB Output is correct
66 Correct 539 ms 1132 KB Output is correct
67 Correct 600 ms 1136 KB Output is correct
68 Correct 581 ms 1140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 344 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 600 KB Output is correct
17 Correct 1 ms 600 KB Output is correct
18 Correct 1 ms 600 KB Output is correct
19 Correct 1 ms 600 KB Output is correct
20 Correct 1 ms 436 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 1 ms 344 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 1 ms 344 KB Output is correct
25 Correct 1 ms 440 KB Output is correct
26 Correct 1 ms 344 KB Output is correct
27 Correct 1 ms 568 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 1 ms 344 KB Output is correct
30 Correct 1 ms 344 KB Output is correct
31 Correct 1 ms 344 KB Output is correct
32 Correct 1 ms 600 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 344 KB Output is correct
35 Correct 1 ms 344 KB Output is correct
36 Correct 1 ms 600 KB Output is correct
37 Correct 1 ms 600 KB Output is correct
38 Correct 1 ms 600 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 1 ms 344 KB Output is correct
41 Correct 1 ms 340 KB Output is correct
42 Correct 0 ms 344 KB Output is correct
43 Correct 411 ms 5976 KB Output is correct
44 Correct 604 ms 11600 KB Output is correct
45 Correct 588 ms 11608 KB Output is correct
46 Correct 637 ms 11708 KB Output is correct
47 Correct 487 ms 5976 KB Output is correct
48 Correct 663 ms 11608 KB Output is correct
49 Correct 740 ms 11608 KB Output is correct
50 Correct 652 ms 11608 KB Output is correct
51 Correct 289 ms 600 KB Output is correct
52 Correct 690 ms 1136 KB Output is correct
53 Correct 641 ms 1128 KB Output is correct
54 Correct 668 ms 1136 KB Output is correct
55 Correct 756 ms 17232 KB Output is correct
56 Correct 816 ms 17488 KB Output is correct
57 Correct 754 ms 17488 KB Output is correct
58 Correct 608 ms 17488 KB Output is correct
59 Correct 758 ms 22096 KB Output is correct
60 Correct 711 ms 22096 KB Output is correct
61 Correct 408 ms 856 KB Output is correct
62 Correct 656 ms 948 KB Output is correct
63 Correct 687 ms 856 KB Output is correct
64 Correct 642 ms 1296 KB Output is correct
65 Correct 641 ms 1292 KB Output is correct
66 Correct 712 ms 1292 KB Output is correct
67 Correct 638 ms 1292 KB Output is correct
68 Correct 637 ms 1296 KB Output is correct
69 Correct 643 ms 992 KB Output is correct
70 Correct 686 ms 988 KB Output is correct
71 Correct 603 ms 988 KB Output is correct
72 Correct 621 ms 1292 KB Output is correct
73 Correct 625 ms 1112 KB Output is correct
74 Correct 677 ms 1060 KB Output is correct
75 Correct 667 ms 948 KB Output is correct
76 Correct 641 ms 1516 KB Output is correct
77 Correct 662 ms 1576 KB Output is correct
78 Correct 673 ms 1580 KB Output is correct
79 Correct 643 ms 856 KB Output is correct
80 Correct 609 ms 856 KB Output is correct
81 Correct 618 ms 856 KB Output is correct
82 Correct 584 ms 960 KB Output is correct
83 Correct 306 ms 600 KB Output is correct
84 Correct 539 ms 1132 KB Output is correct
85 Correct 600 ms 1136 KB Output is correct
86 Correct 581 ms 1140 KB Output is correct
87 Correct 1 ms 344 KB Output is correct
88 Correct 455 ms 15276 KB Output is correct
89 Correct 722 ms 10832 KB Output is correct
90 Correct 715 ms 10840 KB Output is correct
91 Correct 679 ms 17744 KB Output is correct
92 Correct 710 ms 17772 KB Output is correct
93 Correct 723 ms 17752 KB Output is correct
94 Correct 672 ms 17556 KB Output is correct
95 Correct 675 ms 17740 KB Output is correct
96 Correct 653 ms 11220 KB Output is correct
97 Correct 725 ms 11220 KB Output is correct
98 Correct 616 ms 12120 KB Output is correct
99 Correct 733 ms 17488 KB Output is correct
100 Correct 749 ms 13912 KB Output is correct
101 Correct 730 ms 12880 KB Output is correct
102 Correct 758 ms 11096 KB Output is correct
103 Correct 768 ms 22096 KB Output is correct
104 Correct 756 ms 22740 KB Output is correct
105 Correct 652 ms 22736 KB Output is correct
106 Correct 690 ms 11096 KB Output is correct
107 Correct 741 ms 10072 KB Output is correct
108 Correct 745 ms 10320 KB Output is correct
109 Correct 722 ms 11096 KB Output is correct