Submission #629138

# Submission time Handle Problem Language Result Execution time Memory
629138 2022-08-14T08:10:33 Z kdh9949 Digital Circuit (IOI22_circuit) C++17
100 / 100
1304 ms 29456 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

const int SZ = 131072;
const ll MOD = ll(1e9) + 2022;
struct Seg {
  int l[2 * SZ];
  ll d[2 * SZ], w[2 * SZ];

  void i(int n, vector<int> a, vector<ll> v) {
    for(int i = 0; i < n; i++) w[i + SZ] = v[i];
    for(int i = 0; i < n; i++) if(a[i]) d[i + SZ] = v[i];
    for(int i = SZ - 1; i; i--) {
      d[i] = (d[2 * i] + d[2 * i + 1]) % MOD;
      w[i] = (w[2 * i] + w[2 * i + 1]) % MOD;
    }
  }

  void flp(int x) {
    d[x] = (w[x] + MOD - d[x]) % MOD;
    l[x] ^= 1;
  }

  void u(int s, int e, int x = 1, int p = 0, int q = SZ - 1) {
    if(e < p || q < s) return;
    if(s <= p && q <= e) {
      flp(x);
      return;
    }
    if(l[x]) { flp(2 * x); flp(2 * x + 1); l[x] = 0; }
    u(s, e, 2 * x, p, (p + q) / 2);
    u(s, e, 2 * x + 1, (p + q) / 2 + 1, q);
    d[x] = (d[2 * x] + d[2 * x + 1]) % MOD;
  }
} S;

int n;
void init(int N, int M, vector<int> P, vector<int> A) {
  n = N;
  vector<vector<int>> e(N);
  for(int i = 1; i < N + M; i++) e[P[i]].push_back(i);

  vector<ll> w(N);
  for(int i = N - 1; i; i--) {
    w[i] = e[i].size();
    for(int j : e[i]) if(j < N) (w[i] *= w[j]) %= MOD;
  }

  vector<ll> v(M);
  const function<void(int, ll)> f = [&](int x, ll t) {
    if(x >= N) {
      v[x - N] = t;
      return;
    }
    vector<ll> sf = {1};
    for(int i = int(e[x].size()) - 1; i; i--)
      sf.push_back(sf.back() * (e[x][i] < N ? w[e[x][i]] : 1) % MOD);
    ll pf = 1;
    for(int i : e[x]) {
      f(i, t * pf % MOD * sf.back() % MOD);
      if(i < N) (pf *= w[i]) %= MOD;
      sf.pop_back();
    }
  };
  f(0, 1);

  S.i(M, A, v);
}

