Submission #738521

# Submission time Handle Problem Language Result Execution time Memory
738521 2023-05-09T02:28:25 Z math_rabbit_1028 Digital Circuit (IOI22_circuit) C++17
46 / 100
3000 ms 7964 KB
#include "circuit.h"

#include <vector>
#include <bits/stdc++.h>
using namespace std;

int n, m, onoff[101010], par[202020];
vector<int> adj[202020];

const long long MOD = 1000002022;
long long cnt[202020], wgt[202020], sum[101010];

void get_cnt(int v) {
  if (v < n) cnt[v] = adj[v].size();
  else cnt[v] = 1;
  for (int i = 0; i < adj[v].size(); i++) {
    int next = adj[v][i];
    get_cnt(next);
    cnt[v] = (cnt[v] * cnt[next]) % MOD;
  }
}

long long get_wgt(int v, int goal) {
  if (v == goal) return 1;
  for (int i = 0; i < adj[v].size(); i++) {
    int next = adj[v][i];
    long long ret = get_wgt(next, goal);
    if (ret > 0) {
      for (int j = 0; j < adj[v].size(); j++) {
        if (i != j) ret = (ret * cnt[adj[v][j]]) % MOD;
      }
      return ret;
    }
  }
  return 0;
}

struct seg {
  long long tree[404040];
  int lazy[404040];
  vector<long long> arr;
  void init(int v, int st, int ed) {
    if (st == ed) {
      tree[v] = arr[st];
      lazy[v] = 0;
      return;
    }
    int mid = (st + ed) / 2;
    init(2 * v, st, mid);
    init(2 * v + 1, mid + 1, ed);
    tree[v] = (tree[2 * v] + tree[2 * v + 1]) % MOD;
  }
  void update(int v, int st, int ed, int gs, int ge) {
    if (lazy[v] % 2 == 1) {
      tree[v] = (sum[ed] - sum[st - 1] - tree[v] + 2 * MOD) % MOD;
      if (st != ed) {
        lazy[2 * v] += lazy[v];
        lazy[2 * v + 1] += lazy[v];
      }
      lazy[v] = 0;
    }
    if (gs > ed || ge < st) return;
    if (gs <= st && ed <= ge) {
      tree[v] = (sum[ed] - sum[st - 1] - tree[v] + 2 * MOD) % MOD;
      if (st != ed) {
        lazy[2 * v] += 1;
        lazy[2 * v + 1] += 1;
      }
      return;
    }
    int mid = (st + ed) / 2;
    update(2 * v, st, mid, gs, ge);
    update(2 * v + 1, mid + 1, ed, gs, ge);
    tree[v] = (tree[2 * v] + tree[2 * v + 1]) % MOD;
  }
  long long get(int v, int st, int ed, int gs, int ge) {
    if (lazy[v] % 2 == 1) {
      tree[v] = (sum[ed] - sum[st - 1] - tree[v] + 2 * MOD) % MOD;
      if (st != ed) {
        lazy[2 * v] += lazy[v];
        lazy[2 * v + 1] += lazy[v];
      }
      lazy[v] = 0;
    }
    if (gs > ed || ge < st) return 0;
    if (gs <= st && ed <= ge) return tree[v];
    int mid = (st + ed) / 2;
    return (get(2 * v, st, mid, gs, ge) + get(2 * v + 1, mid + 1, ed, gs, ge)) % MOD;
  }
} sumtree;

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
  n = N;
  m = M;
  for (int i = 0; i < n + m; i++) par[i] = P[i];
  for (int i = 0; i < m; i++) onoff[i] = A[i];

  for (int i = 1; i < n + m; i++) {
    adj[par[i]].push_back(i);
  }
  get_cnt(0);
  for (int i = n; i < n + m; i++) wgt[i] = get_wgt(0, i);
  for (int i = n; i < n + m; i++) sum[i] = (sum[i - 1] + wgt[i]) % MOD;

  for (int i = 0; i < n; i++) sumtree.arr.push_back(0);
  for (int i = n; i < n + m; i++) sumtree.arr.push_back(onoff[i - n] * wgt[i]);
  sumtree.init(1, n, n + m - 1);
}

int count_ways(int L, int R) {
  sumtree.update(1, n, n + m - 1, L, R);
  return (sumtree.get(1, n, n + m - 1, n, n + m - 1)) % MOD;
}

Compilation message

