Submission #629924

# Submission time Handle Problem Language Result Execution time Memory
629924 2022-08-15T11:03:09 Z cadmiumsky Digital Circuit (IOI22_circuit) C++17
100 / 100
1157 ms 40028 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int nmax = 1e5 + 5, mod = 1e9 + 2022;
int n, m;
int cost[nmax];

namespace AINT {
  int aint[nmax * 4], inv[nmax * 4], lazy[nmax * 4];
  int init(int node = 1, int cl = 0, int cr = m - 1) {
    lazy[node] = 0;
    inv[node] = 0;
    if(cl == cr) {
      aint[node] = cost[cl];
      return aint[node];
    }
    int mid = cl + cr >> 1;
    return aint[node] = (init(2 * node, cl, mid) + init(2 * node + 1, mid + 1, cr)) % mod;
  }
  void push(int node, bool to) {
    if(lazy[node])
      swap(aint[node], inv[node]);
    if(to)
      lazy[node * 2] ^= lazy[node],
      lazy[node * 2 + 1] ^= lazy[node];
    lazy[node] = 0;
    return;
  }
  int upd(int l, int r, int node = 1, int cl = 0, int cr = m - 1) {
    push(node, cl != cr);
    if(r < cl || cr < l)
      return aint[node];
    if(l <= cl && cr <= r) {
      lazy[node] = 1;
      push(node, cl != cr);
      //cerr << l << " <= " << cl << ' ' << cr << " <= " << r << '\n';
      //cerr << aint[node] << ' ' << inv[node] << "\n\n";
      return aint[node];
    }
    int mid = cl + cr >> 1;
    aint[node] = ((ll)upd(l, r, 2 * node, cl, mid) + upd(l, r, 2 * node + 1, mid + 1, cr)) % mod;
    inv[node] = ((ll)inv[2 * node] + inv[2 * node + 1]) % mod;
    return aint[node]; 
  }
}

vector<int> g[nmax * 2];
int prod[nmax * 2];

void initdfs(int node) {
  prod[node] = max(1LL, (int)g[node].size());
  for(auto x : g[node])
    initdfs(x),
    prod[node] = ((ll)prod[node] * prod[x]) % mod;
  return;
}

void initcost(int node, int accum = 1) {
  if(g[node].size() == 0) {
    cost[node - n] = accum;
    return;
  }
  vector<int> pref(g[node].size()), suff(g[node].size());
  int tmp = 1;
  for(int i = 0; i < g[node].size(); i++) {
    pref[i] = tmp;
    tmp = (ll)tmp * prod[g[node][i]] % mod;
  }
  tmp = 1;
  for(int i = g[node].size() - 1; i >= 0; i--) {
    suff[i] = tmp;
    tmp = (ll)tmp * prod[g[node][i]] % mod;
  }
  for(int i = 0; i < g[node].size(); i++) {
    initcost(g[node][i], (ll)accum * pref[i] % mod * suff[i] % mod);
  }
  return;
  
} 
#undef int
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
#define int ll
  for(int i = 1; i < N + M; i++) {
    g[P[i]].push_back(i);
  }
  tie(n, m) = pii{N, M};
  initdfs(0);
  initcost(0, 1);
  AINT::init();
  for(int i = 0; i < m; i++) {
    //cerr << cost[i] << ' ';
    if(A[i] == 0)
      AINT::upd(i, i);
    //cerr << A[i] << ' ' << AINT::aint[1] << '\n';
  }
  //cerr << '\n';
  return;
}
#undef int
int count_ways(int L, int R) {
  return AINT::upd(L - n, R - n);
}

Compilation message

circuit.cpp: In function 'll AINT::init(ll, ll, ll)':
circuit.cpp:20:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |     int mid = cl + cr >> 1;
      |               ~~~^~~~
circuit.cpp: In function 'll AINT::upd(ll, ll, ll, ll, ll)':
circuit.cpp:43:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |     int mid = cl + cr >> 1;
      |               ~~~^~~~
