답안 #974755

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
974755 2024-05-03T18:32:27 Z LucaIlie 디지털 회로 (IOI22_circuit) C++17
100 / 100
740 ms 42704 KB
#include "circuit.h"
#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 2022;

struct SegTree {
    struct info {
        int sumTot, sumActive;

        info operator + ( info &x ) {
            return { (sumTot + x.sumTot) % MOD, (sumActive + x.sumActive) % MOD };
        }
    };

    int lst, rst;
    vector<info> aint;
    vector<int> lazy;

    void init( int v, int l, int r, int val[] ) {
        lazy[v] = 0;
        if ( l == r ) {
            aint[v] = { val[0], val[0] };
            return;
        }

        int mid = (l + r) / 2;
        init( v * 2 + 1, l, mid, val );
        init( v * 2 + 2, mid + 1, r, val + mid + 1 - l );
        aint[v] = aint[v * 2 + 1] + aint[v * 2 + 2];
    }
    void init( int l, int r, int val[] ) {
        lst = l;
        rst = r;
        aint.resize( 4 * (r - l + 1) );
        lazy.resize( 4 * (r - l + 1) );
        init( 0, lst, rst, val );
    }

    void propag( int v, int l, int r ) {
        if ( !lazy[v] )
            return;

        aint[v].sumActive = (aint[v].sumTot - aint[v].sumActive + MOD) % MOD;
        if ( l != r ) {
            lazy[v * 2 + 1] ^= 1;
            lazy[v * 2 + 2] ^= 1;
        }
        lazy[v] = 0;
    }

    void update( int v, int l, int r, int lu, int ru ) {
        propag( v, l, r );
        if ( l > ru || r < lu )
            return;

        if ( lu <= l && r <= ru ) {
            lazy[v] = 1;
            propag( v, l, r );
            return;
        }

        int mid = (l + r) / 2;
        update( v * 2 + 1, l, mid, lu, ru );
        update( v * 2 + 2, mid + 1, r, lu, ru );
        aint[v] = aint[v * 2 + 1] + aint[v * 2 + 2];
    }

    void update( int l, int r ) {
        update( 0, lst, rst, l, r );
    }

    int queryActive() {
        return aint[0].sumActive;
    }
} aint;

const int MAX_N = 2e5;
int value[MAX_N], dpTot[MAX_N];
vector<int> adj[MAX_N], prefix[MAX_N], suffix[MAX_N];
int n, m;

void dfsDpTot( int u ) {
    for ( int v: adj[u] )
        dfsDpTot( v );

    dpTot[u] = 1;

    if ( adj[u].size() == 0 )
        return;

    for ( int v: adj[u] )
        dpTot[u] = (long long)dpTot[u] * dpTot[v] % MOD;
    dpTot[u] = (long long)dpTot[u] * adj[u].size() % MOD;
}

void dfsCalcValues( int u, int val ) {
    if ( adj[u].size() == 0 ) {
        value[u] = val;
        return;
    }

    prefix[u].resize( adj[u].size() + 1 );
    suffix[u].resize( adj[u].size() + 1 );

    prefix[u][0] = 1;
    for ( int i = 0; i < adj[u].size(); i++ ) {
        int v = adj[u][i];
        prefix[u][i + 1] = (long long)prefix[u][i] * dpTot[v] % MOD;
    }
    suffix[u][adj[u].size()] = 1;
    for ( int i = adj[u].size() - 1; i >= 0; i-- ) {
        int v = adj[u][i];
        suffix[u][i] = (long long)suffix[u][i + 1] * dpTot[v] % MOD;
    }

    for ( int i = 0; i < adj[u].size(); i++ ){
        int v = adj[u][i];
        dfsCalcValues( v, (long long)val * prefix[u][i] % MOD * suffix[u][i + 1] % MOD );
    }
}

