답안 #628553

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
628553 2022-08-13T13:26:23 Z 600Mihnea 디지털 회로 (IOI22_circuit) C++17
89 / 100
3000 ms 24532 KB
#include "circuit.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
const int MOD = 1000002022;

int add(int a, int b) {
  a += b;
  if (a >= MOD) return a - MOD;
  if (a < 0) return a + MOD;
  return a;
}

int mul(int a, int b) {
  return a * (ll) b % MOD;
}

void addup(int &a, int b) {
  a = add(a, b);
}

void mulup(int &a, int b) {
  a = mul(a, b);
}

struct Vertex {
  int s0, s1;
};

Vertex operator + (Vertex a, Vertex b) {
  return {add(a.s0, b.s0), add(a.s1, b.s1)};
}

vector<int> c, now;
int dim, subtract;
vector<Vertex> tree;
vector<int> lazy;

void build(int v, int tl, int tr) {
  lazy[v] = 0;

  if (tl == tr) {
    tree[v].s0 = now[tl] * c[tl];
    tree[v].s1 = (1 - now[tl]) * c[tl];
  } else {
    int tm = (tl + tr) / 2;
    build(2 * v, tl, tm);
    build(2 * v + 1, tm + 1, tr);
    tree[v] = tree[2 * v] + tree[2 * v + 1];
  }
}

void push(int v, int tl, int tr) {
  if (lazy[v]) {
    swap(tree[v].s0, tree[v].s1);
    if (tl < tr) lazy[2 * v] ^= 1, lazy[2 * v + 1] ^= 1;
    lazy[v] = 0;
  }
}

void op(int v, int tl, int tr, int l, int r) {
  push(v, tl, tr);
  if (tr < l || r < tl) return;
  if (l <= tl && tr <= r) {
    lazy[v] ^= 1;
    push(v, tl, tr);
    return;
  }
  int tm = (tl + tr) / 2;
  op(2 * v, tl, tm, l, r);
  op(2 * v + 1, tm + 1, tr, l, r);
  tree[v] = tree[2 * v] + tree[2 * v + 1];
}

void init(int n, int m, std::vector<int> par, std::vector<int> init) {
  dim = m;
  tree.resize(4 * dim + 7);
  lazy.resize(4 * dim + 7);
  subtract = n;
  c.resize(m, 0);
  ///cout << n << " " << m << " : " << (int) par.size() << " vs " << (int) init.size() << "\n";
  vector<vector<int>> g(n + m);
  vector<int> prod(n + m, 1);
  for (int i = 1; i < n + m; i++) {
    g[par[i]].push_back(i);
  }
  function<void(int)> build1 = [&] (int a) {
    if (g[a].empty()) return;
    prod[a] = (int) g[a].size();
    for (auto &b : g[a]) {
      build1(b);
      mulup(prod[a], prod[b]);
    }
  };
  now = init;
  function<void(int, int)> dfs = [&] (int a, int coef) {
    /// optimize this function
    for (int i = 0; i < (int) g[a].size(); i++) {
      int send = coef;
      for (int j = 0; j < (int) g[a].size(); j++) {
        if (i != j) {
          mulup(send, prod[g[a][j]]);
        }
      }
      dfs(g[a][i], send);
    }
    if (g[a].empty()) {
      assert(n + 0 <= a && a < n + m);
      c[a - n] = coef;
    }
  };
  build1(0);
  dfs(0, 1);
  build(1, 0, dim - 1);
}

int count_ways(int l, int r) {
  l -= subtract;
  r -= subtract;
  op(1, 0, dim - 1, l, r);
  push(1, 0, dim - 1);
  return tree[1].s0;
}


# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 6 ms 336 KB Output is correct
4 Correct 6 ms 336 KB Output is correct
5 Correct 6 ms 336 KB Output is correct
6 Correct 6 ms 336 KB Output is correct
7 Correct 6 ms 404 KB Output is correct
8 Correct 5 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 6 ms 336 KB Output is correct
4 Correct 6 ms 336 KB Output is correct
5 Correct 6 ms 336 KB Output is correct
6 Correct 6 ms 336 KB Output is correct
7 Correct 6 ms 404 KB Output is correct
8 Correct 5 ms 336 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 5 ms 336 KB Output is correct
30 Correct 5 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 2 ms 336 KB Output is correct
36 Correct 1 ms 464 KB Output is correct
37 Correct 6 ms 464 KB Output is correct
38 Correct 7 ms 536 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 610 ms 5724 KB Output is correct
2 Correct 909 ms 11036 KB Output is correct
3 Correct 908 ms 11092 KB Output is correct
4 Correct 987 ms 11080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 610 ms 5724 KB Output is correct
2 Correct 909 ms 11036 KB Output is correct
3 Correct 908 ms 11092 KB Output is correct
4 Correct 987 ms 11080 KB Output is correct
5 Correct 760 ms 5576 KB Output is correct
6 Correct 852 ms 11040 KB Output is correct
7 Correct 866 ms 11080 KB Output is correct
8 Correct 710 ms 11036 KB Output is correct
9 Correct 511 ms 592 KB Output is correct
10 Correct 944 ms 848 KB Output is correct
11 Correct 774 ms 976 KB Output is correct
12 Correct 866 ms 976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 610 ms 5724 KB Output is correct
14 Correct 909 ms 11036 KB Output is correct
15 Correct 908 ms 11092 KB Output is correct
16 Correct 987 ms 11080 KB Output is correct
17 Correct 760 ms 5576 KB Output is correct
18 Correct 852 ms 11040 KB Output is correct
19 Correct 866 ms 11080 KB Output is correct
20 Correct 710 ms 11036 KB Output is correct
21 Correct 511 ms 592 KB Output is correct
22 Correct 944 ms 848 KB Output is correct
23 Correct 774 ms 976 KB Output is correct
24 Correct 866 ms 976 KB Output is correct
25 Correct 894 ms 16344 KB Output is correct
26 Correct 1054 ms 16652 KB Output is correct
27 Correct 1051 ms 16712 KB Output is correct
28 Correct 756 ms 16660 KB Output is correct
29 Correct 912 ms 24508 KB Output is correct
30 Correct 867 ms 24532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 6 ms 336 KB Output is correct
4 Correct 6 ms 336 KB Output is correct
5 Correct 6 ms 336 KB Output is correct
6 Correct 6 ms 336 KB Output is correct
7 Correct 6 ms 404 KB Output is correct
8 Correct 5 ms 336 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 5 ms 336 KB Output is correct
30 Correct 5 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 2 ms 336 KB Output is correct
36 Correct 1 ms 464 KB Output is correct
37 Correct 6 ms 464 KB Output is correct
38 Correct 7 ms 536 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 612 ms 720 KB Output is correct
44 Correct 923 ms 720 KB Output is correct
45 Correct 906 ms 720 KB Output is correct
46 Correct 928 ms 1104 KB Output is correct
47 Correct 964 ms 1104 KB Output is correct
48 Correct 700 ms 1104 KB Output is correct
49 Correct 854 ms 1104 KB Output is correct
50 Correct 833 ms 1104 KB Output is correct
51 Correct 917 ms 720 KB Output is correct
52 Correct 1035 ms 816 KB Output is correct
53 Correct 670 ms 976 KB Output is correct
54 Correct 953 ms 1104 KB Output is correct
55 Correct 899 ms 848 KB Output is correct
56 Correct 845 ms 848 KB Output is correct
57 Correct 715 ms 724 KB Output is correct
58 Correct 924 ms 1488 KB Output is correct
59 Correct 971 ms 1528 KB Output is correct
60 Correct 997 ms 1528 KB Output is correct
61 Correct 813 ms 848 KB Output is correct
62 Correct 953 ms 720 KB Output is correct
63 Correct 929 ms 720 KB Output is correct
64 Correct 828 ms 720 KB Output is correct
65 Correct 411 ms 592 KB Output is correct
66 Correct 922 ms 848 KB Output is correct
67 Correct 950 ms 976 KB Output is correct
68 Correct 859 ms 976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Output is correct
2 Correct 1 ms 208 KB Output is correct
3 Correct 6 ms 336 KB Output is correct
4 Correct 6 ms 336 KB Output is correct
5 Correct 6 ms 336 KB Output is correct
6 Correct 6 ms 336 KB Output is correct
7 Correct 6 ms 404 KB Output is correct
8 Correct 5 ms 336 KB Output is correct
9 Correct 0 ms 208 KB Output is correct
10 Correct 1 ms 208 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 336 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
19 Correct 1 ms 464 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 336 KB Output is correct
29 Correct 5 ms 336 KB Output is correct
30 Correct 5 ms 336 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 336 KB Output is correct
33 Correct 1 ms 336 KB Output is correct
34 Correct 1 ms 336 KB Output is correct
35 Correct 2 ms 336 KB Output is correct
36 Correct 1 ms 464 KB Output is correct
37 Correct 6 ms 464 KB Output is correct
38 Correct 7 ms 536 KB Output is correct
39 Correct 1 ms 336 KB Output is correct
40 Correct 1 ms 336 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 336 KB Output is correct
43 Correct 610 ms 5724 KB Output is correct
44 Correct 909 ms 11036 KB Output is correct
45 Correct 908 ms 11092 KB Output is correct
46 Correct 987 ms 11080 KB Output is correct
47 Correct 760 ms 5576 KB Output is correct
48 Correct 852 ms 11040 KB Output is correct
49 Correct 866 ms 11080 KB Output is correct
50 Correct 710 ms 11036 KB Output is correct
51 Correct 511 ms 592 KB Output is correct
52 Correct 944 ms 848 KB Output is correct
53 Correct 774 ms 976 KB Output is correct
54 Correct 866 ms 976 KB Output is correct
55 Correct 894 ms 16344 KB Output is correct
56 Correct 1054 ms 16652 KB Output is correct
57 Correct 1051 ms 16712 KB Output is correct
58 Correct 756 ms 16660 KB Output is correct
59 Correct 912 ms 24508 KB Output is correct
60 Correct 867 ms 24532 KB Output is correct
61 Correct 612 ms 720 KB Output is correct
62 Correct 923 ms 720 KB Output is correct
63 Correct 906 ms 720 KB Output is correct
64 Correct 928 ms 1104 KB Output is correct
65 Correct 964 ms 1104 KB Output is correct
66 Correct 700 ms 1104 KB Output is correct
67 Correct 854 ms 1104 KB Output is correct
68 Correct 833 ms 1104 KB Output is correct
69 Correct 917 ms 720 KB Output is correct
70 Correct 1035 ms 816 KB Output is correct
71 Correct 670 ms 976 KB Output is correct
72 Correct 953 ms 1104 KB Output is correct
73 Correct 899 ms 848 KB Output is correct
74 Correct 845 ms 848 KB Output is correct
75 Correct 715 ms 724 KB Output is correct
76 Correct 924 ms 1488 KB Output is correct
77 Correct 971 ms 1528 KB Output is correct
78 Correct 997 ms 1528 KB Output is correct
79 Correct 813 ms 848 KB Output is correct
80 Correct 953 ms 720 KB Output is correct
81 Correct 929 ms 720 KB Output is correct
82 Correct 828 ms 720 KB Output is correct
83 Correct 411 ms 592 KB Output is correct
84 Correct 922 ms 848 KB Output is correct
85 Correct 950 ms 976 KB Output is correct
86 Correct 859 ms 976 KB Output is correct
87 Correct 0 ms 208 KB Output is correct
88 Correct 648 ms 14616 KB Output is correct
89 Correct 1036 ms 10328 KB Output is correct
90 Correct 863 ms 10268 KB Output is correct
91 Correct 1012 ms 16828 KB Output is correct
92 Correct 1012 ms 16824 KB Output is correct
93 Correct 968 ms 16796 KB Output is correct
94 Correct 980 ms 16796 KB Output is correct
95 Correct 870 ms 16856 KB Output is correct
96 Execution timed out 3069 ms 10564 KB Time limit exceeded
97 Halted 0 ms 0 KB -