Submission #790134

# Submission time Handle Problem Language Result Execution time Memory
790134 2023-07-22T10:58:57 Z Andrey Digital Circuit (IOI22_circuit) C++17
100 / 100
951 ms 58168 KB
#include "circuit.h"
#include<bits/stdc++.h>
using namespace std;

long long n,m;
vector<long long> haha[300001];
vector<long long> prod(300001);
vector<long long> wow(300001,1);
vector<long long> no(300001);
vector<long long> sum(800001);
vector<long long> idk(800001);
vector<long long> val(800001);
const long long MOD = 1e9+2022;

void build(long long l, long long r, long long x) {
    if(l == r) {
        sum[x] = wow[l+n];
        if(no[l]) {
            val[x] = sum[x];
        }
        else {
            val[x] = 0;
        }
        idk[x] = 0;
        return;
    }
    long long mid = (l+r)/2;
    build(l,mid,x*2+1);
    build(mid+1,r,x*2+2);
    sum[x] = (sum[x*2+1]+sum[x*2+2])%MOD;
    val[x] = (val[x*2+1]+val[x*2+2])%MOD;
}

void upd(long long l, long long r, long long ql, long long qr, long long x) {
    if(l == ql && r == qr) {
        idk[x]++;
        idk[x]%=2;
        val[x] = (sum[x]-val[x]+MOD)%MOD;
        return;
    }
    long long mid = (l+r)/2;
    if(qr <= mid) {
        upd(l,mid,ql,qr,x*2+1);
    }
    else if(ql >= mid+1) {
        upd(mid+1,r,ql,qr,x*2+2);
    }
    else {
        upd(l,mid,ql,mid,x*2+1);
        upd(mid+1,r,mid+1,qr,x*2+2);
    }
    val[x] = (val[x*2+1]+val[x*2+2])%MOD;
    if(idk[x]%2) {
        val[x] = (sum[x]-val[x]+MOD)%MOD;
    }
}

void dfs(long long a) {
    long long sb = max(1LL,(long long)haha[a].size());
    for(long long v: haha[a]) {
        dfs(v);
        sb*=prod[v];
        sb%=MOD;
    }
    prod[a] = sb;
}

void dude(long long a) {
    vector<long long> pr(haha[a].size()+1,1);
    vector<long long> su(haha[a].size()+1,1);
    for(int i = 0; i < haha[a].size(); i++) {
        pr[i+1] = prod[haha[a][i]];
        su[i] = prod[haha[a][i]];
    }
    for(int i = 1; i <= haha[a].size(); i++) {
        pr[i]*=pr[i-1];
        pr[i]%=MOD;
    }
    for(int i = haha[a].size()-1; i >= 0; i--) {
        su[i]*=su[i+1];
        su[i]%=MOD;
    }
    for(int i = 0; i < haha[a].size(); i++) {
        wow[haha[a][i]] = (((wow[a]*pr[i])%MOD)*su[i+1])%MOD;
        dude(haha[a][i]);
    }
}

void init(int N, int M, vector<int> p, vector<int> a) {
    n = N;
    m = M;
    for(long long i = 1; i < n+m; i++) {
        haha[p[i]].push_back(i);
    }
    dfs(0);
    dude(0);
    for(int i = 0; i < a.size(); i++) {
        no[i] = a[i];
    }
    build(0,m-1,0);
}

int count_ways(int l, int r) {
    upd(0,m-1,l-n,r-n,0);
    return val[0];
}

Compilation message