void init( int N, int M, vector<int> P, vector<int> A ) {
    n = N + M, m = M;


    for ( int v = 1; v < n; v++ )
        adj[P[v]].push_back( v );

    dfsDpTot( 0 );
    dfsCalcValues( 0, 1 );

    aint.init( n - m, n - 1, value + n - m );
    for ( int v = 0; v < m; v++ ) {
        if ( A[v] == 0 )
            aint.update( v + n - m, v + n - m );
    }
}

int count_ways( int l, int r ) {
    aint.update( l, r );
    return aint.queryActive();
}

Compilation message

circuit.cpp: In function 'void dfsCalcValues(int, int)':
circuit.cpp:108:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  108 |     for ( int i = 0; i < adj[u].size(); i++ ) {
      |                      ~~^~~~~~~~~~~~~~~
circuit.cpp:118:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  118 |     for ( int i = 0; i < adj[u].size(); i++ ){
      |                      ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14936 KB Output is correct
2 Correct 5 ms 14936 KB Output is correct
3 Correct 4 ms 15192 KB Output is correct
4 Correct 6 ms 15056 KB Output is correct
5 Correct 3 ms 14936 KB Output is correct
6 Correct 4 ms 15040 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14936 KB Output is correct
3 Correct 3 ms 14936 KB Output is correct
4 Correct 4 ms 14936 KB Output is correct
5 Correct 3 ms 14936 KB Output is correct
6 Correct 3 ms 14936 KB Output is correct
7 Correct 4 ms 14936 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 4 ms 15008 KB Output is correct
10 Correct 4 ms 15192 KB Output is correct
11 Correct 4 ms 15192 KB Output is correct
12 Correct 3 ms 14932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14936 KB Output is correct
2 Correct 5 ms 14936 KB Output is correct
3 Correct 4 ms 15192 KB Output is correct
4 Correct 6 ms 15056 KB Output is correct
5 Correct 3 ms 14936 KB Output is correct
6 Correct 4 ms 15040 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 3 ms 14936 KB Output is correct
10 Correct 3 ms 14936 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 4 ms 14936 KB Output is correct
13 Correct 3 ms 14936 KB Output is correct
14 Correct 3 ms 14936 KB Output is correct
15 Correct 4 ms 14936 KB Output is correct
16 Correct 4 ms 14936 KB Output is correct
17 Correct 4 ms 15008 KB Output is correct
18 Correct 4 ms 15192 KB Output is correct
19 Correct 4 ms 15192 KB Output is correct
20 Correct 3 ms 14932 KB Output is correct
21 Correct 4 ms 14936 KB Output is correct
22 Correct 4 ms 14936 KB Output is correct
23 Correct 5 ms 15192 KB Output is correct
24 Correct 4 ms 14936 KB Output is correct
25 Correct 4 ms 14936 KB Output is correct
26 Correct 4 ms 14936 KB Output is correct
27 Correct 4 ms 14936 KB Output is correct
28 Correct 4 ms 14936 KB Output is correct
29 Correct 3 ms 14936 KB Output is correct
30 Correct 3 ms 15192 KB Output is correct
31 Correct 3 ms 14936 KB Output is correct
32 Correct 4 ms 14936 KB Output is correct
33 Correct 4 ms 14936 KB Output is correct
34 Correct 3 ms 14936 KB Output is correct
35 Correct 3 ms 14936 KB Output is correct
36 Correct 4 ms 15192 KB Output is correct
37 Correct 4 ms 15192 KB Output is correct
38 Correct 4 ms 15192 KB Output is correct
39 Correct 3 ms 14936 KB Output is correct
40 Correct 4 ms 14936 KB Output is correct
41 Correct 3 ms 14936 KB Output is correct
42 Correct 4 ms 14936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 417 ms 20308 KB Output is correct
2 Correct 595 ms 25944 KB Output is correct
3 Correct 641 ms 25992 KB Output is correct
4 Correct 607 ms 25944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 417 ms 20308 KB Output is correct
2 Correct 595 ms 25944 KB Output is correct
3 Correct 641 ms 25992 KB Output is correct
4 Correct 607 ms 25944 KB Output is correct
5 Correct 511 ms 20312 KB Output is correct
6 Correct 627 ms 25996 KB Output is correct
7 Correct 655 ms 26120 KB Output is correct
8 Correct 582 ms 25972 KB Output is correct
9 Correct 278 ms 15296 KB Output is correct
10 Correct 585 ms 15448 KB Output is correct
11 Correct 545 ms 15448 KB Output is correct
12 Correct 551 ms 15448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14936 KB Output is correct
3 Correct 3 ms 14936 KB Output is correct
4 Correct 4 ms 14936 KB Output is correct
5 Correct 3 ms 14936 KB Output is correct
6 Correct 3 ms 14936 KB Output is correct
7 Correct 4 ms 14936 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 4 ms 15008 KB Output is correct
10 Correct 4 ms 15192 KB Output is correct
11 Correct 4 ms 15192 KB Output is correct
12 Correct 3 ms 14932 KB Output is correct
13 Correct 417 ms 20308 KB Output is correct
14 Correct 595 ms 25944 KB Output is correct
15 Correct 641 ms 25992 KB Output is correct
16 Correct 607 ms 25944 KB Output is correct
17 Correct 511 ms 20312 KB Output is correct
18 Correct 627 ms 25996 KB Output is correct
19 Correct 655 ms 26120 KB Output is correct
20 Correct 582 ms 25972 KB Output is correct
21 Correct 278 ms 15296 KB Output is correct
22 Correct 585 ms 15448 KB Output is correct
23 Correct 545 ms 15448 KB Output is correct
24 Correct 551 ms 15448 KB Output is correct
25 Correct 727 ms 31784 KB Output is correct
26 Correct 728 ms 32004 KB Output is correct
27 Correct 731 ms 32080 KB Output is correct
28 Correct 532 ms 31984 KB Output is correct
29 Correct 696 ms 41316 KB Output is correct
30 Correct 580 ms 41496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14936 KB Output is correct
2 Correct 5 ms 14936 KB Output is correct
3 Correct 4 ms 15192 KB Output is correct
4 Correct 6 ms 15056 KB Output is correct
5 Correct 3 ms 14936 KB Output is correct
6 Correct 4 ms 15040 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 3 ms 14936 KB Output is correct
10 Correct 3 ms 14936 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 4 ms 14936 KB Output is correct
13 Correct 3 ms 14936 KB Output is correct
14 Correct 3 ms 14936 KB Output is correct
15 Correct 4 ms 14936 KB Output is correct
16 Correct 4 ms 14936 KB Output is correct
17 Correct 4 ms 15008 KB Output is correct
18 Correct 4 ms 15192 KB Output is correct
19 Correct 4 ms 15192 KB Output is correct
20 Correct 3 ms 14932 KB Output is correct
21 Correct 4 ms 14936 KB Output is correct
22 Correct 4 ms 14936 KB Output is correct
23 Correct 5 ms 15192 KB Output is correct
24 Correct 4 ms 14936 KB Output is correct
25 Correct 4 ms 14936 KB Output is correct
26 Correct 4 ms 14936 KB Output is correct
27 Correct 4 ms 14936 KB Output is correct
28 Correct 4 ms 14936 KB Output is correct
29 Correct 3 ms 14936 KB Output is correct
30 Correct 3 ms 15192 KB Output is correct
31 Correct 3 ms 14936 KB Output is correct
32 Correct 4 ms 14936 KB Output is correct
33 Correct 4 ms 14936 KB Output is correct
34 Correct 3 ms 14936 KB Output is correct
35 Correct 3 ms 14936 KB Output is correct
36 Correct 4 ms 15192 KB Output is correct
37 Correct 4 ms 15192 KB Output is correct
38 Correct 4 ms 15192 KB Output is correct
39 Correct 3 ms 14936 KB Output is correct
40 Correct 4 ms 14936 KB Output is correct
41 Correct 3 ms 14936 KB Output is correct
42 Correct 4 ms 14936 KB Output is correct
43 Correct 401 ms 15448 KB Output is correct
44 Correct 609 ms 15536 KB Output is correct
45 Correct 572 ms 15492 KB Output is correct
46 Correct 594 ms 15704 KB Output is correct
47 Correct 626 ms 15820 KB Output is correct
48 Correct 599 ms 15816 KB Output is correct
49 Correct 574 ms 15704 KB Output is correct
50 Correct 555 ms 15820 KB Output is correct
51 Correct 539 ms 15372 KB Output is correct
52 Correct 563 ms 15372 KB Output is correct
53 Correct 518 ms 15700 KB Output is correct
54 Correct 562 ms 15808 KB Output is correct
55 Correct 607 ms 15552 KB Output is correct
56 Correct 601 ms 15448 KB Output is correct
57 Correct 570 ms 15440 KB Output is correct
58 Correct 619 ms 16268 KB Output is correct
59 Correct 558 ms 16336 KB Output is correct
60 Correct 565 ms 16344 KB Output is correct
61 Correct 558 ms 15624 KB Output is correct
62 Correct 550 ms 15408 KB Output is correct
63 Correct 572 ms 15360 KB Output is correct
64 Correct 567 ms 15368 KB Output is correct
65 Correct 315 ms 15300 KB Output is correct
66 Correct 607 ms 15448 KB Output is correct
67 Correct 565 ms 15448 KB Output is correct
68 Correct 548 ms 15448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 14936 KB Output is correct
2 Correct 5 ms 14936 KB Output is correct
3 Correct 4 ms 15192 KB Output is correct
4 Correct 6 ms 15056 KB Output is correct
5 Correct 3 ms 14936 KB Output is correct
6 Correct 4 ms 15040 KB Output is correct
7 Correct 3 ms 14936 KB Output is correct
8 Correct 4 ms 14936 KB Output is correct
9 Correct 3 ms 14936 KB Output is correct
10 Correct 3 ms 14936 KB Output is correct
11 Correct 3 ms 14936 KB Output is correct
12 Correct 4 ms 14936 KB Output is correct
13 Correct 3 ms 14936 KB Output is correct
14 Correct 3 ms 14936 KB Output is correct
15 Correct 4 ms 14936 KB Output is correct
16 Correct 4 ms 14936 KB Output is correct
17 Correct 4 ms 15008 KB Output is correct
18 Correct 4 ms 15192 KB Output is correct
19 Correct 4 ms 15192 KB Output is correct
20 Correct 3 ms 14932 KB Output is correct
21 Correct 4 ms 14936 KB Output is correct
22 Correct 4 ms 14936 KB Output is correct
23 Correct 5 ms 15192 KB Output is correct
24 Correct 4 ms 14936 KB Output is correct
25 Correct 4 ms 14936 KB Output is correct
26 Correct 4 ms 14936 KB Output is correct
27 Correct 4 ms 14936 KB Output is correct
28 Correct 4 ms 14936 KB Output is correct
29 Correct 3 ms 14936 KB Output is correct
30 Correct 3 ms 15192 KB Output is correct
31 Correct 3 ms 14936 KB Output is correct
32 Correct 4 ms 14936 KB Output is correct
33 Correct 4 ms 14936 KB Output is correct
34 Correct 3 ms 14936 KB Output is correct
35 Correct 3 ms 14936 KB Output is correct
36 Correct 4 ms 15192 KB Output is correct
37 Correct 4 ms 15192 KB Output is correct
38 Correct 4 ms 15192 KB Output is correct
39 Correct 3 ms 14936 KB Output is correct
40 Correct 4 ms 14936 KB Output is correct
41 Correct 3 ms 14936 KB Output is correct
42 Correct 4 ms 14936 KB Output is correct
43 Correct 417 ms 20308 KB Output is correct
44 Correct 595 ms 25944 KB Output is correct
45 Correct 641 ms 25992 KB Output is correct
46 Correct 607 ms 25944 KB Output is correct
47 Correct 511 ms 20312 KB Output is correct
48 Correct 627 ms 25996 KB Output is correct
49 Correct 655 ms 26120 KB Output is correct
50 Correct 582 ms 25972 KB Output is correct
51 Correct 278 ms 15296 KB Output is correct
52 Correct 585 ms 15448 KB Output is correct
53 Correct 545 ms 15448 KB Output is correct
54 Correct 551 ms 15448 KB Output is correct
55 Correct 727 ms 31784 KB Output is correct
56 Correct 728 ms 32004 KB Output is correct
57 Correct 731 ms 32080 KB Output is correct
58 Correct 532 ms 31984 KB Output is correct
59 Correct 696 ms 41316 KB Output is correct
60 Correct 580 ms 41496 KB Output is correct
61 Correct 401 ms 15448 KB Output is correct
62 Correct 609 ms 15536 KB Output is correct
63 Correct 572 ms 15492 KB Output is correct
64 Correct 594 ms 15704 KB Output is correct
65 Correct 626 ms 15820 KB Output is correct
66 Correct 599 ms 15816 KB Output is correct
67 Correct 574 ms 15704 KB Output is correct
68 Correct 555 ms 15820 KB Output is correct
69 Correct 539 ms 15372 KB Output is correct
70 Correct 563 ms 15372 KB Output is correct
71 Correct 518 ms 15700 KB Output is correct
72 Correct 562 ms 15808 KB Output is correct
73 Correct 607 ms 15552 KB Output is correct
74 Correct 601 ms 15448 KB Output is correct
75 Correct 570 ms 15440 KB Output is correct
76 Correct 619 ms 16268 KB Output is correct
77 Correct 558 ms 16336 KB Output is correct
78 Correct 565 ms 16344 KB Output is correct
79 Correct 558 ms 15624 KB Output is correct
80 Correct 550 ms 15408 KB Output is correct
81 Correct 572 ms 15360 KB Output is correct
82 Correct 567 ms 15368 KB Output is correct
83 Correct 315 ms 15300 KB Output is correct
84 Correct 607 ms 15448 KB Output is correct
85 Correct 565 ms 15448 KB Output is correct
86 Correct 548 ms 15448 KB Output is correct
87 Correct 3 ms 14936 KB Output is correct
88 Correct 465 ms 30336 KB Output is correct
89 Correct 673 ms 26156 KB Output is correct
90 Correct 641 ms 25692 KB Output is correct
91 Correct 650 ms 32336 KB Output is correct
92 Correct 727 ms 32176 KB Output is correct
93 Correct 711 ms 32260 KB Output is correct
94 Correct 727 ms 32336 KB Output is correct
95 Correct 691 ms 32508 KB Output is correct
96 Correct 598 ms 22784 KB Output is correct
97 Correct 635 ms 22736 KB Output is correct
98 Correct 529 ms 34308 KB Output is correct
99 Correct 740 ms 32248 KB Output is correct
100 Correct 681 ms 26692 KB Output is correct
101 Correct 704 ms 24556 KB Output is correct
102 Correct 672 ms 22932 KB Output is correct
103 Correct 722 ms 41292 KB Output is correct
104 Correct 661 ms 42636 KB Output is correct
105 Correct 630 ms 42704 KB Output is correct
106 Correct 636 ms 27620 KB Output is correct
107 Correct 654 ms 23580 KB Output is correct
108 Correct 686 ms 23376 KB Output is correct
109 Correct 653 ms 22932 KB Output is correct