Submission #944814

# Submission time Handle Problem Language Result Execution time Memory
944814 2024-03-13T06:02:30 Z KG07 Digital Circuit (IOI22_circuit) C++17
100 / 100
775 ms 37660 KB
#include "circuit.h"

#include <bits/stdc++.h>
using namespace std;

struct segment_tree{
    int n, m;
    long long tree_size[200002], sum[400004], counting[400004], multiplier[200002];
    bool toggle[400004];
    vector<int> child[100001], A;
    vector<long long> left_product[100001], right_product[100001];
    void init(int N, int M, vector<int> p, vector<int> a){
        n = N;
        m = M;
        A = a;
        tree_size[0] = 1LL;
        for(int i = 1; i < N+M; i++){
            tree_size[i] = 1LL;
            child[p[i]].push_back(i);
            left_product[p[i]].push_back(0LL);
            right_product[p[i]].push_back(0LL);
        }
    }
    void calculate_size(int N){
        if(N >= n)return;
        tree_size[N] = (long long) child[N].size();
        for(int i = 0; i < child[N].size(); i++){
            calculate_size(child[N][i]);
            left_product[N][i] = tree_size[child[N][i]];
            right_product[N][i] = tree_size[child[N][i]];
            tree_size[N] *= tree_size[child[N][i]];
            tree_size[N] %= 1000002022;
        }
        for(int i = 1; i < child[N].size(); i++){
            left_product[N][i] *= left_product[N][i-1];
            left_product[N][i] %= 1000002022;
        }
        for(int i = child[N].size()-1; i; i--){
            right_product[N][i-1] *= right_product[N][i];
            right_product[N][i-1] %= 1000002022;
        }
    }
    void calculate_multiplier(int N, long long M){
        if(N >= n){
            multiplier[N] = M;
            return;
        }
        if(child[N].size() == 1){
            calculate_multiplier(child[N][0], M);
            return;
        }
        for(int i = 0; i < child[N].size(); i++){
            if(!i)calculate_multiplier(child[N][i], (M*right_product[N][1])%1000002022);
            else if(i+1==child[N].size())calculate_multiplier(child[N][i], (M*left_product[N][child[N].size()-2])%1000002022);
            else calculate_multiplier(child[N][i], (M*((right_product[N][i+1]*left_product[N][i-1])%1000002022))%1000002022);
        }
    }
    void create_tree(int N, int l, int r){
        toggle[N] = false;
        if(l == r){
            sum[N] = multiplier[n+r-1];
            if(A[r-1])counting[N] = multiplier[n+r-1];
            else counting[N] = 0LL;
            return;
        }
        create_tree(2*N, l, (l+r)/2);
        create_tree(2*N+1,(l+r)/2+1, r);
        sum[N] = (sum[2*N] + sum[2*N+1]) % 1000002022;
        counting[N] = (counting[2*N] + counting[2*N+1]) % 1000002022;
    }
    void lazy_update(int N){
        if(toggle[N]){
            toggle[N] = false;
            toggle[2*N] = !toggle[2*N];
            toggle[2*N+1] = !toggle[2*N+1];
            counting[2*N] = (sum[2*N]-counting[2*N]+1000002022) % 1000002022;
            counting[2*N+1] = (sum[2*N+1]-counting[2*N+1]+1000002022) % 1000002022;
        }
    }
    void update(int N, int l, int r, int s, int t){
        if(l > t || r < s)return;
        if(l <= s && r >= t){
            toggle[N] = !toggle[N];
            counting[N] = (sum[N]-counting[N]+1000002022) % 1000002022;
            return;
        }
        lazy_update(N);
        update(2*N, l, r, s, (s+t)/2);
        update(2*N+1, l, r, (s+t)/2+1, t);
        counting[N] = (counting[2*N] + counting[2*N+1]) % 1000002022;
    }
} A;

void init(int N, int M, vector<int> p, vector<int> a) {
    A.init(N, M, p, a);
    A.calculate_size(0);
    A.calculate_multiplier(0, 1LL);
    A.create_tree(1, 1, M);
}

int count_ways(int L, int R) {
    A.update(1, L-A.n+1, R-A.n+1, 1, A.m);
    return A.counting[1];
}

