답안 #659865

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
659865 2022-11-19T14:34:15 Z peijar 디지털 회로 (IOI22_circuit) C++17
100 / 100
1241 ms 60336 KB
#include "circuit.h"
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int MOD = (int)1e9 + 2022;
const int MAX = 1e6;

int par[MAX];
vector<int> childs[MAX];
int cntParams[MAX];
int nbInternes, nbFeuilles;

int coeff[MAX];

int iDeb[MAX], iFin[MAX];
int sum[MAX], sumCoeffs[MAX], lazy[MAX];

void pull(int node) {
  sum[node] = sum[2 * node] + sum[2 * node + 1];
  if (sum[node] >= MOD)
    sum[node] -= MOD;
}

void push(int node) {
  if (!lazy[node])
    return;
  sum[node] = sumCoeffs[node] - sum[node];
  if (sum[node] < 0)
    sum[node] += MOD;
  if (iDeb[node] < iFin[node])
    lazy[2 * node] ^= 1, lazy[2 * node + 1] ^= 1;
  lazy[node] = 0;
}

void initSeg(int node, int l, int r, vector<signed> &valInit) {
  iDeb[node] = l, iFin[node] = r;
  if (l == r) {
    sumCoeffs[node] = coeff[l];
    sum[node] = valInit[l] * coeff[l];
    return;
  }
  initSeg(2 * node, l, (l + r) / 2, valInit);
  initSeg(2 * node + 1, (l + r) / 2 + 1, r, valInit);
  pull(node);
  sumCoeffs[node] = sumCoeffs[2 * node] + sumCoeffs[2 * node + 1];
  if (sumCoeffs[node] >= MOD)
    sumCoeffs[node] -= MOD;
}

void upd(int node, int l, int r) {
  push(node);
  if (l > iFin[node] or r < iDeb[node])
    return;
  if (l <= iDeb[node] and r >= iFin[node]) {
    lazy[node] ^= 1;
    push(node);
    return;
  }
  upd(2 * node, l, r);
  upd(2 * node + 1, l, r);
  pull(node);
}

void setParams(int u) {
  if (childs[u].empty()) {
    cntParams[u] = 1;
    return;
  }
  cntParams[u] = childs[u].size();
  for (int v : childs[u]) {
    setParams(v);
    cntParams[u] = cntParams[u] * cntParams[v] % MOD;
  }
}

void setCoeffs(int u, int bef) {
  if (u >= nbInternes) {
    coeff[u - nbInternes] = bef;
    return;
  }

  int deg = childs[u].size();
  vector<int> prefProd(deg + 1, 1), suffProd(deg + 1, 1);
  for (int i = 0; i < deg; ++i)
    prefProd[i + 1] = prefProd[i] * cntParams[childs[u][i]] % MOD;
  for (int i = deg - 1; i >= 0; --i)
    suffProd[i] = suffProd[i + 1] * cntParams[childs[u][i]] % MOD;

  for (int i = 0; i < deg; ++i)
    setCoeffs(childs[u][i], bef * prefProd[i] % MOD * suffProd[i + 1] % MOD);
}

void init(signed N, signed M, vector<signed> P, std::vector<signed> A) {
  nbInternes = N, nbFeuilles = M;
  int nbSommets = N + M;
  for (int i = 1; i < nbSommets; ++i)
    childs[P[i]].push_back(i);

  for (int i = nbSommets - 1; i >= 0; --i) {
    if (i >= nbInternes)
      cntParams[i] = 1;
    else {
      cntParams[i] = childs[i].size();
      for (int j : childs[i])
        if (j < nbInternes)
          cntParams[i] = cntParams[i] * cntParams[j] % MOD;
    }
  }
  setCoeffs(0, 1);
  initSeg(1, 0, nbFeuilles - 1, A);
}