circuit.cpp: In function 'void initcost(ll, ll)':
circuit.cpp:68:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   68 |   for(int i = 0; i < g[node].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~
circuit.cpp:77:20: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   77 |   for(int i = 0; i < g[node].size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5068 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 5004 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 5 ms 5072 KB Output is correct
9 Correct 4 ms 5072 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5068 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 4 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 4 ms 5004 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 5 ms 5072 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 4 ms 5152 KB Output is correct
24 Correct 4 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 4 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 4 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5112 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 4 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 568 ms 9128 KB Output is correct
2 Correct 908 ms 13156 KB Output is correct
3 Correct 902 ms 13208 KB Output is correct
4 Correct 1050 ms 13156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 568 ms 9128 KB Output is correct
2 Correct 908 ms 13156 KB Output is correct
3 Correct 902 ms 13208 KB Output is correct
4 Correct 1050 ms 13156 KB Output is correct
5 Correct 803 ms 9040 KB Output is correct
6 Correct 1080 ms 13176 KB Output is correct
7 Correct 1032 ms 13112 KB Output is correct
8 Correct 856 ms 13128 KB Output is correct
9 Correct 437 ms 5200 KB Output is correct
10 Correct 962 ms 5456 KB Output is correct
11 Correct 951 ms 5456 KB Output is correct
12 Correct 857 ms 5456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 4 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 4 ms 5004 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 5 ms 5072 KB Output is correct
9 Correct 4 ms 5072 KB Output is correct
10 Correct 3 ms 5328 KB Output is correct
11 Correct 3 ms 5328 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 568 ms 9128 KB Output is correct
14 Correct 908 ms 13156 KB Output is correct
15 Correct 902 ms 13208 KB Output is correct
16 Correct 1050 ms 13156 KB Output is correct
17 Correct 803 ms 9040 KB Output is correct
18 Correct 1080 ms 13176 KB Output is correct
19 Correct 1032 ms 13112 KB Output is correct
20 Correct 856 ms 13128 KB Output is correct
21 Correct 437 ms 5200 KB Output is correct
22 Correct 962 ms 5456 KB Output is correct
23 Correct 951 ms 5456 KB Output is correct
24 Correct 857 ms 5456 KB Output is correct
25 Correct 1070 ms 18816 KB Output is correct
26 Correct 920 ms 18976 KB Output is correct
27 Correct 1157 ms 18968 KB Output is correct
28 Correct 882 ms 18956 KB Output is correct
29 Correct 1073 ms 39244 KB Output is correct
30 Correct 996 ms 39296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5068 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 4 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 4 ms 5004 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 5 ms 5072 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 4 ms 5152 KB Output is correct
24 Correct 4 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 4 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 4 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5112 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 4 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 709 ms 5348 KB Output is correct
44 Correct 818 ms 5456 KB Output is correct
45 Correct 861 ms 5364 KB Output is correct
46 Correct 880 ms 5712 KB Output is correct
47 Correct 830 ms 5712 KB Output is correct
48 Correct 983 ms 5712 KB Output is correct
49 Correct 852 ms 5712 KB Output is correct
50 Correct 753 ms 5712 KB Output is correct
51 Correct 920 ms 5688 KB Output is correct
52 Correct 1081 ms 5712 KB Output is correct
53 Correct 612 ms 6244 KB Output is correct
54 Correct 763 ms 5712 KB Output is correct
55 Correct 922 ms 5712 KB Output is correct
56 Correct 701 ms 5584 KB Output is correct
57 Correct 885 ms 5584 KB Output is correct
58 Correct 942 ms 6736 KB Output is correct
59 Correct 860 ms 6864 KB Output is correct
60 Correct 765 ms 6864 KB Output is correct
61 Correct 898 ms 5584 KB Output is correct
62 Correct 753 ms 5328 KB Output is correct
63 Correct 937 ms 5328 KB Output is correct
64 Correct 943 ms 5584 KB Output is correct
65 Correct 406 ms 5200 KB Output is correct
66 Correct 883 ms 5456 KB Output is correct
67 Correct 770 ms 5456 KB Output is correct
68 Correct 766 ms 5456 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5068 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5072 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 4 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 4 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 4 ms 5004 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 5 ms 5072 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 3 ms 5328 KB Output is correct
19 Correct 3 ms 5328 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 4 ms 5152 KB Output is correct
24 Correct 4 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 4 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 3 ms 5072 KB Output is correct
30 Correct 4 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 3 ms 5112 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 3 ms 5328 KB Output is correct
37 Correct 3 ms 5328 KB Output is correct
38 Correct 4 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 568 ms 9128 KB Output is correct
44 Correct 908 ms 13156 KB Output is correct
45 Correct 902 ms 13208 KB Output is correct
46 Correct 1050 ms 13156 KB Output is correct
47 Correct 803 ms 9040 KB Output is correct
48 Correct 1080 ms 13176 KB Output is correct
49 Correct 1032 ms 13112 KB Output is correct
50 Correct 856 ms 13128 KB Output is correct
51 Correct 437 ms 5200 KB Output is correct
52 Correct 962 ms 5456 KB Output is correct
53 Correct 951 ms 5456 KB Output is correct
54 Correct 857 ms 5456 KB Output is correct
55 Correct 1070 ms 18816 KB Output is correct
56 Correct 920 ms 18976 KB Output is correct
57 Correct 1157 ms 18968 KB Output is correct
58 Correct 882 ms 18956 KB Output is correct
59 Correct 1073 ms 39244 KB Output is correct
60 Correct 996 ms 39296 KB Output is correct
61 Correct 709 ms 5348 KB Output is correct
62 Correct 818 ms 5456 KB Output is correct
63 Correct 861 ms 5364 KB Output is correct
64 Correct 880 ms 5712 KB Output is correct
65 Correct 830 ms 5712 KB Output is correct
66 Correct 983 ms 5712 KB Output is correct
67 Correct 852 ms 5712 KB Output is correct
68 Correct 753 ms 5712 KB Output is correct
69 Correct 920 ms 5688 KB Output is correct
70 Correct 1081 ms 5712 KB Output is correct
71 Correct 612 ms 6244 KB Output is correct
72 Correct 763 ms 5712 KB Output is correct
73 Correct 922 ms 5712 KB Output is correct
74 Correct 701 ms 5584 KB Output is correct
75 Correct 885 ms 5584 KB Output is correct
76 Correct 942 ms 6736 KB Output is correct
77 Correct 860 ms 6864 KB Output is correct
78 Correct 765 ms 6864 KB Output is correct
79 Correct 898 ms 5584 KB Output is correct
80 Correct 753 ms 5328 KB Output is correct
81 Correct 937 ms 5328 KB Output is correct
82 Correct 943 ms 5584 KB Output is correct
83 Correct 406 ms 5200 KB Output is correct
84 Correct 883 ms 5456 KB Output is correct
85 Correct 770 ms 5456 KB Output is correct
86 Correct 766 ms 5456 KB Output is correct
87 Correct 3 ms 4944 KB Output is correct
88 Correct 656 ms 18608 KB Output is correct
89 Correct 909 ms 13308 KB Output is correct
90 Correct 963 ms 13312 KB Output is correct
91 Correct 1057 ms 19588 KB Output is correct
92 Correct 1103 ms 19560 KB Output is correct
93 Correct 884 ms 19596 KB Output is correct
94 Correct 857 ms 19612 KB Output is correct
95 Correct 1058 ms 19584 KB Output is correct
96 Correct 920 ms 15132 KB Output is correct
97 Correct 953 ms 15188 KB Output is correct
98 Correct 856 ms 29984 KB Output is correct
99 Correct 1153 ms 18996 KB Output is correct
100 Correct 1072 ms 17684 KB Output is correct
101 Correct 1042 ms 16764 KB Output is correct
102 Correct 950 ms 15392 KB Output is correct
103 Correct 1112 ms 39412 KB Output is correct
104 Correct 979 ms 40028 KB Output is correct
105 Correct 764 ms 40028 KB Output is correct
106 Correct 1016 ms 17540 KB Output is correct
107 Correct 926 ms 15432 KB Output is correct
108 Correct 1004 ms 15832 KB Output is correct
109 Correct 979 ms 15640 KB Output is correct