Compilation message

circuit.cpp: In member function 'void segment_tree::calculate_size(int)':
circuit.cpp:27:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   27 |         for(int i = 0; i < child[N].size(); i++){
      |                        ~~^~~~~~~~~~~~~~~~~
circuit.cpp:34:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         for(int i = 1; i < child[N].size(); i++){
      |                        ~~^~~~~~~~~~~~~~~~~
circuit.cpp: In member function 'void segment_tree::calculate_multiplier(int, long long int)':
circuit.cpp:52:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(int i = 0; i < child[N].size(); i++){
      |                        ~~^~~~~~~~~~~~~~~~~
circuit.cpp:54:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |             else if(i+1==child[N].size())calculate_multiplier(child[N][i], (M*left_product[N][child[N].size()-2])%1000002022);
      |                     ~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 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 3 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 3 ms 15372 KB Output is correct
8 Correct 3 ms 14936 KB Output is correct
# Verdict Execution time Memory 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 3 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 5 ms 15192 KB Output is correct
8 Correct 3 ms 15192 KB Output is correct
9 Correct 3 ms 15192 KB Output is correct
10 Correct 3 ms 15192 KB Output is correct
11 Correct 3 ms 15052 KB Output is correct
12 Correct 3 ms 14936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 3 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 3 ms 15372 KB Output is correct
8 Correct 3 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 3 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 5 ms 15192 KB Output is correct
16 Correct 3 ms 15192 KB Output is correct
17 Correct 3 ms 15192 KB Output is correct
18 Correct 3 ms 15192 KB Output is correct
19 Correct 3 ms 15052 KB Output is correct
20 Correct 3 ms 14936 KB Output is correct
21 Correct 3 ms 14936 KB Output is correct
22 Correct 3 ms 14936 KB Output is correct
23 Correct 3 ms 14936 KB Output is correct
24 Correct 3 ms 15192 KB Output is correct
25 Correct 3 ms 15192 KB Output is correct
26 Correct 4 ms 15192 KB Output is correct
27 Correct 3 ms 15040 KB Output is correct
28 Correct 4 ms 15192 KB Output is correct
29 Correct 3 ms 14936 KB Output is correct
30 Correct 3 ms 15444 KB Output is correct
31 Correct 3 ms 15192 KB Output is correct
32 Correct 3 ms 15192 KB Output is correct
33 Correct 3 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 3 ms 15192 KB Output is correct
37 Correct 3 ms 15192 KB Output is correct
38 Correct 3 ms 15192 KB Output is correct
39 Correct 4 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 3 ms 15028 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 405 ms 19148 KB Output is correct
2 Correct 614 ms 25036 KB Output is correct
3 Correct 611 ms 25008 KB Output is correct
4 Correct 643 ms 25020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 405 ms 19148 KB Output is correct
2 Correct 614 ms 25036 KB Output is correct
3 Correct 611 ms 25008 KB Output is correct
4 Correct 643 ms 25020 KB Output is correct
5 Correct 492 ms 19136 KB Output is correct
6 Correct 668 ms 25028 KB Output is correct
7 Correct 601 ms 25184 KB Output is correct
8 Correct 615 ms 25036 KB Output is correct
9 Correct 302 ms 15192 KB Output is correct
10 Correct 537 ms 15448 KB Output is correct
11 Correct 591 ms 15448 KB Output is correct
12 Correct 553 ms 15448 KB Output is correct
# Verdict Execution time Memory 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 3 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 5 ms 15192 KB Output is correct
8 Correct 3 ms 15192 KB Output is correct
9 Correct 3 ms 15192 KB Output is correct
10 Correct 3 ms 15192 KB Output is correct
11 Correct 3 ms 15052 KB Output is correct
12 Correct 3 ms 14936 KB Output is correct
13 Correct 405 ms 19148 KB Output is correct
14 Correct 614 ms 25036 KB Output is correct
15 Correct 611 ms 25008 KB Output is correct
16 Correct 643 ms 25020 KB Output is correct
17 Correct 492 ms 19136 KB Output is correct
18 Correct 668 ms 25028 KB Output is correct
19 Correct 601 ms 25184 KB Output is correct
20 Correct 615 ms 25036 KB Output is correct
21 Correct 302 ms 15192 KB Output is correct
22 Correct 537 ms 15448 KB Output is correct
23 Correct 591 ms 15448 KB Output is correct
24 Correct 553 ms 15448 KB Output is correct
25 Correct 671 ms 29136 KB Output is correct
26 Correct 708 ms 29540 KB Output is correct
27 Correct 775 ms 29380 KB Output is correct
28 Correct 561 ms 29364 KB Output is correct
29 Correct 648 ms 35504 KB Output is correct
30 Correct 663 ms 35512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 3 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 3 ms 15372 KB Output is correct
8 Correct 3 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 3 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 5 ms 15192 KB Output is correct
16 Correct 3 ms 15192 KB Output is correct
17 Correct 3 ms 15192 KB Output is correct
18 Correct 3 ms 15192 KB Output is correct
19 Correct 3 ms 15052 KB Output is correct
20 Correct 3 ms 14936 KB Output is correct
21 Correct 3 ms 14936 KB Output is correct
22 Correct 3 ms 14936 KB Output is correct
23 Correct 3 ms 14936 KB Output is correct
24 Correct 3 ms 15192 KB Output is correct
25 Correct 3 ms 15192 KB Output is correct
26 Correct 4 ms 15192 KB Output is correct
27 Correct 3 ms 15040 KB Output is correct
28 Correct 4 ms 15192 KB Output is correct
29 Correct 3 ms 14936 KB Output is correct
30 Correct 3 ms 15444 KB Output is correct
31 Correct 3 ms 15192 KB Output is correct
32 Correct 3 ms 15192 KB Output is correct
33 Correct 3 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 3 ms 15192 KB Output is correct
37 Correct 3 ms 15192 KB Output is correct
38 Correct 3 ms 15192 KB Output is correct
39 Correct 4 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 3 ms 15028 KB Output is correct
43 Correct 401 ms 15448 KB Output is correct
44 Correct 586 ms 15448 KB Output is correct
45 Correct 602 ms 15604 KB Output is correct
46 Correct 564 ms 15704 KB Output is correct
47 Correct 594 ms 15704 KB Output is correct
48 Correct 567 ms 15620 KB Output is correct
49 Correct 583 ms 15704 KB Output is correct
50 Correct 576 ms 15704 KB Output is correct
51 Correct 553 ms 15444 KB Output is correct
52 Correct 561 ms 15420 KB Output is correct
53 Correct 508 ms 15704 KB Output is correct
54 Correct 584 ms 15704 KB Output is correct
55 Correct 582 ms 15448 KB Output is correct
56 Correct 582 ms 15448 KB Output is correct
57 Correct 564 ms 15324 KB Output is correct
58 Correct 561 ms 15972 KB Output is correct
59 Correct 586 ms 16468 KB Output is correct
60 Correct 554 ms 16300 KB Output is correct
61 Correct 582 ms 15448 KB Output is correct
62 Correct 535 ms 15448 KB Output is correct
63 Correct 553 ms 15192 KB Output is correct
64 Correct 582 ms 15444 KB Output is correct
65 Correct 288 ms 15192 KB Output is correct
66 Correct 524 ms 15448 KB Output is correct
67 Correct 550 ms 15448 KB Output is correct
68 Correct 547 ms 15444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 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 3 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 3 ms 15372 KB Output is correct
8 Correct 3 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 3 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 5 ms 15192 KB Output is correct
16 Correct 3 ms 15192 KB Output is correct
17 Correct 3 ms 15192 KB Output is correct
18 Correct 3 ms 15192 KB Output is correct
19 Correct 3 ms 15052 KB Output is correct
20 Correct 3 ms 14936 KB Output is correct
21 Correct 3 ms 14936 KB Output is correct
22 Correct 3 ms 14936 KB Output is correct
23 Correct 3 ms 14936 KB Output is correct
24 Correct 3 ms 15192 KB Output is correct
25 Correct 3 ms 15192 KB Output is correct
26 Correct 4 ms 15192 KB Output is correct
27 Correct 3 ms 15040 KB Output is correct
28 Correct 4 ms 15192 KB Output is correct
29 Correct 3 ms 14936 KB Output is correct
30 Correct 3 ms 15444 KB Output is correct
31 Correct 3 ms 15192 KB Output is correct
32 Correct 3 ms 15192 KB Output is correct
33 Correct 3 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 3 ms 15192 KB Output is correct
37 Correct 3 ms 15192 KB Output is correct
38 Correct 3 ms 15192 KB Output is correct
39 Correct 4 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 3 ms 15028 KB Output is correct
43 Correct 405 ms 19148 KB Output is correct
44 Correct 614 ms 25036 KB Output is correct
45 Correct 611 ms 25008 KB Output is correct
46 Correct 643 ms 25020 KB Output is correct
47 Correct 492 ms 19136 KB Output is correct
48 Correct 668 ms 25028 KB Output is correct
49 Correct 601 ms 25184 KB Output is correct
50 Correct 615 ms 25036 KB Output is correct
51 Correct 302 ms 15192 KB Output is correct
52 Correct 537 ms 15448 KB Output is correct
53 Correct 591 ms 15448 KB Output is correct
54 Correct 553 ms 15448 KB Output is correct
55 Correct 671 ms 29136 KB Output is correct
56 Correct 708 ms 29540 KB Output is correct
57 Correct 775 ms 29380 KB Output is correct
58 Correct 561 ms 29364 KB Output is correct
59 Correct 648 ms 35504 KB Output is correct
60 Correct 663 ms 35512 KB Output is correct
61 Correct 401 ms 15448 KB Output is correct
62 Correct 586 ms 15448 KB Output is correct
63 Correct 602 ms 15604 KB Output is correct
64 Correct 564 ms 15704 KB Output is correct
65 Correct 594 ms 15704 KB Output is correct
66 Correct 567 ms 15620 KB Output is correct
67 Correct 583 ms 15704 KB Output is correct
68 Correct 576 ms 15704 KB Output is correct
69 Correct 553 ms 15444 KB Output is correct
70 Correct 561 ms 15420 KB Output is correct
71 Correct 508 ms 15704 KB Output is correct
72 Correct 584 ms 15704 KB Output is correct
73 Correct 582 ms 15448 KB Output is correct
74 Correct 582 ms 15448 KB Output is correct
75 Correct 564 ms 15324 KB Output is correct
76 Correct 561 ms 15972 KB Output is correct
77 Correct 586 ms 16468 KB Output is correct
78 Correct 554 ms 16300 KB Output is correct
79 Correct 582 ms 15448 KB Output is correct
80 Correct 535 ms 15448 KB Output is correct
81 Correct 553 ms 15192 KB Output is correct
82 Correct 582 ms 15444 KB Output is correct
83 Correct 288 ms 15192 KB Output is correct
84 Correct 524 ms 15448 KB Output is correct
85 Correct 550 ms 15448 KB Output is correct
86 Correct 547 ms 15444 KB Output is correct
87 Correct 2 ms 14936 KB Output is correct
88 Correct 418 ms 29280 KB Output is correct
89 Correct 645 ms 23988 KB Output is correct
90 Correct 667 ms 25776 KB Output is correct
91 Correct 665 ms 30628 KB Output is correct
92 Correct 708 ms 30608 KB Output is correct
93 Correct 673 ms 30652 KB Output is correct
94 Correct 735 ms 30668 KB Output is correct
95 Correct 666 ms 30712 KB Output is correct
96 Correct 624 ms 21172 KB Output is correct
97 Correct 661 ms 21180 KB Output is correct
98 Correct 575 ms 29372 KB Output is correct
99 Correct 663 ms 29368 KB Output is correct
100 Correct 676 ms 26056 KB Output is correct
101 Correct 681 ms 24760 KB Output is correct
102 Correct 635 ms 21548 KB Output is correct
103 Correct 656 ms 35504 KB Output is correct
104 Correct 654 ms 37660 KB Output is correct
105 Correct 613 ms 37616 KB Output is correct
106 Correct 609 ms 25284 KB Output is correct
107 Correct 638 ms 23412 KB Output is correct
108 Correct 631 ms 23532 KB Output is correct
109 Correct 625 ms 21960 KB Output is correct