Submission #1025254

# Submission time Handle Problem Language Result Execution time Memory
1025254 2024-07-16T18:24:55 Z vjudge1 Digital Circuit (IOI22_circuit) C++17
100 / 100
861 ms 36452 KB
#include <bits/stdc++.h>
#define ent '\n'
#define f first
#define s second

using namespace std;
typedef long long ll;
const int maxn = 2e5 + 12;
const int mod = 1e9 + 2022;

pair<ll, ll> t[maxn*4];
vector<int> g[maxn];
ll dp[maxn];
ll mul[maxn];
int a[maxn];
int p[maxn];
int n, m;

void calc(int v, int p){
    dp[v] = max(1, (int)g[v].size());
    for(int to:g[v]){
        calc(to, v);
        dp[v] = dp[v] * dp[to] % mod;
    }
}

void dfs(int v, int p){
    if(!mul[v]) mul[v] = 1;
    vector<ll> suff;
    for(int i=0;i<g[v].size();i++){
        suff.push_back(dp[g[v][i]]);
    }
    suff.push_back(1);
    for(int i=(int)suff.size()-2;i>=0;i--){
        suff[i] = suff[i] * suff[i+1] % mod;
    }
    ll pref = 1;
    for(int i=0;i<g[v].size();i++){
        int to = g[v][i];
        mul[to] = pref * suff[i+1] % mod * mul[v] % mod;
        dfs(to, v);
        pref = pref * dp[to] % mod;
    }

}

void build(int v, int tl, int tr){
    p[v] = 0;
    if(tl == tr){
        if(a[tl]){
            t[v] = {0, mul[tl+m-1]};
        }
        else{
            t[v] = {mul[tl+m-1], 0};
        }
    }
    else{
        int mid = tl + tr >> 1;
        build(v*2, tl, mid);
        build(v*2+1, mid+1, tr);
        t[v].f = (t[v*2].f + t[v*2+1].f) % mod;
        t[v].s = (t[v*2].s + t[v*2+1].s) % mod;
    }
}

void push(int v, int tl, int tr){
    if(tl == tr || !p[v]){
        return;
    }
    p[v*2] ^= 1;
    p[v*2+1] ^= 1;
    swap(t[v*2].f, t[v*2].s);
    swap(t[v*2+1].f, t[v*2+1].s);
    p[v] = 0;
}

void upd(int v, int tl, int tr, int l, int r){
    push(v, tl, tr);
    if(tl > r || l > tr){
        return;
    }
    if(tl >= l && tr <= r){
        swap(t[v].f, t[v].s);
        p[v] = 1;
        return;
    }
    int mid = tl + tr >> 1;
    upd(v*2, tl, mid, l, r);
    upd(v*2+1, mid+1, tr, l, r);
    t[v].f = (t[v*2].f + t[v*2+1].f) % mod;
    t[v].s = (t[v*2].s + t[v*2+1].s) % mod;
}

void init(int N, int M, std::vector<int> p, std::vector<int> A){
    m = N, n = M;
    for(int i=1;i<n+m;i++){
        g[p[i]].push_back(i);
    }
    for(int i=1;i<=n;i++){
        a[i] = A[i-1];
    }
    calc(0, -1);
    dfs(0, -1);
    build(1, 1, n);
}

int count_ways(int L, int R){
    L -= m - 1, R -= m - 1;
    upd(1, 1, n, L, R);
    return t[1].s;
}

Compilation message

