Submission #627950

# Submission time Handle Problem Language Result Execution time Memory
627950 2022-08-13T01:32:53 Z lunchbox Digital Circuit (IOI22_circuit) C++17
100 / 100
1244 ms 29384 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;

const int MD = 1000002022;

template<int N>
struct Lst {
  static const int N_ = 1 << (__lg(N - 1) + 1);
  int n, z[N_];
  pi t[N_ * 2];

  void bld(int k, int l, int r, const vector<pi>& ar) {
    if (l == r)
      t[k] = ar[l];
    else {
      int m = (l + r) / 2;
      z[k] = 0;
      bld(k << 1 | 0, l, m, ar), bld(k << 1 | 1, m + 1, r, ar);
      pul(k, l, r);
    }
  }
  void bld(int n_, const vector<pi>& ar) {
    n = n_;
    bld(1, 0, n - 1, ar);
  }
  void pul(int k, int l, int r) {
    int lc = k << 1 | 0, rc = k << 1 | 1;
    t[k].first = (t[lc].first + t[rc].first) % MD;
    t[k].second = (t[lc].second + t[rc].second) % MD;
  }
  void put(int k, int l, int r, int x) {
    swap(t[k].first, t[k].second);
    if (l != r)
      z[k] ^= 1;
  }
  void pus(int k, int l, int r) {
    if (z[k]) {
      int m = (l + r) / 2;
      put(k << 1 | 0, l, m, z[k]), put(k << 1 | 1, m + 1, r, z[k]);
      z[k] = 0;
    }
  }
  void upd(int k, int l, int r, int ql, int qr, int x) {
    if (ql <= l && qr >= r)
      put(k, l, r, x);
    else if (qr >= l && ql <= r) {
      int m = (l + r) / 2;
      pus(k, l, r);
      upd(k << 1 | 0, l, m, ql, qr, x), upd(k << 1 | 1, m + 1, r, ql, qr, x);
      pul(k, l, r);
    }
  }
  void upd(int l, int r, int x) {
    upd(1, 0, n - 1, l, r, x);
  }
};

Lst<100000> st;

int n;

void init(int n_, int m, vi p, vi a) {
  n = n_;
  vector<vi> ej(n + m);
  for (int i = 0; i < n + m; i++)
    if (p[i] != -1)
      ej[p[i]].push_back(i);
  vector<ll> v(n + m), f(n + m);
  vector<pi> c(m);
  function<void(int)> dfs = [&](int i) {
    if (ej[i].size() == 0) {
      f[i] = 1;
      return;
    }
    f[i] = ej[i].size();
    for (int j : ej[i]) {
      dfs(j);
      f[i] = f[i] * f[j] % MD;
    }
    int k = ej[i].size();
    vector<ll> L(k, 1), R(k, 1);
    for (int j = 1; j < k; j++)
      L[j] = L[j - 1] * f[ej[i][j - 1]] % MD;
    for (int j = k - 2; j >= 0; j--)
      R[j] = R[j + 1] * f[ej[i][j + 1]] % MD;
    for (int j = 0; j < k; j++)
      v[ej[i][j]] = L[j] * R[j] % MD;
  };
  v[0] = 1;
  dfs(0);
  for (int i = 1; i < n + m; i++)
    v[i] = v[p[i]] * v[i] % MD;
  for (int i = 0; i < m; i++) {
    int u = v[i + n];
    if (a[i])
      c[i].first = u % MD;
    else
      c[i].second = u % MD;
  }
  st.bld(m, c);
}

