Submission #674061

# Submission time Handle Problem Language Result Execution time Memory
674061 2022-12-22T19:41:24 Z Ronin13 Digital Circuit (IOI22_circuit) C++17
100 / 100
1101 ms 144304 KB
#include "circuit.h"

#include <vector>
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
using namespace std;
const ll mod = 1e9 + 2022;
const int nmax = 1e6 + 1;

vector <vector <int> > g(nmax);
vector <int> lazy(4* nmax);
vector <ll>t(4 * nmax), t1(4 * nmax);
/*
3 4 3
-1 0 1 2 1 1 0
1 0 1 0
3 4
4 5
3 6
*/
void push(int v){
    if(!lazy[v]) return;
    lazy[2 * v] ^= lazy[v];
    lazy[2 * v + 1] ^= lazy[v];
    swap(t[2 * v], t1[2 * v]);
    swap(t[2 * v + 1], t1[2 * v + 1]);
    lazy[v] = 0;
}

void update(int v, int l, int r, int st, int fin){
    if(l > fin || r < st) return;
    if(l >= st && r <= fin){
        swap(t[v], t1[v]);
        lazy[v] ^= 1;
        return;
    }
    int m = (l + r) / 2;
    push(v);
    update(2 * v, l, m, st, fin);
    update(2 * v + 1, m + 1, r, st, fin);
    t[v] = t[2 * v] + t[2 * v + 1]; t[v] %= mod;
    t1[v] = t1[2 * v] + t1[2 * v + 1]; t1[v] %= mod;
}

vector <int> a;
vector <ll> val(nmax);
int n;
void build(int v, int l, int r){
    if(l == r){
        if(a[l - 1]){
            t[v] = val[l + n];
            return;
        }
        else t1[v] = val[l + n];
        return;
    }
    int m = (l + r) / 2;
    build(2 * v, l, m);
    build(2 * v + 1, m + 1, r);
    t[v] = t[2 * v] + t[2 * v + 1]; t[v] %= mod;
    t1[v] = t1[2 * v] + t1[2 * v + 1]; t1[v] %= mod;
}
vector <ll> dp(nmax);


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

}

void DFS(int v, ll value = 1){
    vector <ll> pref, suf;
    pref.resize(g[v].size());
    suf.resize(g[v].size());
    for(int i = 0; i < g[v].size(); i++){
        if(i == 0) pref[i] = dp[g[v][i]];
        else pref[i] = dp[g[v][i]] * pref[i - 1] % mod;
    }
    for(int i = g[v].size() - 1; i >= 0; i--){
        if(i == g[v].size() - 1){
            suf[i] = dp[g[v][i]];
        }
        else suf[i] = suf[i + 1] * dp[g[v][i]] % mod;
    }
    for(int i = 0; i < g[v].size(); i++){
        val[g[v][i]] = value;
        int u = g[v][i];
        if(i) val[u] *= pref[i - 1], val[u] %= mod;
        if(i != g[v].size() - 1)
            val[u] *= suf[i + 1], val[u] %= mod;
        DFS(u, val[u]);
    }
}
int m;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
    n = N;
    m = M;
    a = A;
    for(int i = 0; i < n + m; i++){
        int x = P[i];
        if(x != -1)
        g[x + 1].pb(i + 1);
    }
    dfs(1);
    DFS(1);
    /*for(int i = 1; i <= n + m; i++){
        cout << dp[i] << ' ';
    }
    cout << "\n";
    for(int i = 1; i <= m; i++) cout << val[i + n] << ' ';*/
    build(1, 1, m);
   // cout << t[1] << ' ';
}

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

Compilation message