circuit.cpp: In function 'void dfs(int, int)':
circuit.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |     for(int i=0;i<g[v].size();i++){
      |                 ~^~~~~~~~~~~~
circuit.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   38 |     for(int i=0;i<g[v].size();i++){
      |                 ~^~~~~~~~~~~~
circuit.cpp: In function 'void build(int, int, int)':
circuit.cpp:58:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   58 |         int mid = tl + tr >> 1;
      |                   ~~~^~~~
circuit.cpp: In function 'void upd(int, int, int, int, int)':
circuit.cpp:87:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   87 |     int mid = tl + tr >> 1;
      |               ~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 3 ms 5208 KB Output is correct
4 Correct 3 ms 5208 KB Output is correct
5 Correct 4 ms 5208 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4952 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 4 ms 5208 KB Output is correct
4 Correct 2 ms 5208 KB Output is correct
5 Correct 3 ms 5028 KB Output is correct
6 Correct 2 ms 5024 KB Output is correct
7 Correct 4 ms 5208 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 3 ms 5208 KB Output is correct
10 Correct 3 ms 5208 KB Output is correct
11 Correct 4 ms 5208 KB Output is correct
12 Correct 3 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 3 ms 5208 KB Output is correct
4 Correct 3 ms 5208 KB Output is correct
5 Correct 4 ms 5208 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 4 ms 4952 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 4 ms 5208 KB Output is correct
12 Correct 2 ms 5208 KB Output is correct
13 Correct 3 ms 5028 KB Output is correct
14 Correct 2 ms 5024 KB Output is correct
15 Correct 4 ms 5208 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 3 ms 5208 KB Output is correct
19 Correct 4 ms 5208 KB Output is correct
20 Correct 3 ms 5208 KB Output is correct
21 Correct 3 ms 10584 KB Output is correct
22 Correct 3 ms 5120 KB Output is correct
23 Correct 4 ms 5208 KB Output is correct
24 Correct 3 ms 5208 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 5208 KB Output is correct
27 Correct 3 ms 5204 KB Output is correct
28 Correct 5 ms 5208 KB Output is correct
29 Correct 4 ms 5208 KB Output is correct
30 Correct 2 ms 5208 KB Output is correct
31 Correct 4 ms 5184 KB Output is correct
32 Correct 4 ms 5208 KB Output is correct
33 Correct 4 ms 5208 KB Output is correct
34 Correct 3 ms 5244 KB Output is correct
35 Correct 3 ms 5208 KB Output is correct
36 Correct 3 ms 5208 KB Output is correct
37 Correct 3 ms 5208 KB Output is correct
38 Correct 3 ms 5208 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 3 ms 5208 KB Output is correct
41 Correct 2 ms 5208 KB Output is correct
42 Correct 3 ms 5208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 555 ms 9296 KB Output is correct
2 Correct 774 ms 13392 KB Output is correct
3 Correct 759 ms 13396 KB Output is correct
4 Correct 774 ms 13396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 555 ms 9296 KB Output is correct
2 Correct 774 ms 13392 KB Output is correct
3 Correct 759 ms 13396 KB Output is correct
4 Correct 774 ms 13396 KB Output is correct
5 Correct 575 ms 9304 KB Output is correct
6 Correct 743 ms 13392 KB Output is correct
7 Correct 794 ms 16484 KB Output is correct
8 Correct 721 ms 16472 KB Output is correct
9 Correct 302 ms 10584 KB Output is correct
10 Correct 691 ms 10840 KB Output is correct
11 Correct 638 ms 10840 KB Output is correct
12 Correct 731 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4952 KB Output is correct
2 Correct 3 ms 4952 KB Output is correct
3 Correct 4 ms 5208 KB Output is correct
4 Correct 2 ms 5208 KB Output is correct
5 Correct 3 ms 5028 KB Output is correct
6 Correct 2 ms 5024 KB Output is correct
7 Correct 4 ms 5208 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 3 ms 5208 KB Output is correct
10 Correct 3 ms 5208 KB Output is correct
11 Correct 4 ms 5208 KB Output is correct
12 Correct 3 ms 5208 KB Output is correct
13 Correct 555 ms 9296 KB Output is correct
14 Correct 774 ms 13392 KB Output is correct
15 Correct 759 ms 13396 KB Output is correct
16 Correct 774 ms 13396 KB Output is correct
17 Correct 575 ms 9304 KB Output is correct
18 Correct 743 ms 13392 KB Output is correct
19 Correct 794 ms 16484 KB Output is correct
20 Correct 721 ms 16472 KB Output is correct
21 Correct 302 ms 10584 KB Output is correct
22 Correct 691 ms 10840 KB Output is correct
23 Correct 638 ms 10840 KB Output is correct
24 Correct 731 ms 10840 KB Output is correct
25 Correct 846 ms 19264 KB Output is correct
26 Correct 832 ms 19276 KB Output is correct
27 Correct 776 ms 19260 KB Output is correct
28 Correct 650 ms 19024 KB Output is correct
29 Correct 811 ms 36176 KB Output is correct
30 Correct 732 ms 36016 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 3 ms 5208 KB Output is correct
4 Correct 3 ms 5208 KB Output is correct
5 Correct 4 ms 5208 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 4 ms 4952 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 4 ms 5208 KB Output is correct
12 Correct 2 ms 5208 KB Output is correct
13 Correct 3 ms 5028 KB Output is correct
14 Correct 2 ms 5024 KB Output is correct
15 Correct 4 ms 5208 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 3 ms 5208 KB Output is correct
19 Correct 4 ms 5208 KB Output is correct
20 Correct 3 ms 5208 KB Output is correct
21 Correct 3 ms 10584 KB Output is correct
22 Correct 3 ms 5120 KB Output is correct
23 Correct 4 ms 5208 KB Output is correct
24 Correct 3 ms 5208 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 5208 KB Output is correct
27 Correct 3 ms 5204 KB Output is correct
28 Correct 5 ms 5208 KB Output is correct
29 Correct 4 ms 5208 KB Output is correct
30 Correct 2 ms 5208 KB Output is correct
31 Correct 4 ms 5184 KB Output is correct
32 Correct 4 ms 5208 KB Output is correct
33 Correct 4 ms 5208 KB Output is correct
34 Correct 3 ms 5244 KB Output is correct
35 Correct 3 ms 5208 KB Output is correct
36 Correct 3 ms 5208 KB Output is correct
37 Correct 3 ms 5208 KB Output is correct
38 Correct 3 ms 5208 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 3 ms 5208 KB Output is correct
41 Correct 2 ms 5208 KB Output is correct
42 Correct 3 ms 5208 KB Output is correct
43 Correct 472 ms 5464 KB Output is correct
44 Correct 667 ms 5464 KB Output is correct
45 Correct 608 ms 5464 KB Output is correct
46 Correct 606 ms 5720 KB Output is correct
47 Correct 647 ms 5720 KB Output is correct
48 Correct 609 ms 6232 KB Output is correct
49 Correct 729 ms 5720 KB Output is correct
50 Correct 658 ms 5720 KB Output is correct
51 Correct 703 ms 6180 KB Output is correct
52 Correct 656 ms 6180 KB Output is correct
53 Correct 675 ms 6488 KB Output is correct
54 Correct 718 ms 6232 KB Output is correct
55 Correct 695 ms 5976 KB Output is correct
56 Correct 647 ms 5976 KB Output is correct
57 Correct 651 ms 10840 KB Output is correct
58 Correct 673 ms 11864 KB Output is correct
59 Correct 694 ms 11864 KB Output is correct
60 Correct 681 ms 11864 KB Output is correct
61 Correct 649 ms 11096 KB Output is correct
62 Correct 670 ms 5976 KB Output is correct
63 Correct 697 ms 10840 KB Output is correct
64 Correct 670 ms 10840 KB Output is correct
65 Correct 321 ms 5208 KB Output is correct
66 Correct 725 ms 5464 KB Output is correct
67 Correct 657 ms 10840 KB Output is correct
68 Correct 626 ms 8792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4952 KB Output is correct
2 Correct 2 ms 4952 KB Output is correct
3 Correct 3 ms 5208 KB Output is correct
4 Correct 3 ms 5208 KB Output is correct
5 Correct 4 ms 5208 KB Output is correct
6 Correct 3 ms 5208 KB Output is correct
7 Correct 2 ms 5208 KB Output is correct
8 Correct 3 ms 5208 KB Output is correct
9 Correct 4 ms 4952 KB Output is correct
10 Correct 3 ms 4952 KB Output is correct
11 Correct 4 ms 5208 KB Output is correct
12 Correct 2 ms 5208 KB Output is correct
13 Correct 3 ms 5028 KB Output is correct
14 Correct 2 ms 5024 KB Output is correct
15 Correct 4 ms 5208 KB Output is correct
16 Correct 3 ms 5208 KB Output is correct
17 Correct 3 ms 5208 KB Output is correct
18 Correct 3 ms 5208 KB Output is correct
19 Correct 4 ms 5208 KB Output is correct
20 Correct 3 ms 5208 KB Output is correct
21 Correct 3 ms 10584 KB Output is correct
22 Correct 3 ms 5120 KB Output is correct
23 Correct 4 ms 5208 KB Output is correct
24 Correct 3 ms 5208 KB Output is correct
25 Correct 3 ms 5208 KB Output is correct
26 Correct 3 ms 5208 KB Output is correct
27 Correct 3 ms 5204 KB Output is correct
28 Correct 5 ms 5208 KB Output is correct
29 Correct 4 ms 5208 KB Output is correct
30 Correct 2 ms 5208 KB Output is correct
31 Correct 4 ms 5184 KB Output is correct
32 Correct 4 ms 5208 KB Output is correct
33 Correct 4 ms 5208 KB Output is correct
34 Correct 3 ms 5244 KB Output is correct
35 Correct 3 ms 5208 KB Output is correct
36 Correct 3 ms 5208 KB Output is correct
37 Correct 3 ms 5208 KB Output is correct
38 Correct 3 ms 5208 KB Output is correct
39 Correct 3 ms 5208 KB Output is correct
40 Correct 3 ms 5208 KB Output is correct
41 Correct 2 ms 5208 KB Output is correct
42 Correct 3 ms 5208 KB Output is correct
43 Correct 555 ms 9296 KB Output is correct
44 Correct 774 ms 13392 KB Output is correct
45 Correct 759 ms 13396 KB Output is correct
46 Correct 774 ms 13396 KB Output is correct
47 Correct 575 ms 9304 KB Output is correct
48 Correct 743 ms 13392 KB Output is correct
49 Correct 794 ms 16484 KB Output is correct
50 Correct 721 ms 16472 KB Output is correct
51 Correct 302 ms 10584 KB Output is correct
52 Correct 691 ms 10840 KB Output is correct
53 Correct 638 ms 10840 KB Output is correct
54 Correct 731 ms 10840 KB Output is correct
55 Correct 846 ms 19264 KB Output is correct
56 Correct 832 ms 19276 KB Output is correct
57 Correct 776 ms 19260 KB Output is correct
58 Correct 650 ms 19024 KB Output is correct
59 Correct 811 ms 36176 KB Output is correct
60 Correct 732 ms 36016 KB Output is correct
61 Correct 472 ms 5464 KB Output is correct
62 Correct 667 ms 5464 KB Output is correct
63 Correct 608 ms 5464 KB Output is correct
64 Correct 606 ms 5720 KB Output is correct
65 Correct 647 ms 5720 KB Output is correct
66 Correct 609 ms 6232 KB Output is correct
67 Correct 729 ms 5720 KB Output is correct
68 Correct 658 ms 5720 KB Output is correct
69 Correct 703 ms 6180 KB Output is correct
70 Correct 656 ms 6180 KB Output is correct
71 Correct 675 ms 6488 KB Output is correct
72 Correct 718 ms 6232 KB Output is correct
73 Correct 695 ms 5976 KB Output is correct
74 Correct 647 ms 5976 KB Output is correct
75 Correct 651 ms 10840 KB Output is correct
76 Correct 673 ms 11864 KB Output is correct
77 Correct 694 ms 11864 KB Output is correct
78 Correct 681 ms 11864 KB Output is correct
79 Correct 649 ms 11096 KB Output is correct
80 Correct 670 ms 5976 KB Output is correct
81 Correct 697 ms 10840 KB Output is correct
82 Correct 670 ms 10840 KB Output is correct
83 Correct 321 ms 5208 KB Output is correct
84 Correct 725 ms 5464 KB Output is correct
85 Correct 657 ms 10840 KB Output is correct
86 Correct 626 ms 8792 KB Output is correct
87 Correct 2 ms 10584 KB Output is correct
88 Correct 503 ms 19768 KB Output is correct
89 Correct 846 ms 14160 KB Output is correct
90 Correct 797 ms 14508 KB Output is correct
91 Correct 733 ms 19284 KB Output is correct
92 Correct 788 ms 19276 KB Output is correct
93 Correct 861 ms 19280 KB Output is correct
94 Correct 794 ms 19280 KB Output is correct
95 Correct 718 ms 19280 KB Output is correct
96 Correct 672 ms 16960 KB Output is correct
97 Correct 731 ms 16960 KB Output is correct
98 Correct 575 ms 30040 KB Output is correct
99 Correct 770 ms 19292 KB Output is correct
100 Correct 804 ms 17232 KB Output is correct
101 Correct 816 ms 15696 KB Output is correct
102 Correct 730 ms 15960 KB Output is correct
103 Correct 817 ms 36432 KB Output is correct
104 Correct 733 ms 36452 KB Output is correct
105 Correct 724 ms 36424 KB Output is correct
106 Correct 797 ms 20048 KB Output is correct
107 Correct 773 ms 16464 KB Output is correct
108 Correct 817 ms 16272 KB Output is correct
109 Correct 797 ms 16088 KB Output is correct