circuit.cpp: In function 'void get_cnt(int)':
circuit.cpp:16:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |   for (int i = 0; i < adj[v].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~
circuit.cpp: In function 'long long int get_wgt(int, int)':
circuit.cpp:25:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |   for (int i = 0; i < adj[v].size(); i++) {
      |                   ~~^~~~~~~~~~~~~~~
circuit.cpp:29:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |       for (int j = 0; j < adj[v].size(); j++) {
      |                       ~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5072 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 9 ms 5072 KB Output is correct
4 Correct 9 ms 5112 KB Output is correct
5 Correct 11 ms 5124 KB Output is correct
6 Correct 9 ms 5072 KB Output is correct
7 Correct 9 ms 5120 KB Output is correct
8 Correct 11 ms 5128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5072 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 7 ms 5072 KB Output is correct
4 Correct 4 ms 5072 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 6 ms 5200 KB Output is correct
7 Correct 11 ms 5200 KB Output is correct
8 Correct 11 ms 5172 KB Output is correct
9 Correct 10 ms 5164 KB Output is correct
10 Correct 13 ms 5300 KB Output is correct
11 Correct 12 ms 5308 KB Output is correct
12 Correct 7 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5072 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 9 ms 5072 KB Output is correct
4 Correct 9 ms 5112 KB Output is correct
5 Correct 11 ms 5124 KB Output is correct
6 Correct 9 ms 5072 KB Output is correct
7 Correct 9 ms 5120 KB Output is correct
8 Correct 11 ms 5128 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 7 ms 5072 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 4 ms 5072 KB Output is correct
14 Correct 6 ms 5200 KB Output is correct
15 Correct 11 ms 5200 KB Output is correct
16 Correct 11 ms 5172 KB Output is correct
17 Correct 10 ms 5164 KB Output is correct
18 Correct 13 ms 5300 KB Output is correct
19 Correct 12 ms 5308 KB Output is correct
20 Correct 7 ms 5200 KB Output is correct
21 Correct 8 ms 5152 KB Output is correct
22 Correct 5 ms 5140 KB Output is correct
23 Correct 7 ms 5200 KB Output is correct
24 Correct 10 ms 5240 KB Output is correct
25 Correct 10 ms 5160 KB Output is correct
26 Correct 10 ms 5200 KB Output is correct
27 Correct 10 ms 5164 KB Output is correct
28 Correct 10 ms 5200 KB Output is correct
29 Correct 9 ms 5072 KB Output is correct
30 Correct 10 ms 5200 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 11 ms 5200 KB Output is correct
33 Correct 8 ms 5140 KB Output is correct
34 Correct 7 ms 5200 KB Output is correct
35 Correct 7 ms 5072 KB Output is correct
36 Correct 15 ms 5200 KB Output is correct
37 Correct 16 ms 5228 KB Output is correct
38 Correct 15 ms 5232 KB Output is correct
39 Correct 5 ms 5200 KB Output is correct
40 Correct 7 ms 5132 KB Output is correct
41 Correct 7 ms 5200 KB Output is correct
42 Correct 7 ms 5124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3082 ms 7964 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3082 ms 7964 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5072 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 7 ms 5072 KB Output is correct
4 Correct 4 ms 5072 KB Output is correct
5 Correct 4 ms 5072 KB Output is correct
6 Correct 6 ms 5200 KB Output is correct
7 Correct 11 ms 5200 KB Output is correct
8 Correct 11 ms 5172 KB Output is correct
9 Correct 10 ms 5164 KB Output is correct
10 Correct 13 ms 5300 KB Output is correct
11 Correct 12 ms 5308 KB Output is correct
12 Correct 7 ms 5200 KB Output is correct
13 Execution timed out 3082 ms 7964 KB Time limit exceeded
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5072 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 9 ms 5072 KB Output is correct
4 Correct 9 ms 5112 KB Output is correct
5 Correct 11 ms 5124 KB Output is correct
6 Correct 9 ms 5072 KB Output is correct
7 Correct 9 ms 5120 KB Output is correct
8 Correct 11 ms 5128 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 7 ms 5072 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 4 ms 5072 KB Output is correct
14 Correct 6 ms 5200 KB Output is correct
15 Correct 11 ms 5200 KB Output is correct
16 Correct 11 ms 5172 KB Output is correct
17 Correct 10 ms 5164 KB Output is correct
18 Correct 13 ms 5300 KB Output is correct
19 Correct 12 ms 5308 KB Output is correct
20 Correct 7 ms 5200 KB Output is correct
21 Correct 8 ms 5152 KB Output is correct
22 Correct 5 ms 5140 KB Output is correct
23 Correct 7 ms 5200 KB Output is correct
24 Correct 10 ms 5240 KB Output is correct
25 Correct 10 ms 5160 KB Output is correct
26 Correct 10 ms 5200 KB Output is correct
27 Correct 10 ms 5164 KB Output is correct
28 Correct 10 ms 5200 KB Output is correct
29 Correct 9 ms 5072 KB Output is correct
30 Correct 10 ms 5200 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 11 ms 5200 KB Output is correct
33 Correct 8 ms 5140 KB Output is correct
34 Correct 7 ms 5200 KB Output is correct
35 Correct 7 ms 5072 KB Output is correct
36 Correct 15 ms 5200 KB Output is correct
37 Correct 16 ms 5228 KB Output is correct
38 Correct 15 ms 5232 KB Output is correct
39 Correct 5 ms 5200 KB Output is correct
40 Correct 7 ms 5132 KB Output is correct
41 Correct 7 ms 5200 KB Output is correct
42 Correct 7 ms 5124 KB Output is correct
43 Correct 764 ms 5688 KB Output is correct
44 Correct 987 ms 5616 KB Output is correct
45 Correct 1113 ms 5592 KB Output is correct
46 Correct 1246 ms 6016 KB Output is correct
47 Correct 1103 ms 5880 KB Output is correct
48 Correct 1304 ms 5948 KB Output is correct
49 Correct 1347 ms 5956 KB Output is correct
50 Correct 997 ms 5872 KB Output is correct
51 Correct 1073 ms 5616 KB Output is correct
52 Correct 980 ms 5624 KB Output is correct
53 Correct 699 ms 5712 KB Output is correct
54 Correct 1306 ms 6004 KB Output is correct
55 Correct 1128 ms 5756 KB Output is correct
56 Correct 919 ms 5736 KB Output is correct
57 Correct 1064 ms 5624 KB Output is correct
58 Correct 1245 ms 6164 KB Output is correct
59 Correct 1223 ms 6216 KB Output is correct
60 Correct 1320 ms 6360 KB Output is correct
61 Correct 943 ms 5548 KB Output is correct
62 Correct 1000 ms 5560 KB Output is correct
63 Correct 884 ms 5532 KB Output is correct
64 Correct 1102 ms 5632 KB Output is correct
65 Correct 521 ms 5304 KB Output is correct
66 Correct 1051 ms 5696 KB Output is correct
67 Correct 975 ms 5792 KB Output is correct
68 Correct 892 ms 5692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 5072 KB Output is correct
2 Correct 3 ms 5072 KB Output is correct
3 Correct 9 ms 5072 KB Output is correct
4 Correct 9 ms 5112 KB Output is correct
5 Correct 11 ms 5124 KB Output is correct
6 Correct 9 ms 5072 KB Output is correct
7 Correct 9 ms 5120 KB Output is correct
8 Correct 11 ms 5128 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5072 KB Output is correct
11 Correct 7 ms 5072 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 4 ms 5072 KB Output is correct
14 Correct 6 ms 5200 KB Output is correct
15 Correct 11 ms 5200 KB Output is correct
16 Correct 11 ms 5172 KB Output is correct
17 Correct 10 ms 5164 KB Output is correct
18 Correct 13 ms 5300 KB Output is correct
19 Correct 12 ms 5308 KB Output is correct
20 Correct 7 ms 5200 KB Output is correct
21 Correct 8 ms 5152 KB Output is correct
22 Correct 5 ms 5140 KB Output is correct
23 Correct 7 ms 5200 KB Output is correct
24 Correct 10 ms 5240 KB Output is correct
25 Correct 10 ms 5160 KB Output is correct
26 Correct 10 ms 5200 KB Output is correct
27 Correct 10 ms 5164 KB Output is correct
28 Correct 10 ms 5200 KB Output is correct
29 Correct 9 ms 5072 KB Output is correct
30 Correct 10 ms 5200 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 11 ms 5200 KB Output is correct
33 Correct 8 ms 5140 KB Output is correct
34 Correct 7 ms 5200 KB Output is correct
35 Correct 7 ms 5072 KB Output is correct
36 Correct 15 ms 5200 KB Output is correct
37 Correct 16 ms 5228 KB Output is correct
38 Correct 15 ms 5232 KB Output is correct
39 Correct 5 ms 5200 KB Output is correct
40 Correct 7 ms 5132 KB Output is correct
41 Correct 7 ms 5200 KB Output is correct
42 Correct 7 ms 5124 KB Output is correct
43 Execution timed out 3082 ms 7964 KB Time limit exceeded
44 Halted 0 ms 0 KB -