circuit.cpp: In function 'void DFS(int, long long int)':
circuit.cpp:87:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |     for(int i = 0; i < g[v].size(); i++){
      |                    ~~^~~~~~~~~~~~~
circuit.cpp:92:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |         if(i == g[v].size() - 1){
      |            ~~^~~~~~~~~~~~~~~~~~
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 < g[v].size(); i++){
      |                    ~~^~~~~~~~~~~~~
circuit.cpp:101:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |         if(i != g[v].size() - 1)
      |            ~~^~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 49 ms 117720 KB Output is correct
2 Correct 44 ms 117680 KB Output is correct
3 Correct 44 ms 117708 KB Output is correct
4 Correct 44 ms 117704 KB Output is correct
5 Correct 45 ms 117652 KB Output is correct
6 Correct 44 ms 117756 KB Output is correct
7 Correct 50 ms 117776 KB Output is correct
8 Correct 46 ms 117760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 117624 KB Output is correct
2 Correct 47 ms 117668 KB Output is correct
3 Correct 49 ms 117696 KB Output is correct
4 Correct 48 ms 117688 KB Output is correct
5 Correct 44 ms 117712 KB Output is correct
6 Correct 45 ms 117744 KB Output is correct
7 Correct 45 ms 117760 KB Output is correct
8 Correct 45 ms 117688 KB Output is correct
9 Correct 49 ms 117784 KB Output is correct
10 Correct 51 ms 117880 KB Output is correct
11 Correct 51 ms 117880 KB Output is correct
12 Correct 45 ms 117760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 117720 KB Output is correct
2 Correct 44 ms 117680 KB Output is correct
3 Correct 44 ms 117708 KB Output is correct
4 Correct 44 ms 117704 KB Output is correct
5 Correct 45 ms 117652 KB Output is correct
6 Correct 44 ms 117756 KB Output is correct
7 Correct 50 ms 117776 KB Output is correct
8 Correct 46 ms 117760 KB Output is correct
9 Correct 45 ms 117624 KB Output is correct
10 Correct 47 ms 117668 KB Output is correct
11 Correct 49 ms 117696 KB Output is correct
12 Correct 48 ms 117688 KB Output is correct
13 Correct 44 ms 117712 KB Output is correct
14 Correct 45 ms 117744 KB Output is correct
15 Correct 45 ms 117760 KB Output is correct
16 Correct 45 ms 117688 KB Output is correct
17 Correct 49 ms 117784 KB Output is correct
18 Correct 51 ms 117880 KB Output is correct
19 Correct 51 ms 117880 KB Output is correct
20 Correct 45 ms 117760 KB Output is correct
21 Correct 46 ms 117756 KB Output is correct
22 Correct 46 ms 117684 KB Output is correct
23 Correct 53 ms 117752 KB Output is correct
24 Correct 46 ms 117700 KB Output is correct
25 Correct 44 ms 117724 KB Output is correct
26 Correct 46 ms 117772 KB Output is correct
27 Correct 46 ms 117664 KB Output is correct
28 Correct 46 ms 117700 KB Output is correct
29 Correct 50 ms 117716 KB Output is correct
30 Correct 45 ms 117700 KB Output is correct
31 Correct 48 ms 117824 KB Output is correct
32 Correct 45 ms 117688 KB Output is correct
33 Correct 44 ms 117760 KB Output is correct
34 Correct 45 ms 117756 KB Output is correct
35 Correct 44 ms 117672 KB Output is correct
36 Correct 45 ms 117928 KB Output is correct
37 Correct 53 ms 117908 KB Output is correct
38 Correct 48 ms 117960 KB Output is correct
39 Correct 44 ms 117732 KB Output is correct
40 Correct 45 ms 117632 KB Output is correct
41 Correct 43 ms 117704 KB Output is correct
42 Correct 44 ms 117684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 707 ms 119644 KB Output is correct
2 Correct 1000 ms 121500 KB Output is correct
3 Correct 911 ms 121568 KB Output is correct
4 Correct 967 ms 121544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 707 ms 119644 KB Output is correct
2 Correct 1000 ms 121500 KB Output is correct
3 Correct 911 ms 121568 KB Output is correct
4 Correct 967 ms 121544 KB Output is correct
5 Correct 683 ms 119600 KB Output is correct
6 Correct 965 ms 121568 KB Output is correct
7 Correct 916 ms 121576 KB Output is correct
8 Correct 972 ms 121468 KB Output is correct
9 Correct 409 ms 117840 KB Output is correct
10 Correct 755 ms 117964 KB Output is correct
11 Correct 913 ms 118072 KB Output is correct
12 Correct 844 ms 117960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 117624 KB Output is correct
2 Correct 47 ms 117668 KB Output is correct
3 Correct 49 ms 117696 KB Output is correct
4 Correct 48 ms 117688 KB Output is correct
5 Correct 44 ms 117712 KB Output is correct
6 Correct 45 ms 117744 KB Output is correct
7 Correct 45 ms 117760 KB Output is correct
8 Correct 45 ms 117688 KB Output is correct
9 Correct 49 ms 117784 KB Output is correct
10 Correct 51 ms 117880 KB Output is correct
11 Correct 51 ms 117880 KB Output is correct
12 Correct 45 ms 117760 KB Output is correct
13 Correct 707 ms 119644 KB Output is correct
14 Correct 1000 ms 121500 KB Output is correct
15 Correct 911 ms 121568 KB Output is correct
16 Correct 967 ms 121544 KB Output is correct
17 Correct 683 ms 119600 KB Output is correct
18 Correct 965 ms 121568 KB Output is correct
19 Correct 916 ms 121576 KB Output is correct
20 Correct 972 ms 121468 KB Output is correct
21 Correct 409 ms 117840 KB Output is correct
22 Correct 755 ms 117964 KB Output is correct
23 Correct 913 ms 118072 KB Output is correct
24 Correct 844 ms 117960 KB Output is correct
25 Correct 1030 ms 123480 KB Output is correct
26 Correct 1101 ms 123608 KB Output is correct
27 Correct 1000 ms 123588 KB Output is correct
28 Correct 858 ms 123600 KB Output is correct
29 Correct 1070 ms 142316 KB Output is correct
30 Correct 976 ms 142308 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 117720 KB Output is correct
2 Correct 44 ms 117680 KB Output is correct
3 Correct 44 ms 117708 KB Output is correct
4 Correct 44 ms 117704 KB Output is correct
5 Correct 45 ms 117652 KB Output is correct
6 Correct 44 ms 117756 KB Output is correct
7 Correct 50 ms 117776 KB Output is correct
8 Correct 46 ms 117760 KB Output is correct
9 Correct 45 ms 117624 KB Output is correct
10 Correct 47 ms 117668 KB Output is correct
11 Correct 49 ms 117696 KB Output is correct
12 Correct 48 ms 117688 KB Output is correct
13 Correct 44 ms 117712 KB Output is correct
14 Correct 45 ms 117744 KB Output is correct
15 Correct 45 ms 117760 KB Output is correct
16 Correct 45 ms 117688 KB Output is correct
17 Correct 49 ms 117784 KB Output is correct
18 Correct 51 ms 117880 KB Output is correct
19 Correct 51 ms 117880 KB Output is correct
20 Correct 45 ms 117760 KB Output is correct
21 Correct 46 ms 117756 KB Output is correct
22 Correct 46 ms 117684 KB Output is correct
23 Correct 53 ms 117752 KB Output is correct
24 Correct 46 ms 117700 KB Output is correct
25 Correct 44 ms 117724 KB Output is correct
26 Correct 46 ms 117772 KB Output is correct
27 Correct 46 ms 117664 KB Output is correct
28 Correct 46 ms 117700 KB Output is correct
29 Correct 50 ms 117716 KB Output is correct
30 Correct 45 ms 117700 KB Output is correct
31 Correct 48 ms 117824 KB Output is correct
32 Correct 45 ms 117688 KB Output is correct
33 Correct 44 ms 117760 KB Output is correct
34 Correct 45 ms 117756 KB Output is correct
35 Correct 44 ms 117672 KB Output is correct
36 Correct 45 ms 117928 KB Output is correct
37 Correct 53 ms 117908 KB Output is correct
38 Correct 48 ms 117960 KB Output is correct
39 Correct 44 ms 117732 KB Output is correct
40 Correct 45 ms 117632 KB Output is correct
41 Correct 43 ms 117704 KB Output is correct
42 Correct 44 ms 117684 KB Output is correct
43 Correct 592 ms 117900 KB Output is correct
44 Correct 822 ms 117936 KB Output is correct
45 Correct 964 ms 117960 KB Output is correct
46 Correct 813 ms 118032 KB Output is correct
47 Correct 847 ms 118088 KB Output is correct
48 Correct 785 ms 118084 KB Output is correct
49 Correct 801 ms 118024 KB Output is correct
50 Correct 934 ms 118020 KB Output is correct
51 Correct 872 ms 117960 KB Output is correct
52 Correct 868 ms 117960 KB Output is correct
53 Correct 523 ms 118908 KB Output is correct
54 Correct 867 ms 118016 KB Output is correct
55 Correct 835 ms 117912 KB Output is correct
56 Correct 935 ms 117908 KB Output is correct
57 Correct 871 ms 117960 KB Output is correct
58 Correct 969 ms 118948 KB Output is correct
59 Correct 812 ms 119056 KB Output is correct
60 Correct 706 ms 119052 KB Output is correct
61 Correct 923 ms 118144 KB Output is correct
62 Correct 790 ms 117876 KB Output is correct
63 Correct 952 ms 117960 KB Output is correct
64 Correct 851 ms 117896 KB Output is correct
65 Correct 478 ms 117844 KB Output is correct
66 Correct 932 ms 117960 KB Output is correct
67 Correct 684 ms 117968 KB Output is correct
68 Correct 903 ms 117964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 117720 KB Output is correct
2 Correct 44 ms 117680 KB Output is correct
3 Correct 44 ms 117708 KB Output is correct
4 Correct 44 ms 117704 KB Output is correct
5 Correct 45 ms 117652 KB Output is correct
6 Correct 44 ms 117756 KB Output is correct
7 Correct 50 ms 117776 KB Output is correct
8 Correct 46 ms 117760 KB Output is correct
9 Correct 45 ms 117624 KB Output is correct
10 Correct 47 ms 117668 KB Output is correct
11 Correct 49 ms 117696 KB Output is correct
12 Correct 48 ms 117688 KB Output is correct
13 Correct 44 ms 117712 KB Output is correct
14 Correct 45 ms 117744 KB Output is correct
15 Correct 45 ms 117760 KB Output is correct
16 Correct 45 ms 117688 KB Output is correct
17 Correct 49 ms 117784 KB Output is correct
18 Correct 51 ms 117880 KB Output is correct
19 Correct 51 ms 117880 KB Output is correct
20 Correct 45 ms 117760 KB Output is correct
21 Correct 46 ms 117756 KB Output is correct
22 Correct 46 ms 117684 KB Output is correct
23 Correct 53 ms 117752 KB Output is correct
24 Correct 46 ms 117700 KB Output is correct
25 Correct 44 ms 117724 KB Output is correct
26 Correct 46 ms 117772 KB Output is correct
27 Correct 46 ms 117664 KB Output is correct
28 Correct 46 ms 117700 KB Output is correct
29 Correct 50 ms 117716 KB Output is correct
30 Correct 45 ms 117700 KB Output is correct
31 Correct 48 ms 117824 KB Output is correct
32 Correct 45 ms 117688 KB Output is correct
33 Correct 44 ms 117760 KB Output is correct
34 Correct 45 ms 117756 KB Output is correct
35 Correct 44 ms 117672 KB Output is correct
36 Correct 45 ms 117928 KB Output is correct
37 Correct 53 ms 117908 KB Output is correct
38 Correct 48 ms 117960 KB Output is correct
39 Correct 44 ms 117732 KB Output is correct
40 Correct 45 ms 117632 KB Output is correct
41 Correct 43 ms 117704 KB Output is correct
42 Correct 44 ms 117684 KB Output is correct
43 Correct 707 ms 119644 KB Output is correct
44 Correct 1000 ms 121500 KB Output is correct
45 Correct 911 ms 121568 KB Output is correct
46 Correct 967 ms 121544 KB Output is correct
47 Correct 683 ms 119600 KB Output is correct
48 Correct 965 ms 121568 KB Output is correct
49 Correct 916 ms 121576 KB Output is correct
50 Correct 972 ms 121468 KB Output is correct
51 Correct 409 ms 117840 KB Output is correct
52 Correct 755 ms 117964 KB Output is correct
53 Correct 913 ms 118072 KB Output is correct
54 Correct 844 ms 117960 KB Output is correct
55 Correct 1030 ms 123480 KB Output is correct
56 Correct 1101 ms 123608 KB Output is correct
57 Correct 1000 ms 123588 KB Output is correct
58 Correct 858 ms 123600 KB Output is correct
59 Correct 1070 ms 142316 KB Output is correct
60 Correct 976 ms 142308 KB Output is correct
61 Correct 592 ms 117900 KB Output is correct
62 Correct 822 ms 117936 KB Output is correct
63 Correct 964 ms 117960 KB Output is correct
64 Correct 813 ms 118032 KB Output is correct
65 Correct 847 ms 118088 KB Output is correct
66 Correct 785 ms 118084 KB Output is correct
67 Correct 801 ms 118024 KB Output is correct
68 Correct 934 ms 118020 KB Output is correct
69 Correct 872 ms 117960 KB Output is correct
70 Correct 868 ms 117960 KB Output is correct
71 Correct 523 ms 118908 KB Output is correct
72 Correct 867 ms 118016 KB Output is correct
73 Correct 835 ms 117912 KB Output is correct
74 Correct 935 ms 117908 KB Output is correct
75 Correct 871 ms 117960 KB Output is correct
76 Correct 969 ms 118948 KB Output is correct
77 Correct 812 ms 119056 KB Output is correct
78 Correct 706 ms 119052 KB Output is correct
79 Correct 923 ms 118144 KB Output is correct
80 Correct 790 ms 117876 KB Output is correct
81 Correct 952 ms 117960 KB Output is correct
82 Correct 851 ms 117896 KB Output is correct
83 Correct 478 ms 117844 KB Output is correct
84 Correct 932 ms 117960 KB Output is correct
85 Correct 684 ms 117968 KB Output is correct
86 Correct 903 ms 117964 KB Output is correct
87 Correct 47 ms 117664 KB Output is correct
88 Correct 670 ms 122956 KB Output is correct
89 Correct 910 ms 121708 KB Output is correct
90 Correct 974 ms 121388 KB Output is correct
91 Correct 795 ms 123712 KB Output is correct
92 Correct 787 ms 123700 KB Output is correct
93 Correct 1050 ms 123740 KB Output is correct
94 Correct 981 ms 123708 KB Output is correct
95 Correct 924 ms 123652 KB Output is correct
96 Correct 911 ms 121668 KB Output is correct
97 Correct 1006 ms 121748 KB Output is correct
98 Correct 606 ms 140292 KB Output is correct
99 Correct 1083 ms 123576 KB Output is correct
100 Correct 1022 ms 121548 KB Output is correct
101 Correct 886 ms 121164 KB Output is correct
102 Correct 883 ms 120092 KB Output is correct
103 Correct 966 ms 142280 KB Output is correct
104 Correct 972 ms 144272 KB Output is correct
105 Correct 919 ms 144304 KB Output is correct
106 Correct 912 ms 125696 KB Output is correct
107 Correct 1071 ms 120588 KB Output is correct
108 Correct 907 ms 120456 KB Output is correct
109 Correct 740 ms 120296 KB Output is correct