circuit.cpp: In function 'void dude(long long int)':
circuit.cpp:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |     for(int i = 0; i < haha[a].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~
circuit.cpp:75:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for(int i = 1; i <= haha[a].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~~
circuit.cpp:83:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for(int i = 0; i < haha[a].size(); i++) {
      |                    ~~^~~~~~~~~~~~~~~~
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:97:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |     for(int i = 0; i < a.size(); i++) {
      |                    ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 14 ms 33104 KB Output is correct
2 Correct 13 ms 33200 KB Output is correct
3 Correct 13 ms 33244 KB Output is correct
4 Correct 13 ms 33220 KB Output is correct
5 Correct 15 ms 33204 KB Output is correct
6 Correct 13 ms 33232 KB Output is correct
7 Correct 13 ms 33164 KB Output is correct
8 Correct 12 ms 33232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 33104 KB Output is correct
2 Correct 12 ms 33104 KB Output is correct
3 Correct 13 ms 33104 KB Output is correct
4 Correct 13 ms 33100 KB Output is correct
5 Correct 13 ms 33104 KB Output is correct
6 Correct 14 ms 33220 KB Output is correct
7 Correct 13 ms 33232 KB Output is correct
8 Correct 13 ms 33232 KB Output is correct
9 Correct 14 ms 33208 KB Output is correct
10 Correct 12 ms 33416 KB Output is correct
11 Correct 16 ms 33348 KB Output is correct
12 Correct 12 ms 33232 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 33104 KB Output is correct
2 Correct 13 ms 33200 KB Output is correct
3 Correct 13 ms 33244 KB Output is correct
4 Correct 13 ms 33220 KB Output is correct
5 Correct 15 ms 33204 KB Output is correct
6 Correct 13 ms 33232 KB Output is correct
7 Correct 13 ms 33164 KB Output is correct
8 Correct 12 ms 33232 KB Output is correct
9 Correct 12 ms 33104 KB Output is correct
10 Correct 12 ms 33104 KB Output is correct
11 Correct 13 ms 33104 KB Output is correct
12 Correct 13 ms 33100 KB Output is correct
13 Correct 13 ms 33104 KB Output is correct
14 Correct 14 ms 33220 KB Output is correct
15 Correct 13 ms 33232 KB Output is correct
16 Correct 13 ms 33232 KB Output is correct
17 Correct 14 ms 33208 KB Output is correct
18 Correct 12 ms 33416 KB Output is correct
19 Correct 16 ms 33348 KB Output is correct
20 Correct 12 ms 33232 KB Output is correct
21 Correct 12 ms 33244 KB Output is correct
22 Correct 12 ms 33104 KB Output is correct
23 Correct 12 ms 33104 KB Output is correct
24 Correct 12 ms 33144 KB Output is correct
25 Correct 12 ms 33216 KB Output is correct
26 Correct 12 ms 33220 KB Output is correct
27 Correct 12 ms 33236 KB Output is correct
28 Correct 12 ms 33232 KB Output is correct
29 Correct 12 ms 33120 KB Output is correct
30 Correct 13 ms 33236 KB Output is correct
31 Correct 13 ms 33396 KB Output is correct
32 Correct 13 ms 33212 KB Output is correct
33 Correct 15 ms 33224 KB Output is correct
34 Correct 13 ms 33104 KB Output is correct
35 Correct 14 ms 33232 KB Output is correct
36 Correct 14 ms 33416 KB Output is correct
37 Correct 13 ms 33360 KB Output is correct
38 Correct 14 ms 33348 KB Output is correct
39 Correct 13 ms 33208 KB Output is correct
40 Correct 13 ms 33232 KB Output is correct
41 Correct 13 ms 33232 KB Output is correct
42 Correct 13 ms 33208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 538 ms 34896 KB Output is correct
2 Correct 864 ms 36784 KB Output is correct
3 Correct 726 ms 36760 KB Output is correct
4 Correct 872 ms 36704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 538 ms 34896 KB Output is correct
2 Correct 864 ms 36784 KB Output is correct
3 Correct 726 ms 36760 KB Output is correct
4 Correct 872 ms 36704 KB Output is correct
5 Correct 766 ms 34988 KB Output is correct
6 Correct 648 ms 36680 KB Output is correct
7 Correct 881 ms 36788 KB Output is correct
8 Correct 894 ms 36764 KB Output is correct
9 Correct 332 ms 33292 KB Output is correct
10 Correct 919 ms 33404 KB Output is correct
11 Correct 817 ms 33404 KB Output is correct
12 Correct 722 ms 33404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 33104 KB Output is correct
2 Correct 12 ms 33104 KB Output is correct
3 Correct 13 ms 33104 KB Output is correct
4 Correct 13 ms 33100 KB Output is correct
5 Correct 13 ms 33104 KB Output is correct
6 Correct 14 ms 33220 KB Output is correct
7 Correct 13 ms 33232 KB Output is correct
8 Correct 13 ms 33232 KB Output is correct
9 Correct 14 ms 33208 KB Output is correct
10 Correct 12 ms 33416 KB Output is correct
11 Correct 16 ms 33348 KB Output is correct
12 Correct 12 ms 33232 KB Output is correct
13 Correct 538 ms 34896 KB Output is correct
14 Correct 864 ms 36784 KB Output is correct
15 Correct 726 ms 36760 KB Output is correct
16 Correct 872 ms 36704 KB Output is correct
17 Correct 766 ms 34988 KB Output is correct
18 Correct 648 ms 36680 KB Output is correct
19 Correct 881 ms 36788 KB Output is correct
20 Correct 894 ms 36764 KB Output is correct
21 Correct 332 ms 33292 KB Output is correct
22 Correct 919 ms 33404 KB Output is correct
23 Correct 817 ms 33404 KB Output is correct
24 Correct 722 ms 33404 KB Output is correct
25 Correct 941 ms 38560 KB Output is correct
26 Correct 930 ms 38544 KB Output is correct
27 Correct 947 ms 38600 KB Output is correct
28 Correct 732 ms 38568 KB Output is correct
29 Correct 856 ms 55824 KB Output is correct
30 Correct 842 ms 55856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 33104 KB Output is correct
2 Correct 13 ms 33200 KB Output is correct
3 Correct 13 ms 33244 KB Output is correct
4 Correct 13 ms 33220 KB Output is correct
5 Correct 15 ms 33204 KB Output is correct
6 Correct 13 ms 33232 KB Output is correct
7 Correct 13 ms 33164 KB Output is correct
8 Correct 12 ms 33232 KB Output is correct
9 Correct 12 ms 33104 KB Output is correct
10 Correct 12 ms 33104 KB Output is correct
11 Correct 13 ms 33104 KB Output is correct
12 Correct 13 ms 33100 KB Output is correct
13 Correct 13 ms 33104 KB Output is correct
14 Correct 14 ms 33220 KB Output is correct
15 Correct 13 ms 33232 KB Output is correct
16 Correct 13 ms 33232 KB Output is correct
17 Correct 14 ms 33208 KB Output is correct
18 Correct 12 ms 33416 KB Output is correct
19 Correct 16 ms 33348 KB Output is correct
20 Correct 12 ms 33232 KB Output is correct
21 Correct 12 ms 33244 KB Output is correct
22 Correct 12 ms 33104 KB Output is correct
23 Correct 12 ms 33104 KB Output is correct
24 Correct 12 ms 33144 KB Output is correct
25 Correct 12 ms 33216 KB Output is correct
26 Correct 12 ms 33220 KB Output is correct
27 Correct 12 ms 33236 KB Output is correct
28 Correct 12 ms 33232 KB Output is correct
29 Correct 12 ms 33120 KB Output is correct
30 Correct 13 ms 33236 KB Output is correct
31 Correct 13 ms 33396 KB Output is correct
32 Correct 13 ms 33212 KB Output is correct
33 Correct 15 ms 33224 KB Output is correct
34 Correct 13 ms 33104 KB Output is correct
35 Correct 14 ms 33232 KB Output is correct
36 Correct 14 ms 33416 KB Output is correct
37 Correct 13 ms 33360 KB Output is correct
38 Correct 14 ms 33348 KB Output is correct
39 Correct 13 ms 33208 KB Output is correct
40 Correct 13 ms 33232 KB Output is correct
41 Correct 13 ms 33232 KB Output is correct
42 Correct 13 ms 33208 KB Output is correct
43 Correct 543 ms 33360 KB Output is correct
44 Correct 786 ms 33376 KB Output is correct
45 Correct 780 ms 33376 KB Output is correct
46 Correct 725 ms 33492 KB Output is correct
47 Correct 845 ms 33524 KB Output is correct
48 Correct 729 ms 33496 KB Output is correct
49 Correct 761 ms 33484 KB Output is correct
50 Correct 633 ms 33608 KB Output is correct
51 Correct 696 ms 33396 KB Output is correct
52 Correct 714 ms 33436 KB Output is correct
53 Correct 634 ms 34224 KB Output is correct
54 Correct 761 ms 33444 KB Output is correct
55 Correct 652 ms 33412 KB Output is correct
56 Correct 694 ms 33368 KB Output is correct
57 Correct 735 ms 33336 KB Output is correct
58 Correct 759 ms 34324 KB Output is correct
59 Correct 547 ms 34436 KB Output is correct
60 Correct 685 ms 34440 KB Output is correct
61 Correct 859 ms 33576 KB Output is correct
62 Correct 747 ms 33324 KB Output is correct
63 Correct 755 ms 33360 KB Output is correct
64 Correct 770 ms 33360 KB Output is correct
65 Correct 373 ms 33352 KB Output is correct
66 Correct 687 ms 33404 KB Output is correct
67 Correct 808 ms 33392 KB Output is correct
68 Correct 762 ms 33392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 33104 KB Output is correct
2 Correct 13 ms 33200 KB Output is correct
3 Correct 13 ms 33244 KB Output is correct
4 Correct 13 ms 33220 KB Output is correct
5 Correct 15 ms 33204 KB Output is correct
6 Correct 13 ms 33232 KB Output is correct
7 Correct 13 ms 33164 KB Output is correct
8 Correct 12 ms 33232 KB Output is correct
9 Correct 12 ms 33104 KB Output is correct
10 Correct 12 ms 33104 KB Output is correct
11 Correct 13 ms 33104 KB Output is correct
12 Correct 13 ms 33100 KB Output is correct
13 Correct 13 ms 33104 KB Output is correct
14 Correct 14 ms 33220 KB Output is correct
15 Correct 13 ms 33232 KB Output is correct
16 Correct 13 ms 33232 KB Output is correct
17 Correct 14 ms 33208 KB Output is correct
18 Correct 12 ms 33416 KB Output is correct
19 Correct 16 ms 33348 KB Output is correct
20 Correct 12 ms 33232 KB Output is correct
21 Correct 12 ms 33244 KB Output is correct
22 Correct 12 ms 33104 KB Output is correct
23 Correct 12 ms 33104 KB Output is correct
24 Correct 12 ms 33144 KB Output is correct
25 Correct 12 ms 33216 KB Output is correct
26 Correct 12 ms 33220 KB Output is correct
27 Correct 12 ms 33236 KB Output is correct
28 Correct 12 ms 33232 KB Output is correct
29 Correct 12 ms 33120 KB Output is correct
30 Correct 13 ms 33236 KB Output is correct
31 Correct 13 ms 33396 KB Output is correct
32 Correct 13 ms 33212 KB Output is correct
33 Correct 15 ms 33224 KB Output is correct
34 Correct 13 ms 33104 KB Output is correct
35 Correct 14 ms 33232 KB Output is correct
36 Correct 14 ms 33416 KB Output is correct
37 Correct 13 ms 33360 KB Output is correct
38 Correct 14 ms 33348 KB Output is correct
39 Correct 13 ms 33208 KB Output is correct
40 Correct 13 ms 33232 KB Output is correct
41 Correct 13 ms 33232 KB Output is correct
42 Correct 13 ms 33208 KB Output is correct
43 Correct 538 ms 34896 KB Output is correct
44 Correct 864 ms 36784 KB Output is correct
45 Correct 726 ms 36760 KB Output is correct
46 Correct 872 ms 36704 KB Output is correct
47 Correct 766 ms 34988 KB Output is correct
48 Correct 648 ms 36680 KB Output is correct
49 Correct 881 ms 36788 KB Output is correct
50 Correct 894 ms 36764 KB Output is correct
51 Correct 332 ms 33292 KB Output is correct
52 Correct 919 ms 33404 KB Output is correct
53 Correct 817 ms 33404 KB Output is correct
54 Correct 722 ms 33404 KB Output is correct
55 Correct 941 ms 38560 KB Output is correct
56 Correct 930 ms 38544 KB Output is correct
57 Correct 947 ms 38600 KB Output is correct
58 Correct 732 ms 38568 KB Output is correct
59 Correct 856 ms 55824 KB Output is correct
60 Correct 842 ms 55856 KB Output is correct
61 Correct 543 ms 33360 KB Output is correct
62 Correct 786 ms 33376 KB Output is correct
63 Correct 780 ms 33376 KB Output is correct
64 Correct 725 ms 33492 KB Output is correct
65 Correct 845 ms 33524 KB Output is correct
66 Correct 729 ms 33496 KB Output is correct
67 Correct 761 ms 33484 KB Output is correct
68 Correct 633 ms 33608 KB Output is correct
69 Correct 696 ms 33396 KB Output is correct
70 Correct 714 ms 33436 KB Output is correct
71 Correct 634 ms 34224 KB Output is correct
72 Correct 761 ms 33444 KB Output is correct
73 Correct 652 ms 33412 KB Output is correct
74 Correct 694 ms 33368 KB Output is correct
75 Correct 735 ms 33336 KB Output is correct
76 Correct 759 ms 34324 KB Output is correct
77 Correct 547 ms 34436 KB Output is correct
78 Correct 685 ms 34440 KB Output is correct
79 Correct 859 ms 33576 KB Output is correct
80 Correct 747 ms 33324 KB Output is correct
81 Correct 755 ms 33360 KB Output is correct
82 Correct 770 ms 33360 KB Output is correct
83 Correct 373 ms 33352 KB Output is correct
84 Correct 687 ms 33404 KB Output is correct
85 Correct 808 ms 33392 KB Output is correct
86 Correct 762 ms 33392 KB Output is correct
87 Correct 15 ms 33104 KB Output is correct
88 Correct 455 ms 38556 KB Output is correct
89 Correct 822 ms 37032 KB Output is correct
90 Correct 745 ms 37016 KB Output is correct
91 Correct 781 ms 39208 KB Output is correct
92 Correct 854 ms 39344 KB Output is correct
93 Correct 951 ms 39368 KB Output is correct
94 Correct 730 ms 39240 KB Output is correct
95 Correct 814 ms 39240 KB Output is correct
96 Correct 731 ms 37160 KB Output is correct
97 Correct 800 ms 37180 KB Output is correct
98 Correct 703 ms 54300 KB Output is correct
99 Correct 884 ms 38556 KB Output is correct
100 Correct 792 ms 37576 KB Output is correct
101 Correct 793 ms 37028 KB Output is correct
102 Correct 852 ms 35636 KB Output is correct
103 Correct 792 ms 55836 KB Output is correct
104 Correct 823 ms 58168 KB Output is correct
105 Correct 744 ms 58128 KB Output is correct
106 Correct 713 ms 40776 KB Output is correct
107 Correct 809 ms 36128 KB Output is correct
108 Correct 704 ms 36304 KB Output is correct
109 Correct 678 ms 35912 KB Output is correct