Submission #1078496

# Submission time Handle Problem Language Result Execution time Memory
1078496 2024-08-27T18:48:19 Z allin27x Digital Circuit (IOI22_circuit) C++17
100 / 100
860 ms 34656 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1000002022;

const int MAXN = 100007;
int ar[MAXN];
int n,m;
vector<int> ch[2*MAXN];
int mlt[2*MAXN];
int sgt[4*MAXN];
int rel[MAXN];
int res = 0;


void update(int i, int v) {
    for (sgt[i+=2*MAXN]=v; i>1; i>>=1) sgt[i>>1] = (sgt[i] * sgt[i^1]) % mod;
}

int query(int l, int r) {
    int res = 1;
    for (l+=2*MAXN, r+=2*MAXN+1; l<r; l>>=1, r>>=1) {
        if (l&1) res *= sgt[l++], res %= mod;
        if (r&1) res *= sgt[--r], res %= mod;
    }
    return res;
}

int dfs0(int i) {
    vector<int> vl;
    for (int c: ch[i]) vl.push_back(dfs0(c));
    if (vl.size() == 0) return 1;
    int ans = vl.size(); for (int i=0; i<vl.size(); i++) ans *= vl[i], ans%=mod;
    for (int i=0; i<vl.size(); i++) update(i, vl[i]);
    for (int j=0; j<vl.size(); j++) {
        mlt[ch[i][j]] = ((query(0, j-1)) * query(j+1, vl.size()-1)) % mod;
    }
    return ans;
}

void dfs1(int i, int p) {
    if (ch[i].size() == 0) {
        rel[i-n] = (p*mlt[i]) % mod;
    } else {
        for (int c: ch[i]) {
            dfs1(c, (p*mlt[i]) % mod);
        }
    }
}

int pr[MAXN];
int t[4*MAXN];
int lz[4*MAXN];

int sum(int l, int r) {
    if (!l) return pr[r];
    int s=  pr[r] - pr[l-1];
    s %=mod; s+=mod; s%=mod;
    return s;
}

void push(int p, int l, int r) {
    if (!lz[p]) return;
    t[p] = sum(l,r) - t[p]; t[p] %= mod; t[p] += mod; t[p]%=mod;
    lz[p] = 0;
    if (l!=r) {
        lz[2*p] ^= 1;
        lz[2*p+1] ^= 1;
    }
}

int SumQuery(int p, int tl, int tr, int l, int r) {
    push(p, tl, tr);
    if (tl == l && tr == r) return t[p];
    if (l>r) return 0;
    int tm = (tl+tr)/2;
    int a1 = SumQuery(2*p, tl, tm, l, min(tm, r)); a1 %= mod; a1+=mod; a1 %= mod;
    int a2 = SumQuery(2*p+1, tm+1, tr, max(tm+1, l), r); a2 %= mod; a2+=mod; a2 %= mod;
    return (a1 + a2) % mod;
}

void SumUpdate(int p, int tl, int tr, int l, int r) {
    push(p, tl, tr);
    if (tl == l && tr == r) {
        lz[p] = 1; push(p, tl, tr); return;
    }
    if (l>r) return;
    int tm = (tl+tr)/2;
    SumUpdate(2*p, tl, tm, l, min(tm, r));
    SumUpdate(2*p+1, tm+1, tr, max(tm+1, l), r);
    t[p] = t[2*p] + t[2*p+1]; t[p] %= mod;
}


void init(signed N, signed M, std::vector<signed> P, std::vector<signed> A) {
    for (int i=0; i<M; i++) ar[i] = A[i]; n= N;m=M;
    for (int i=1; i<M+N; i++) ch[P[i]].push_back(i);
    for (int i=0; i<4*MAXN; i++) sgt[i] = 1;
    for (int i=0; i<2*MAXN; i++) mlt[i] = 1;
    dfs0(0); dfs1(0,1);
    pr[0] = rel[0]; for (int i=1; i<M; i++) pr[i] = pr[i-1] + rel[i];
    for (int i=0; i<M; i++) if (A[i]) SumUpdate(1, 0, MAXN-1, i, i);
}