signed count_ways(signed L, signed R) {
  L -= nbInternes, R -= nbInternes;
  upd(1, L, R);
  return sum[1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23788 KB Output is correct
2 Correct 14 ms 23760 KB Output is correct
3 Correct 13 ms 23888 KB Output is correct
4 Correct 14 ms 23864 KB Output is correct
5 Correct 18 ms 23888 KB Output is correct
6 Correct 16 ms 23888 KB Output is correct
7 Correct 17 ms 23888 KB Output is correct
8 Correct 13 ms 23888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23772 KB Output is correct
2 Correct 15 ms 23888 KB Output is correct
3 Correct 15 ms 23872 KB Output is correct
4 Correct 14 ms 23888 KB Output is correct
5 Correct 17 ms 23936 KB Output is correct
6 Correct 13 ms 23896 KB Output is correct
7 Correct 14 ms 23940 KB Output is correct
8 Correct 14 ms 23896 KB Output is correct
9 Correct 14 ms 23888 KB Output is correct
10 Correct 15 ms 24144 KB Output is correct
11 Correct 14 ms 24144 KB Output is correct
12 Correct 18 ms 23864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23788 KB Output is correct
2 Correct 14 ms 23760 KB Output is correct
3 Correct 13 ms 23888 KB Output is correct
4 Correct 14 ms 23864 KB Output is correct
5 Correct 18 ms 23888 KB Output is correct
6 Correct 16 ms 23888 KB Output is correct
7 Correct 17 ms 23888 KB Output is correct
8 Correct 13 ms 23888 KB Output is correct
9 Correct 16 ms 23772 KB Output is correct
10 Correct 15 ms 23888 KB Output is correct
11 Correct 15 ms 23872 KB Output is correct
12 Correct 14 ms 23888 KB Output is correct
13 Correct 17 ms 23936 KB Output is correct
14 Correct 13 ms 23896 KB Output is correct
15 Correct 14 ms 23940 KB Output is correct
16 Correct 14 ms 23896 KB Output is correct
17 Correct 14 ms 23888 KB Output is correct
18 Correct 15 ms 24144 KB Output is correct
19 Correct 14 ms 24144 KB Output is correct
20 Correct 18 ms 23864 KB Output is correct
21 Correct 16 ms 23888 KB Output is correct
22 Correct 13 ms 23824 KB Output is correct
23 Correct 15 ms 23888 KB Output is correct
24 Correct 15 ms 23888 KB Output is correct
25 Correct 18 ms 24012 KB Output is correct
26 Correct 14 ms 23972 KB Output is correct
27 Correct 15 ms 23888 KB Output is correct
28 Correct 17 ms 23888 KB Output is correct
29 Correct 15 ms 23888 KB Output is correct
30 Correct 18 ms 23888 KB Output is correct
31 Correct 15 ms 24016 KB Output is correct
32 Correct 15 ms 23912 KB Output is correct
33 Correct 14 ms 23932 KB Output is correct
34 Correct 14 ms 23888 KB Output is correct
35 Correct 16 ms 23976 KB Output is correct
36 Correct 19 ms 24136 KB Output is correct
37 Correct 18 ms 24212 KB Output is correct
38 Correct 18 ms 24144 KB Output is correct
39 Correct 17 ms 23888 KB Output is correct
40 Correct 19 ms 23908 KB Output is correct
41 Correct 15 ms 23936 KB Output is correct
42 Correct 16 ms 23888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 729 ms 28424 KB Output is correct
2 Correct 967 ms 33000 KB Output is correct
3 Correct 662 ms 32976 KB Output is correct
4 Correct 1109 ms 33060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 729 ms 28424 KB Output is correct
2 Correct 967 ms 33000 KB Output is correct
3 Correct 662 ms 32976 KB Output is correct
4 Correct 1109 ms 33060 KB Output is correct
5 Correct 722 ms 28604 KB Output is correct
6 Correct 951 ms 33344 KB Output is correct
7 Correct 869 ms 33348 KB Output is correct
8 Correct 917 ms 32988 KB Output is correct
9 Correct 382 ms 24144 KB Output is correct
10 Correct 984 ms 24456 KB Output is correct
11 Correct 851 ms 24448 KB Output is correct
12 Correct 886 ms 24400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23772 KB Output is correct
2 Correct 15 ms 23888 KB Output is correct
3 Correct 15 ms 23872 KB Output is correct
4 Correct 14 ms 23888 KB Output is correct
5 Correct 17 ms 23936 KB Output is correct
6 Correct 13 ms 23896 KB Output is correct
7 Correct 14 ms 23940 KB Output is correct
8 Correct 14 ms 23896 KB Output is correct
9 Correct 14 ms 23888 KB Output is correct
10 Correct 15 ms 24144 KB Output is correct
11 Correct 14 ms 24144 KB Output is correct
12 Correct 18 ms 23864 KB Output is correct
13 Correct 729 ms 28424 KB Output is correct
14 Correct 967 ms 33000 KB Output is correct
15 Correct 662 ms 32976 KB Output is correct
16 Correct 1109 ms 33060 KB Output is correct
17 Correct 722 ms 28604 KB Output is correct
18 Correct 951 ms 33344 KB Output is correct
19 Correct 869 ms 33348 KB Output is correct
20 Correct 917 ms 32988 KB Output is correct
21 Correct 382 ms 24144 KB Output is correct
22 Correct 984 ms 24456 KB Output is correct
23 Correct 851 ms 24448 KB Output is correct
24 Correct 886 ms 24400 KB Output is correct
25 Correct 1106 ms 40692 KB Output is correct
26 Correct 1099 ms 40876 KB Output is correct
27 Correct 1006 ms 40764 KB Output is correct
28 Correct 834 ms 39880 KB Output is correct
29 Correct 930 ms 59544 KB Output is correct
30 Correct 941 ms 58600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23788 KB Output is correct
2 Correct 14 ms 23760 KB Output is correct
3 Correct 13 ms 23888 KB Output is correct
4 Correct 14 ms 23864 KB Output is correct
5 Correct 18 ms 23888 KB Output is correct
6 Correct 16 ms 23888 KB Output is correct
7 Correct 17 ms 23888 KB Output is correct
8 Correct 13 ms 23888 KB Output is correct
9 Correct 16 ms 23772 KB Output is correct
10 Correct 15 ms 23888 KB Output is correct
11 Correct 15 ms 23872 KB Output is correct
12 Correct 14 ms 23888 KB Output is correct
13 Correct 17 ms 23936 KB Output is correct
14 Correct 13 ms 23896 KB Output is correct
15 Correct 14 ms 23940 KB Output is correct
16 Correct 14 ms 23896 KB Output is correct
17 Correct 14 ms 23888 KB Output is correct
18 Correct 15 ms 24144 KB Output is correct
19 Correct 14 ms 24144 KB Output is correct
20 Correct 18 ms 23864 KB Output is correct
21 Correct 16 ms 23888 KB Output is correct
22 Correct 13 ms 23824 KB Output is correct
23 Correct 15 ms 23888 KB Output is correct
24 Correct 15 ms 23888 KB Output is correct
25 Correct 18 ms 24012 KB Output is correct
26 Correct 14 ms 23972 KB Output is correct
27 Correct 15 ms 23888 KB Output is correct
28 Correct 17 ms 23888 KB Output is correct
29 Correct 15 ms 23888 KB Output is correct
30 Correct 18 ms 23888 KB Output is correct
31 Correct 15 ms 24016 KB Output is correct
32 Correct 15 ms 23912 KB Output is correct
33 Correct 14 ms 23932 KB Output is correct
34 Correct 14 ms 23888 KB Output is correct
35 Correct 16 ms 23976 KB Output is correct
36 Correct 19 ms 24136 KB Output is correct
37 Correct 18 ms 24212 KB Output is correct
38 Correct 18 ms 24144 KB Output is correct
39 Correct 17 ms 23888 KB Output is correct
40 Correct 19 ms 23908 KB Output is correct
41 Correct 15 ms 23936 KB Output is correct
42 Correct 16 ms 23888 KB Output is correct
43 Correct 692 ms 24400 KB Output is correct
44 Correct 967 ms 24312 KB Output is correct
45 Correct 1112 ms 24400 KB Output is correct
46 Correct 797 ms 24784 KB Output is correct
47 Correct 877 ms 24864 KB Output is correct
48 Correct 854 ms 24848 KB Output is correct
49 Correct 1060 ms 24852 KB Output is correct
50 Correct 801 ms 24784 KB Output is correct
51 Correct 870 ms 24656 KB Output is correct
52 Correct 805 ms 24768 KB Output is correct
53 Correct 739 ms 24912 KB Output is correct
54 Correct 865 ms 24860 KB Output is correct
55 Correct 1002 ms 24784 KB Output is correct
56 Correct 949 ms 24656 KB Output is correct
57 Correct 767 ms 24656 KB Output is correct
58 Correct 890 ms 25808 KB Output is correct
59 Correct 1002 ms 25844 KB Output is correct
60 Correct 796 ms 25772 KB Output is correct
61 Correct 961 ms 24528 KB Output is correct
62 Correct 1241 ms 24272 KB Output is correct
63 Correct 891 ms 24388 KB Output is correct
64 Correct 821 ms 24668 KB Output is correct
65 Correct 540 ms 24144 KB Output is correct
66 Correct 906 ms 24436 KB Output is correct
67 Correct 707 ms 24444 KB Output is correct
68 Correct 938 ms 24400 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23788 KB Output is correct
2 Correct 14 ms 23760 KB Output is correct
3 Correct 13 ms 23888 KB Output is correct
4 Correct 14 ms 23864 KB Output is correct
5 Correct 18 ms 23888 KB Output is correct
6 Correct 16 ms 23888 KB Output is correct
7 Correct 17 ms 23888 KB Output is correct
8 Correct 13 ms 23888 KB Output is correct
9 Correct 16 ms 23772 KB Output is correct
10 Correct 15 ms 23888 KB Output is correct
11 Correct 15 ms 23872 KB Output is correct
12 Correct 14 ms 23888 KB Output is correct
13 Correct 17 ms 23936 KB Output is correct
14 Correct 13 ms 23896 KB Output is correct
15 Correct 14 ms 23940 KB Output is correct
16 Correct 14 ms 23896 KB Output is correct
17 Correct 14 ms 23888 KB Output is correct
18 Correct 15 ms 24144 KB Output is correct
19 Correct 14 ms 24144 KB Output is correct
20 Correct 18 ms 23864 KB Output is correct
21 Correct 16 ms 23888 KB Output is correct
22 Correct 13 ms 23824 KB Output is correct
23 Correct 15 ms 23888 KB Output is correct
24 Correct 15 ms 23888 KB Output is correct
25 Correct 18 ms 24012 KB Output is correct
26 Correct 14 ms 23972 KB Output is correct
27 Correct 15 ms 23888 KB Output is correct
28 Correct 17 ms 23888 KB Output is correct
29 Correct 15 ms 23888 KB Output is correct
30 Correct 18 ms 23888 KB Output is correct
31 Correct 15 ms 24016 KB Output is correct
32 Correct 15 ms 23912 KB Output is correct
33 Correct 14 ms 23932 KB Output is correct
34 Correct 14 ms 23888 KB Output is correct
35 Correct 16 ms 23976 KB Output is correct
36 Correct 19 ms 24136 KB Output is correct
37 Correct 18 ms 24212 KB Output is correct
38 Correct 18 ms 24144 KB Output is correct
39 Correct 17 ms 23888 KB Output is correct
40 Correct 19 ms 23908 KB Output is correct
41 Correct 15 ms 23936 KB Output is correct
42 Correct 16 ms 23888 KB Output is correct
43 Correct 729 ms 28424 KB Output is correct
44 Correct 967 ms 33000 KB Output is correct
45 Correct 662 ms 32976 KB Output is correct
46 Correct 1109 ms 33060 KB Output is correct
47 Correct 722 ms 28604 KB Output is correct
48 Correct 951 ms 33344 KB Output is correct
49 Correct 869 ms 33348 KB Output is correct
50 Correct 917 ms 32988 KB Output is correct
51 Correct 382 ms 24144 KB Output is correct
52 Correct 984 ms 24456 KB Output is correct
53 Correct 851 ms 24448 KB Output is correct
54 Correct 886 ms 24400 KB Output is correct
55 Correct 1106 ms 40692 KB Output is correct
56 Correct 1099 ms 40876 KB Output is correct
57 Correct 1006 ms 40764 KB Output is correct
58 Correct 834 ms 39880 KB Output is correct
59 Correct 930 ms 59544 KB Output is correct
60 Correct 941 ms 58600 KB Output is correct
61 Correct 692 ms 24400 KB Output is correct
62 Correct 967 ms 24312 KB Output is correct
63 Correct 1112 ms 24400 KB Output is correct
64 Correct 797 ms 24784 KB Output is correct
65 Correct 877 ms 24864 KB Output is correct
66 Correct 854 ms 24848 KB Output is correct
67 Correct 1060 ms 24852 KB Output is correct
68 Correct 801 ms 24784 KB Output is correct
69 Correct 870 ms 24656 KB Output is correct
70 Correct 805 ms 24768 KB Output is correct
71 Correct 739 ms 24912 KB Output is correct
72 Correct 865 ms 24860 KB Output is correct
73 Correct 1002 ms 24784 KB Output is correct
74 Correct 949 ms 24656 KB Output is correct
75 Correct 767 ms 24656 KB Output is correct
76 Correct 890 ms 25808 KB Output is correct
77 Correct 1002 ms 25844 KB Output is correct
78 Correct 796 ms 25772 KB Output is correct
79 Correct 961 ms 24528 KB Output is correct
80 Correct 1241 ms 24272 KB Output is correct
81 Correct 891 ms 24388 KB Output is correct
82 Correct 821 ms 24668 KB Output is correct
83 Correct 540 ms 24144 KB Output is correct
84 Correct 906 ms 24436 KB Output is correct
85 Correct 707 ms 24444 KB Output is correct
86 Correct 938 ms 24400 KB Output is correct
87 Correct 13 ms 23760 KB Output is correct
88 Correct 585 ms 40560 KB Output is correct
89 Correct 999 ms 33532 KB Output is correct
90 Correct 818 ms 33556 KB Output is correct
91 Correct 903 ms 40872 KB Output is correct
92 Correct 1155 ms 41420 KB Output is correct
93 Correct 942 ms 41520 KB Output is correct
94 Correct 1042 ms 41384 KB Output is correct
95 Correct 977 ms 40448 KB Output is correct
96 Correct 915 ms 36052 KB Output is correct
97 Correct 958 ms 37376 KB Output is correct
98 Correct 932 ms 47276 KB Output is correct
99 Correct 1016 ms 40772 KB Output is correct
100 Correct 1115 ms 39664 KB Output is correct
101 Correct 1039 ms 38868 KB Output is correct
102 Correct 980 ms 37460 KB Output is correct
103 Correct 982 ms 59576 KB Output is correct
104 Correct 1056 ms 60336 KB Output is correct
105 Correct 1004 ms 59428 KB Output is correct
106 Correct 1060 ms 37636 KB Output is correct
107 Correct 936 ms 37848 KB Output is correct
108 Correct 989 ms 38056 KB Output is correct
109 Correct 1025 ms 37696 KB Output is correct