int count_ways(int l, int r) {
  st.upd(l - n, r - n, 1);
  return st.t[1].first;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2256 KB Output is correct
2 Correct 1 ms 2256 KB Output is correct
3 Correct 2 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 2 ms 2384 KB Output is correct
7 Correct 2 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2256 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 2 ms 2384 KB Output is correct
4 Correct 2 ms 2384 KB Output is correct
5 Correct 2 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 2 ms 2384 KB Output is correct
8 Correct 3 ms 2384 KB Output is correct
9 Correct 2 ms 2384 KB Output is correct
10 Correct 2 ms 2512 KB Output is correct
11 Correct 2 ms 2512 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2256 KB Output is correct
2 Correct 1 ms 2256 KB Output is correct
3 Correct 2 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 2 ms 2384 KB Output is correct
7 Correct 2 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2256 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 2 ms 2384 KB Output is correct
12 Correct 2 ms 2384 KB Output is correct
13 Correct 2 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 2 ms 2384 KB Output is correct
16 Correct 3 ms 2384 KB Output is correct
17 Correct 2 ms 2384 KB Output is correct
18 Correct 2 ms 2512 KB Output is correct
19 Correct 2 ms 2512 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 2 ms 2384 KB Output is correct
22 Correct 2 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 2 ms 2384 KB Output is correct
25 Correct 2 ms 2384 KB Output is correct
26 Correct 2 ms 2384 KB Output is correct
27 Correct 2 ms 2384 KB Output is correct
28 Correct 2 ms 2384 KB Output is correct
29 Correct 2 ms 2384 KB Output is correct
30 Correct 1 ms 2384 KB Output is correct
31 Correct 2 ms 2512 KB Output is correct
32 Correct 2 ms 2384 KB Output is correct
33 Correct 2 ms 2384 KB Output is correct
34 Correct 1 ms 2384 KB Output is correct
35 Correct 2 ms 2384 KB Output is correct
36 Correct 2 ms 2512 KB Output is correct
37 Correct 2 ms 2512 KB Output is correct
38 Correct 2 ms 2512 KB Output is correct
39 Correct 2 ms 2384 KB Output is correct
40 Correct 1 ms 2384 KB Output is correct
41 Correct 2 ms 2384 KB Output is correct
42 Correct 1 ms 2384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 485 ms 7084 KB Output is correct
2 Correct 962 ms 11848 KB Output is correct
3 Correct 952 ms 11848 KB Output is correct
4 Correct 1000 ms 11812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 485 ms 7084 KB Output is correct
2 Correct 962 ms 11848 KB Output is correct
3 Correct 952 ms 11848 KB Output is correct
4 Correct 1000 ms 11812 KB Output is correct
5 Correct 795 ms 7028 KB Output is correct
6 Correct 895 ms 11876 KB Output is correct
7 Correct 922 ms 11856 KB Output is correct
8 Correct 771 ms 11812 KB Output is correct
9 Correct 512 ms 2640 KB Output is correct
10 Correct 893 ms 2896 KB Output is correct
11 Correct 935 ms 2896 KB Output is correct
12 Correct 893 ms 2896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2256 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 2 ms 2384 KB Output is correct
4 Correct 2 ms 2384 KB Output is correct
5 Correct 2 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 2 ms 2384 KB Output is correct
8 Correct 3 ms 2384 KB Output is correct
9 Correct 2 ms 2384 KB Output is correct
10 Correct 2 ms 2512 KB Output is correct
11 Correct 2 ms 2512 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 485 ms 7084 KB Output is correct
14 Correct 962 ms 11848 KB Output is correct
15 Correct 952 ms 11848 KB Output is correct
16 Correct 1000 ms 11812 KB Output is correct
17 Correct 795 ms 7028 KB Output is correct
18 Correct 895 ms 11876 KB Output is correct
19 Correct 922 ms 11856 KB Output is correct
20 Correct 771 ms 11812 KB Output is correct
21 Correct 512 ms 2640 KB Output is correct
22 Correct 893 ms 2896 KB Output is correct
23 Correct 935 ms 2896 KB Output is correct
24 Correct 893 ms 2896 KB Output is correct
25 Correct 984 ms 16680 KB Output is correct
26 Correct 947 ms 16836 KB Output is correct
27 Correct 1244 ms 16828 KB Output is correct
28 Correct 801 ms 16936 KB Output is correct
29 Correct 1076 ms 27804 KB Output is correct
30 Correct 1211 ms 27808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2256 KB Output is correct
2 Correct 1 ms 2256 KB Output is correct
3 Correct 2 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 2 ms 2384 KB Output is correct
7 Correct 2 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2256 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 2 ms 2384 KB Output is correct
12 Correct 2 ms 2384 KB Output is correct
13 Correct 2 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 2 ms 2384 KB Output is correct
16 Correct 3 ms 2384 KB Output is correct
17 Correct 2 ms 2384 KB Output is correct
18 Correct 2 ms 2512 KB Output is correct
19 Correct 2 ms 2512 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 2 ms 2384 KB Output is correct
22 Correct 2 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 2 ms 2384 KB Output is correct
25 Correct 2 ms 2384 KB Output is correct
26 Correct 2 ms 2384 KB Output is correct
27 Correct 2 ms 2384 KB Output is correct
28 Correct 2 ms 2384 KB Output is correct
29 Correct 2 ms 2384 KB Output is correct
30 Correct 1 ms 2384 KB Output is correct
31 Correct 2 ms 2512 KB Output is correct
32 Correct 2 ms 2384 KB Output is correct
33 Correct 2 ms 2384 KB Output is correct
34 Correct 1 ms 2384 KB Output is correct
35 Correct 2 ms 2384 KB Output is correct
36 Correct 2 ms 2512 KB Output is correct
37 Correct 2 ms 2512 KB Output is correct
38 Correct 2 ms 2512 KB Output is correct
39 Correct 2 ms 2384 KB Output is correct
40 Correct 1 ms 2384 KB Output is correct
41 Correct 2 ms 2384 KB Output is correct
42 Correct 1 ms 2384 KB Output is correct
43 Correct 529 ms 2768 KB Output is correct
44 Correct 890 ms 2768 KB Output is correct
45 Correct 809 ms 2788 KB Output is correct
46 Correct 742 ms 3024 KB Output is correct
47 Correct 739 ms 3024 KB Output is correct
48 Correct 917 ms 3024 KB Output is correct
49 Correct 824 ms 3024 KB Output is correct
50 Correct 738 ms 3024 KB Output is correct
51 Correct 807 ms 2768 KB Output is correct
52 Correct 923 ms 2768 KB Output is correct
53 Correct 436 ms 3280 KB Output is correct
54 Correct 811 ms 3024 KB Output is correct
55 Correct 746 ms 2896 KB Output is correct
56 Correct 691 ms 2768 KB Output is correct
57 Correct 830 ms 2640 KB Output is correct
58 Correct 835 ms 3536 KB Output is correct
59 Correct 702 ms 3664 KB Output is correct
60 Correct 792 ms 3664 KB Output is correct
61 Correct 803 ms 2896 KB Output is correct
62 Correct 933 ms 2640 KB Output is correct
63 Correct 745 ms 2640 KB Output is correct
64 Correct 697 ms 2768 KB Output is correct
65 Correct 472 ms 2640 KB Output is correct
66 Correct 788 ms 2896 KB Output is correct
67 Correct 885 ms 2896 KB Output is correct
68 Correct 767 ms 2896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2256 KB Output is correct
2 Correct 1 ms 2256 KB Output is correct
3 Correct 2 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 2 ms 2384 KB Output is correct
7 Correct 2 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2256 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 2 ms 2384 KB Output is correct
12 Correct 2 ms 2384 KB Output is correct
13 Correct 2 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 2 ms 2384 KB Output is correct
16 Correct 3 ms 2384 KB Output is correct
17 Correct 2 ms 2384 KB Output is correct
18 Correct 2 ms 2512 KB Output is correct
19 Correct 2 ms 2512 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 2 ms 2384 KB Output is correct
22 Correct 2 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 2 ms 2384 KB Output is correct
25 Correct 2 ms 2384 KB Output is correct
26 Correct 2 ms 2384 KB Output is correct
27 Correct 2 ms 2384 KB Output is correct
28 Correct 2 ms 2384 KB Output is correct
29 Correct 2 ms 2384 KB Output is correct
30 Correct 1 ms 2384 KB Output is correct
31 Correct 2 ms 2512 KB Output is correct
32 Correct 2 ms 2384 KB Output is correct
33 Correct 2 ms 2384 KB Output is correct
34 Correct 1 ms 2384 KB Output is correct
35 Correct 2 ms 2384 KB Output is correct
36 Correct 2 ms 2512 KB Output is correct
37 Correct 2 ms 2512 KB Output is correct
38 Correct 2 ms 2512 KB Output is correct
39 Correct 2 ms 2384 KB Output is correct
40 Correct 1 ms 2384 KB Output is correct
41 Correct 2 ms 2384 KB Output is correct
42 Correct 1 ms 2384 KB Output is correct
43 Correct 485 ms 7084 KB Output is correct
44 Correct 962 ms 11848 KB Output is correct
45 Correct 952 ms 11848 KB Output is correct
46 Correct 1000 ms 11812 KB Output is correct
47 Correct 795 ms 7028 KB Output is correct
48 Correct 895 ms 11876 KB Output is correct
49 Correct 922 ms 11856 KB Output is correct
50 Correct 771 ms 11812 KB Output is correct
51 Correct 512 ms 2640 KB Output is correct
52 Correct 893 ms 2896 KB Output is correct
53 Correct 935 ms 2896 KB Output is correct
54 Correct 893 ms 2896 KB Output is correct
55 Correct 984 ms 16680 KB Output is correct
56 Correct 947 ms 16836 KB Output is correct
57 Correct 1244 ms 16828 KB Output is correct
58 Correct 801 ms 16936 KB Output is correct
59 Correct 1076 ms 27804 KB Output is correct
60 Correct 1211 ms 27808 KB Output is correct
61 Correct 529 ms 2768 KB Output is correct
62 Correct 890 ms 2768 KB Output is correct
63 Correct 809 ms 2788 KB Output is correct
64 Correct 742 ms 3024 KB Output is correct
65 Correct 739 ms 3024 KB Output is correct
66 Correct 917 ms 3024 KB Output is correct
67 Correct 824 ms 3024 KB Output is correct
68 Correct 738 ms 3024 KB Output is correct
69 Correct 807 ms 2768 KB Output is correct
70 Correct 923 ms 2768 KB Output is correct
71 Correct 436 ms 3280 KB Output is correct
72 Correct 811 ms 3024 KB Output is correct
73 Correct 746 ms 2896 KB Output is correct
74 Correct 691 ms 2768 KB Output is correct
75 Correct 830 ms 2640 KB Output is correct
76 Correct 835 ms 3536 KB Output is correct
77 Correct 702 ms 3664 KB Output is correct
78 Correct 792 ms 3664 KB Output is correct
79 Correct 803 ms 2896 KB Output is correct
80 Correct 933 ms 2640 KB Output is correct
81 Correct 745 ms 2640 KB Output is correct
82 Correct 697 ms 2768 KB Output is correct
83 Correct 472 ms 2640 KB Output is correct
84 Correct 788 ms 2896 KB Output is correct
85 Correct 885 ms 2896 KB Output is correct
86 Correct 767 ms 2896 KB Output is correct
87 Correct 1 ms 2256 KB Output is correct
88 Correct 527 ms 15404 KB Output is correct
89 Correct 868 ms 11752 KB Output is correct
90 Correct 942 ms 11492 KB Output is correct
91 Correct 1129 ms 17060 KB Output is correct
92 Correct 857 ms 16968 KB Output is correct
93 Correct 952 ms 16960 KB Output is correct
94 Correct 861 ms 17076 KB Output is correct
95 Correct 837 ms 16968 KB Output is correct
96 Correct 855 ms 10688 KB Output is correct
97 Correct 870 ms 10688 KB Output is correct
98 Correct 831 ms 21048 KB Output is correct
99 Correct 910 ms 16940 KB Output is correct
100 Correct 820 ms 13000 KB Output is correct
101 Correct 954 ms 11560 KB Output is correct
102 Correct 833 ms 9544 KB Output is correct
103 Correct 1012 ms 27848 KB Output is correct
104 Correct 890 ms 29380 KB Output is correct
105 Correct 891 ms 29384 KB Output is correct
106 Correct 736 ms 13616 KB Output is correct
107 Correct 988 ms 10184 KB Output is correct
108 Correct 888 ms 10188 KB Output is correct
109 Correct 966 ms 9680 KB Output is correct