signed count_ways(signed L, signed R) {
        L-=n; R-=n;
        SumUpdate(1, 0, MAXN-1, L, R);

        return  SumQuery(1, 0, MAXN-1, 0, m-1);
}

Compilation message

circuit.cpp: In function 'long long int dfs0(long long int)':
circuit.cpp:33:41: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   33 |     int ans = vl.size(); for (int i=0; i<vl.size(); i++) ans *= vl[i], ans%=mod;
      |                                        ~^~~~~~~~~~
circuit.cpp:34:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |     for (int i=0; i<vl.size(); i++) update(i, vl[i]);
      |                   ~^~~~~~~~~~
circuit.cpp:35:20: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for (int j=0; j<vl.size(); j++) {
      |                   ~^~~~~~~~~~
circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:96:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   96 |     for (int i=0; i<M; i++) ar[i] = A[i]; n= N;m=M;
      |     ^~~
circuit.cpp:96:43: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   96 |     for (int i=0; i<M; i++) ar[i] = A[i]; n= N;m=M;
      |                                           ^
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 4 ms 9828 KB Output is correct
3 Correct 5 ms 9816 KB Output is correct
4 Correct 4 ms 9816 KB Output is correct
5 Correct 5 ms 9816 KB Output is correct
6 Correct 5 ms 9816 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Correct 5 ms 9816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 4 ms 9816 KB Output is correct
3 Correct 4 ms 9816 KB Output is correct
4 Correct 6 ms 9896 KB Output is correct
5 Correct 5 ms 9904 KB Output is correct
6 Correct 4 ms 9816 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Correct 5 ms 9816 KB Output is correct
9 Correct 4 ms 9816 KB Output is correct
10 Correct 5 ms 10120 KB Output is correct
11 Correct 5 ms 10072 KB Output is correct
12 Correct 5 ms 9816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 4 ms 9828 KB Output is correct
3 Correct 5 ms 9816 KB Output is correct
4 Correct 4 ms 9816 KB Output is correct
5 Correct 5 ms 9816 KB Output is correct
6 Correct 5 ms 9816 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Correct 5 ms 9816 KB Output is correct
9 Correct 4 ms 9816 KB Output is correct
10 Correct 4 ms 9816 KB Output is correct
11 Correct 4 ms 9816 KB Output is correct
12 Correct 6 ms 9896 KB Output is correct
13 Correct 5 ms 9904 KB Output is correct
14 Correct 4 ms 9816 KB Output is correct
15 Correct 5 ms 9816 KB Output is correct
16 Correct 5 ms 9816 KB Output is correct
17 Correct 4 ms 9816 KB Output is correct
18 Correct 5 ms 10120 KB Output is correct
19 Correct 5 ms 10072 KB Output is correct
20 Correct 5 ms 9816 KB Output is correct
21 Correct 7 ms 9816 KB Output is correct
22 Correct 4 ms 9816 KB Output is correct
23 Correct 5 ms 9816 KB Output is correct
24 Correct 4 ms 9816 KB Output is correct
25 Correct 4 ms 9816 KB Output is correct
26 Correct 5 ms 9812 KB Output is correct
27 Correct 5 ms 9816 KB Output is correct
28 Correct 5 ms 9816 KB Output is correct
29 Correct 5 ms 9816 KB Output is correct
30 Correct 5 ms 9828 KB Output is correct
31 Correct 5 ms 9816 KB Output is correct
32 Correct 5 ms 9816 KB Output is correct
33 Correct 5 ms 9788 KB Output is correct
34 Correct 5 ms 9816 KB Output is correct
35 Correct 5 ms 9816 KB Output is correct
36 Correct 6 ms 10072 KB Output is correct
37 Correct 5 ms 10068 KB Output is correct
38 Correct 5 ms 10072 KB Output is correct
39 Correct 5 ms 9860 KB Output is correct
40 Correct 5 ms 9816 KB Output is correct
41 Correct 5 ms 10008 KB Output is correct
42 Correct 5 ms 9816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 506 ms 13624 KB Output is correct
2 Correct 722 ms 17224 KB Output is correct
3 Correct 728 ms 17232 KB Output is correct
4 Correct 719 ms 16612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 506 ms 13624 KB Output is correct
2 Correct 722 ms 17224 KB Output is correct
3 Correct 728 ms 17232 KB Output is correct
4 Correct 719 ms 16612 KB Output is correct
5 Correct 617 ms 13648 KB Output is correct
6 Correct 857 ms 17240 KB Output is correct
7 Correct 828 ms 17240 KB Output is correct
8 Correct 771 ms 17232 KB Output is correct
9 Correct 339 ms 10072 KB Output is correct
10 Correct 759 ms 10328 KB Output is correct
11 Correct 724 ms 10328 KB Output is correct
12 Correct 685 ms 10328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 4 ms 9816 KB Output is correct
3 Correct 4 ms 9816 KB Output is correct
4 Correct 6 ms 9896 KB Output is correct
5 Correct 5 ms 9904 KB Output is correct
6 Correct 4 ms 9816 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Correct 5 ms 9816 KB Output is correct
9 Correct 4 ms 9816 KB Output is correct
10 Correct 5 ms 10120 KB Output is correct
11 Correct 5 ms 10072 KB Output is correct
12 Correct 5 ms 9816 KB Output is correct
13 Correct 506 ms 13624 KB Output is correct
14 Correct 722 ms 17224 KB Output is correct
15 Correct 728 ms 17232 KB Output is correct
16 Correct 719 ms 16612 KB Output is correct
17 Correct 617 ms 13648 KB Output is correct
18 Correct 857 ms 17240 KB Output is correct
19 Correct 828 ms 17240 KB Output is correct
20 Correct 771 ms 17232 KB Output is correct
21 Correct 339 ms 10072 KB Output is correct
22 Correct 759 ms 10328 KB Output is correct
23 Correct 724 ms 10328 KB Output is correct
24 Correct 685 ms 10328 KB Output is correct
25 Correct 840 ms 21072 KB Output is correct
26 Correct 812 ms 21072 KB Output is correct
27 Correct 852 ms 21068 KB Output is correct
28 Correct 649 ms 21168 KB Output is correct
29 Correct 815 ms 33688 KB Output is correct
30 Correct 812 ms 33728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 4 ms 9828 KB Output is correct
3 Correct 5 ms 9816 KB Output is correct
4 Correct 4 ms 9816 KB Output is correct
5 Correct 5 ms 9816 KB Output is correct
6 Correct 5 ms 9816 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Correct 5 ms 9816 KB Output is correct
9 Correct 4 ms 9816 KB Output is correct
10 Correct 4 ms 9816 KB Output is correct
11 Correct 4 ms 9816 KB Output is correct
12 Correct 6 ms 9896 KB Output is correct
13 Correct 5 ms 9904 KB Output is correct
14 Correct 4 ms 9816 KB Output is correct
15 Correct 5 ms 9816 KB Output is correct
16 Correct 5 ms 9816 KB Output is correct
17 Correct 4 ms 9816 KB Output is correct
18 Correct 5 ms 10120 KB Output is correct
19 Correct 5 ms 10072 KB Output is correct
20 Correct 5 ms 9816 KB Output is correct
21 Correct 7 ms 9816 KB Output is correct
22 Correct 4 ms 9816 KB Output is correct
23 Correct 5 ms 9816 KB Output is correct
24 Correct 4 ms 9816 KB Output is correct
25 Correct 4 ms 9816 KB Output is correct
26 Correct 5 ms 9812 KB Output is correct
27 Correct 5 ms 9816 KB Output is correct
28 Correct 5 ms 9816 KB Output is correct
29 Correct 5 ms 9816 KB Output is correct
30 Correct 5 ms 9828 KB Output is correct
31 Correct 5 ms 9816 KB Output is correct
32 Correct 5 ms 9816 KB Output is correct
33 Correct 5 ms 9788 KB Output is correct
34 Correct 5 ms 9816 KB Output is correct
35 Correct 5 ms 9816 KB Output is correct
36 Correct 6 ms 10072 KB Output is correct
37 Correct 5 ms 10068 KB Output is correct
38 Correct 5 ms 10072 KB Output is correct
39 Correct 5 ms 9860 KB Output is correct
40 Correct 5 ms 9816 KB Output is correct
41 Correct 5 ms 10008 KB Output is correct
42 Correct 5 ms 9816 KB Output is correct
43 Correct 533 ms 10072 KB Output is correct
44 Correct 776 ms 10072 KB Output is correct
45 Correct 717 ms 10072 KB Output is correct
46 Correct 669 ms 10416 KB Output is correct
47 Correct 703 ms 10328 KB Output is correct
48 Correct 749 ms 10328 KB Output is correct
49 Correct 712 ms 10384 KB Output is correct
50 Correct 753 ms 10328 KB Output is correct
51 Correct 637 ms 10456 KB Output is correct
52 Correct 661 ms 10464 KB Output is correct
53 Correct 652 ms 10584 KB Output is correct
54 Correct 691 ms 10328 KB Output is correct
55 Correct 732 ms 10328 KB Output is correct
56 Correct 699 ms 10328 KB Output is correct
57 Correct 669 ms 10328 KB Output is correct
58 Correct 753 ms 11096 KB Output is correct
59 Correct 667 ms 11288 KB Output is correct
60 Correct 663 ms 11280 KB Output is correct
61 Correct 673 ms 10328 KB Output is correct
62 Correct 745 ms 10196 KB Output is correct
63 Correct 696 ms 10328 KB Output is correct
64 Correct 723 ms 10328 KB Output is correct
65 Correct 366 ms 10072 KB Output is correct
66 Correct 762 ms 10328 KB Output is correct
67 Correct 721 ms 10328 KB Output is correct
68 Correct 730 ms 10328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 9816 KB Output is correct
2 Correct 4 ms 9828 KB Output is correct
3 Correct 5 ms 9816 KB Output is correct
4 Correct 4 ms 9816 KB Output is correct
5 Correct 5 ms 9816 KB Output is correct
6 Correct 5 ms 9816 KB Output is correct
7 Correct 5 ms 9816 KB Output is correct
8 Correct 5 ms 9816 KB Output is correct
9 Correct 4 ms 9816 KB Output is correct
10 Correct 4 ms 9816 KB Output is correct
11 Correct 4 ms 9816 KB Output is correct
12 Correct 6 ms 9896 KB Output is correct
13 Correct 5 ms 9904 KB Output is correct
14 Correct 4 ms 9816 KB Output is correct
15 Correct 5 ms 9816 KB Output is correct
16 Correct 5 ms 9816 KB Output is correct
17 Correct 4 ms 9816 KB Output is correct
18 Correct 5 ms 10120 KB Output is correct
19 Correct 5 ms 10072 KB Output is correct
20 Correct 5 ms 9816 KB Output is correct
21 Correct 7 ms 9816 KB Output is correct
22 Correct 4 ms 9816 KB Output is correct
23 Correct 5 ms 9816 KB Output is correct
24 Correct 4 ms 9816 KB Output is correct
25 Correct 4 ms 9816 KB Output is correct
26 Correct 5 ms 9812 KB Output is correct
27 Correct 5 ms 9816 KB Output is correct
28 Correct 5 ms 9816 KB Output is correct
29 Correct 5 ms 9816 KB Output is correct
30 Correct 5 ms 9828 KB Output is correct
31 Correct 5 ms 9816 KB Output is correct
32 Correct 5 ms 9816 KB Output is correct
33 Correct 5 ms 9788 KB Output is correct
34 Correct 5 ms 9816 KB Output is correct
35 Correct 5 ms 9816 KB Output is correct
36 Correct 6 ms 10072 KB Output is correct
37 Correct 5 ms 10068 KB Output is correct
38 Correct 5 ms 10072 KB Output is correct
39 Correct 5 ms 9860 KB Output is correct
40 Correct 5 ms 9816 KB Output is correct
41 Correct 5 ms 10008 KB Output is correct
42 Correct 5 ms 9816 KB Output is correct
43 Correct 506 ms 13624 KB Output is correct
44 Correct 722 ms 17224 KB Output is correct
45 Correct 728 ms 17232 KB Output is correct
46 Correct 719 ms 16612 KB Output is correct
47 Correct 617 ms 13648 KB Output is correct
48 Correct 857 ms 17240 KB Output is correct
49 Correct 828 ms 17240 KB Output is correct
50 Correct 771 ms 17232 KB Output is correct
51 Correct 339 ms 10072 KB Output is correct
52 Correct 759 ms 10328 KB Output is correct
53 Correct 724 ms 10328 KB Output is correct
54 Correct 685 ms 10328 KB Output is correct
55 Correct 840 ms 21072 KB Output is correct
56 Correct 812 ms 21072 KB Output is correct
57 Correct 852 ms 21068 KB Output is correct
58 Correct 649 ms 21168 KB Output is correct
59 Correct 815 ms 33688 KB Output is correct
60 Correct 812 ms 33728 KB Output is correct
61 Correct 533 ms 10072 KB Output is correct
62 Correct 776 ms 10072 KB Output is correct
63 Correct 717 ms 10072 KB Output is correct
64 Correct 669 ms 10416 KB Output is correct
65 Correct 703 ms 10328 KB Output is correct
66 Correct 749 ms 10328 KB Output is correct
67 Correct 712 ms 10384 KB Output is correct
68 Correct 753 ms 10328 KB Output is correct
69 Correct 637 ms 10456 KB Output is correct
70 Correct 661 ms 10464 KB Output is correct
71 Correct 652 ms 10584 KB Output is correct
72 Correct 691 ms 10328 KB Output is correct
73 Correct 732 ms 10328 KB Output is correct
74 Correct 699 ms 10328 KB Output is correct
75 Correct 669 ms 10328 KB Output is correct
76 Correct 753 ms 11096 KB Output is correct
77 Correct 667 ms 11288 KB Output is correct
78 Correct 663 ms 11280 KB Output is correct
79 Correct 673 ms 10328 KB Output is correct
80 Correct 745 ms 10196 KB Output is correct
81 Correct 696 ms 10328 KB Output is correct
82 Correct 723 ms 10328 KB Output is correct
83 Correct 366 ms 10072 KB Output is correct
84 Correct 762 ms 10328 KB Output is correct
85 Correct 721 ms 10328 KB Output is correct
86 Correct 730 ms 10328 KB Output is correct
87 Correct 5 ms 9816 KB Output is correct
88 Correct 554 ms 20148 KB Output is correct
89 Correct 800 ms 16464 KB Output is correct
90 Correct 820 ms 16976 KB Output is correct
91 Correct 816 ms 21840 KB Output is correct
92 Correct 843 ms 21840 KB Output is correct
93 Correct 794 ms 21216 KB Output is correct
94 Correct 830 ms 21824 KB Output is correct
95 Correct 824 ms 21820 KB Output is correct
96 Correct 751 ms 18228 KB Output is correct
97 Correct 753 ms 18232 KB Output is correct
98 Correct 673 ms 26192 KB Output is correct
99 Correct 805 ms 21072 KB Output is correct
100 Correct 807 ms 20304 KB Output is correct
101 Correct 808 ms 19536 KB Output is correct
102 Correct 855 ms 18256 KB Output is correct
103 Correct 860 ms 33616 KB Output is correct
104 Correct 858 ms 34620 KB Output is correct
105 Correct 826 ms 34656 KB Output is correct
106 Correct 818 ms 18904 KB Output is correct
107 Correct 770 ms 16720 KB Output is correct
108 Correct 776 ms 17488 KB Output is correct
109 Correct 811 ms 18264 KB Output is correct