int count_ways(int L, int R) {
  S.u(L - n, R - n);
  return S.d[1];
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2376 KB Output is correct
2 Correct 3 ms 2300 KB Output is correct
3 Correct 3 ms 2424 KB Output is correct
4 Correct 3 ms 2432 KB Output is correct
5 Correct 2 ms 2384 KB Output is correct
6 Correct 2 ms 2432 KB Output is correct
7 Correct 2 ms 2384 KB Output is correct
8 Correct 2 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2256 KB Output is correct
2 Correct 2 ms 2384 KB Output is correct
3 Correct 3 ms 2416 KB Output is correct
4 Correct 2 ms 2348 KB Output is correct
5 Correct 3 ms 2432 KB Output is correct
6 Correct 3 ms 2468 KB Output is correct
7 Correct 2 ms 2512 KB Output is correct
8 Correct 4 ms 2512 KB Output is correct
9 Correct 3 ms 2512 KB Output is correct
10 Correct 4 ms 2640 KB Output is correct
11 Correct 4 ms 2640 KB Output is correct
12 Correct 4 ms 2492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2376 KB Output is correct
2 Correct 3 ms 2300 KB Output is correct
3 Correct 3 ms 2424 KB Output is correct
4 Correct 3 ms 2432 KB Output is correct
5 Correct 2 ms 2384 KB Output is correct
6 Correct 2 ms 2432 KB Output is correct
7 Correct 2 ms 2384 KB Output is correct
8 Correct 2 ms 2384 KB Output is correct
9 Correct 3 ms 2256 KB Output is correct
10 Correct 2 ms 2384 KB Output is correct
11 Correct 3 ms 2416 KB Output is correct
12 Correct 2 ms 2348 KB Output is correct
13 Correct 3 ms 2432 KB Output is correct
14 Correct 3 ms 2468 KB Output is correct
15 Correct 2 ms 2512 KB Output is correct
16 Correct 4 ms 2512 KB Output is correct
17 Correct 3 ms 2512 KB Output is correct
18 Correct 4 ms 2640 KB Output is correct
19 Correct 4 ms 2640 KB Output is correct
20 Correct 4 ms 2492 KB Output is correct
21 Correct 4 ms 2384 KB Output is correct
22 Correct 3 ms 2384 KB Output is correct
23 Correct 3 ms 2392 KB Output is correct
24 Correct 3 ms 2384 KB Output is correct
25 Correct 3 ms 2512 KB Output is correct
26 Correct 2 ms 2512 KB Output is correct
27 Correct 3 ms 2512 KB Output is correct
28 Correct 2 ms 2512 KB Output is correct
29 Correct 3 ms 2384 KB Output is correct
30 Correct 3 ms 2384 KB Output is correct
31 Correct 3 ms 2512 KB Output is correct
32 Correct 4 ms 2512 KB Output is correct
33 Correct 3 ms 2432 KB Output is correct
34 Correct 4 ms 2360 KB Output is correct
35 Correct 2 ms 2384 KB Output is correct
36 Correct 3 ms 2688 KB Output is correct
37 Correct 4 ms 2676 KB Output is correct
38 Correct 3 ms 2640 KB Output is correct
39 Correct 4 ms 2432 KB Output is correct
40 Correct 2 ms 2432 KB Output is correct
41 Correct 2 ms 2384 KB Output is correct
42 Correct 3 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 595 ms 6308 KB Output is correct
2 Correct 1014 ms 10316 KB Output is correct
3 Correct 1304 ms 10272 KB Output is correct
4 Correct 955 ms 9800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 595 ms 6308 KB Output is correct
2 Correct 1014 ms 10316 KB Output is correct
3 Correct 1304 ms 10272 KB Output is correct
4 Correct 955 ms 9800 KB Output is correct
5 Correct 867 ms 6324 KB Output is correct
6 Correct 1075 ms 10312 KB Output is correct
7 Correct 870 ms 10324 KB Output is correct
8 Correct 1037 ms 10280 KB Output is correct
9 Correct 495 ms 2640 KB Output is correct
10 Correct 825 ms 2896 KB Output is correct
11 Correct 1044 ms 2896 KB Output is correct
12 Correct 785 ms 2896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2256 KB Output is correct
2 Correct 2 ms 2384 KB Output is correct
3 Correct 3 ms 2416 KB Output is correct
4 Correct 2 ms 2348 KB Output is correct
5 Correct 3 ms 2432 KB Output is correct
6 Correct 3 ms 2468 KB Output is correct
7 Correct 2 ms 2512 KB Output is correct
8 Correct 4 ms 2512 KB Output is correct
9 Correct 3 ms 2512 KB Output is correct
10 Correct 4 ms 2640 KB Output is correct
11 Correct 4 ms 2640 KB Output is correct
12 Correct 4 ms 2492 KB Output is correct
13 Correct 595 ms 6308 KB Output is correct
14 Correct 1014 ms 10316 KB Output is correct
15 Correct 1304 ms 10272 KB Output is correct
16 Correct 955 ms 9800 KB Output is correct
17 Correct 867 ms 6324 KB Output is correct
18 Correct 1075 ms 10312 KB Output is correct
19 Correct 870 ms 10324 KB Output is correct
20 Correct 1037 ms 10280 KB Output is correct
21 Correct 495 ms 2640 KB Output is correct
22 Correct 825 ms 2896 KB Output is correct
23 Correct 1044 ms 2896 KB Output is correct
24 Correct 785 ms 2896 KB Output is correct
25 Correct 1044 ms 14200 KB Output is correct
26 Correct 922 ms 14500 KB Output is correct
27 Correct 901 ms 14440 KB Output is correct
28 Correct 800 ms 14404 KB Output is correct
29 Correct 1000 ms 28864 KB Output is correct
30 Correct 960 ms 28868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2376 KB Output is correct
2 Correct 3 ms 2300 KB Output is correct
3 Correct 3 ms 2424 KB Output is correct
4 Correct 3 ms 2432 KB Output is correct
5 Correct 2 ms 2384 KB Output is correct
6 Correct 2 ms 2432 KB Output is correct
7 Correct 2 ms 2384 KB Output is correct
8 Correct 2 ms 2384 KB Output is correct
9 Correct 3 ms 2256 KB Output is correct
10 Correct 2 ms 2384 KB Output is correct
11 Correct 3 ms 2416 KB Output is correct
12 Correct 2 ms 2348 KB Output is correct
13 Correct 3 ms 2432 KB Output is correct
14 Correct 3 ms 2468 KB Output is correct
15 Correct 2 ms 2512 KB Output is correct
16 Correct 4 ms 2512 KB Output is correct
17 Correct 3 ms 2512 KB Output is correct
18 Correct 4 ms 2640 KB Output is correct
19 Correct 4 ms 2640 KB Output is correct
20 Correct 4 ms 2492 KB Output is correct
21 Correct 4 ms 2384 KB Output is correct
22 Correct 3 ms 2384 KB Output is correct
23 Correct 3 ms 2392 KB Output is correct
24 Correct 3 ms 2384 KB Output is correct
25 Correct 3 ms 2512 KB Output is correct
26 Correct 2 ms 2512 KB Output is correct
27 Correct 3 ms 2512 KB Output is correct
28 Correct 2 ms 2512 KB Output is correct
29 Correct 3 ms 2384 KB Output is correct
30 Correct 3 ms 2384 KB Output is correct
31 Correct 3 ms 2512 KB Output is correct
32 Correct 4 ms 2512 KB Output is correct
33 Correct 3 ms 2432 KB Output is correct
34 Correct 4 ms 2360 KB Output is correct
35 Correct 2 ms 2384 KB Output is correct
36 Correct 3 ms 2688 KB Output is correct
37 Correct 4 ms 2676 KB Output is correct
38 Correct 3 ms 2640 KB Output is correct
39 Correct 4 ms 2432 KB Output is correct
40 Correct 2 ms 2432 KB Output is correct
41 Correct 2 ms 2384 KB Output is correct
42 Correct 3 ms 2384 KB Output is correct
43 Correct 595 ms 2768 KB Output is correct
44 Correct 699 ms 2768 KB Output is correct
45 Correct 732 ms 2816 KB Output is correct
46 Correct 754 ms 2896 KB Output is correct
47 Correct 1062 ms 3024 KB Output is correct
48 Correct 1016 ms 3024 KB Output is correct
49 Correct 1123 ms 3024 KB Output is correct
50 Correct 792 ms 3024 KB Output is correct
51 Correct 783 ms 2640 KB Output is correct
52 Correct 896 ms 2704 KB Output is correct
53 Correct 1045 ms 3456 KB Output is correct
54 Correct 943 ms 3056 KB Output is correct
55 Correct 928 ms 2804 KB Output is correct
56 Correct 1073 ms 2740 KB Output is correct
57 Correct 1045 ms 2688 KB Output is correct
58 Correct 965 ms 3692 KB Output is correct
59 Correct 889 ms 3852 KB Output is correct
60 Correct 821 ms 3792 KB Output is correct
61 Correct 779 ms 2896 KB Output is correct
62 Correct 870 ms 2844 KB Output is correct
63 Correct 876 ms 2640 KB Output is correct
64 Correct 765 ms 2640 KB Output is correct
65 Correct 457 ms 2640 KB Output is correct
66 Correct 766 ms 2896 KB Output is correct
67 Correct 945 ms 2896 KB Output is correct
68 Correct 825 ms 2896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2376 KB Output is correct
2 Correct 3 ms 2300 KB Output is correct
3 Correct 3 ms 2424 KB Output is correct
4 Correct 3 ms 2432 KB Output is correct
5 Correct 2 ms 2384 KB Output is correct
6 Correct 2 ms 2432 KB Output is correct
7 Correct 2 ms 2384 KB Output is correct
8 Correct 2 ms 2384 KB Output is correct
9 Correct 3 ms 2256 KB Output is correct
10 Correct 2 ms 2384 KB Output is correct
11 Correct 3 ms 2416 KB Output is correct
12 Correct 2 ms 2348 KB Output is correct
13 Correct 3 ms 2432 KB Output is correct
14 Correct 3 ms 2468 KB Output is correct
15 Correct 2 ms 2512 KB Output is correct
16 Correct 4 ms 2512 KB Output is correct
17 Correct 3 ms 2512 KB Output is correct
18 Correct 4 ms 2640 KB Output is correct
19 Correct 4 ms 2640 KB Output is correct
20 Correct 4 ms 2492 KB Output is correct
21 Correct 4 ms 2384 KB Output is correct
22 Correct 3 ms 2384 KB Output is correct
23 Correct 3 ms 2392 KB Output is correct
24 Correct 3 ms 2384 KB Output is correct
25 Correct 3 ms 2512 KB Output is correct
26 Correct 2 ms 2512 KB Output is correct
27 Correct 3 ms 2512 KB Output is correct
28 Correct 2 ms 2512 KB Output is correct
29 Correct 3 ms 2384 KB Output is correct
30 Correct 3 ms 2384 KB Output is correct
31 Correct 3 ms 2512 KB Output is correct
32 Correct 4 ms 2512 KB Output is correct
33 Correct 3 ms 2432 KB Output is correct
34 Correct 4 ms 2360 KB Output is correct
35 Correct 2 ms 2384 KB Output is correct
36 Correct 3 ms 2688 KB Output is correct
37 Correct 4 ms 2676 KB Output is correct
38 Correct 3 ms 2640 KB Output is correct
39 Correct 4 ms 2432 KB Output is correct
40 Correct 2 ms 2432 KB Output is correct
41 Correct 2 ms 2384 KB Output is correct
42 Correct 3 ms 2384 KB Output is correct
43 Correct 595 ms 6308 KB Output is correct
44 Correct 1014 ms 10316 KB Output is correct
45 Correct 1304 ms 10272 KB Output is correct
46 Correct 955 ms 9800 KB Output is correct
47 Correct 867 ms 6324 KB Output is correct
48 Correct 1075 ms 10312 KB Output is correct
49 Correct 870 ms 10324 KB Output is correct
50 Correct 1037 ms 10280 KB Output is correct
51 Correct 495 ms 2640 KB Output is correct
52 Correct 825 ms 2896 KB Output is correct
53 Correct 1044 ms 2896 KB Output is correct
54 Correct 785 ms 2896 KB Output is correct
55 Correct 1044 ms 14200 KB Output is correct
56 Correct 922 ms 14500 KB Output is correct
57 Correct 901 ms 14440 KB Output is correct
58 Correct 800 ms 14404 KB Output is correct
59 Correct 1000 ms 28864 KB Output is correct
60 Correct 960 ms 28868 KB Output is correct
61 Correct 595 ms 2768 KB Output is correct
62 Correct 699 ms 2768 KB Output is correct
63 Correct 732 ms 2816 KB Output is correct
64 Correct 754 ms 2896 KB Output is correct
65 Correct 1062 ms 3024 KB Output is correct
66 Correct 1016 ms 3024 KB Output is correct
67 Correct 1123 ms 3024 KB Output is correct
68 Correct 792 ms 3024 KB Output is correct
69 Correct 783 ms 2640 KB Output is correct
70 Correct 896 ms 2704 KB Output is correct
71 Correct 1045 ms 3456 KB Output is correct
72 Correct 943 ms 3056 KB Output is correct
73 Correct 928 ms 2804 KB Output is correct
74 Correct 1073 ms 2740 KB Output is correct
75 Correct 1045 ms 2688 KB Output is correct
76 Correct 965 ms 3692 KB Output is correct
77 Correct 889 ms 3852 KB Output is correct
78 Correct 821 ms 3792 KB Output is correct
79 Correct 779 ms 2896 KB Output is correct
80 Correct 870 ms 2844 KB Output is correct
81 Correct 876 ms 2640 KB Output is correct
82 Correct 765 ms 2640 KB Output is correct
83 Correct 457 ms 2640 KB Output is correct
84 Correct 766 ms 2896 KB Output is correct
85 Correct 945 ms 2896 KB Output is correct
86 Correct 825 ms 2896 KB Output is correct
87 Correct 2 ms 2384 KB Output is correct
88 Correct 520 ms 13088 KB Output is correct
89 Correct 992 ms 10336 KB Output is correct
90 Correct 991 ms 9972 KB Output is correct
91 Correct 963 ms 14532 KB Output is correct
92 Correct 848 ms 14536 KB Output is correct
93 Correct 994 ms 13736 KB Output is correct
94 Correct 902 ms 14548 KB Output is correct
95 Correct 1006 ms 14500 KB Output is correct
96 Correct 764 ms 7864 KB Output is correct
97 Correct 817 ms 7716 KB Output is correct
98 Correct 684 ms 24996 KB Output is correct
99 Correct 941 ms 14408 KB Output is correct
100 Correct 1083 ms 10908 KB Output is correct
101 Correct 761 ms 9640 KB Output is correct
102 Correct 937 ms 7880 KB Output is correct
103 Correct 901 ms 28968 KB Output is correct
104 Correct 719 ms 29404 KB Output is correct
105 Correct 853 ms 29456 KB Output is correct
106 Correct 985 ms 12836 KB Output is correct
107 Correct 1072 ms 8644 KB Output is correct
108 Correct 956 ms 8484 KB Output is correct
109 Correct 1018 ms 8004 KB Output is correct