Submission #825801

# Submission time Handle Problem Language Result Execution time Memory
825801 2023-08-15T08:14:20 Z becaido Digital Circuit (IOI22_circuit) C++17
100 / 100
1037 ms 30500 KB
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#include <bits/stdc++.h>
using namespace std;

#ifndef WAIMAI
#include "circuit.h"
#endif

#ifdef WAIMAI
#define debug(HEHE...) cout << "[" << #HEHE << "] : ", dout(HEHE)
void dout() {cout << '\n';}
template<typename T, typename...U>
void dout(T t, U...u) {cout << t << (sizeof...(u) ? ", " : ""), dout(u...);}
#else
#define debug(...) 7122
#endif

#define ll long long
#define Waimai ios::sync_with_stdio(false), cin.tie(0)
#define FOR(x,a,b) for (int x = a, I = b; x <= I; x++)
#define pb emplace_back
#define F first
#define S second

#define lpos pos*2
#define rpos pos*2+1

const int MOD = 1000002022;
const int SIZE = 2e5 + 5;

int n, m, ans;
vector<int> adj[SIZE];
int a[SIZE], coef[SIZE], all[SIZE], pre[SIZE];

int add(const int &x, const int &y) {
    return x + y >= MOD ? x + y - MOD : x < -y ? x + y + MOD : x + y;
}
int mul(const int &x, const int &y) {
    return 1ll * x * y % MOD;
}

struct Node {
    int sum = 0, lazy = 0;
} node[SIZE * 4];

void build(int pos, int l, int r) {
    if (l == r) {
        if (a[l]) node[pos].sum = coef[l];
        return;
    }
    int mid = (l + r) / 2;
    build(lpos, l, mid);
    build(rpos, mid + 1, r);
    node[pos].sum = add(node[lpos].sum, node[rpos].sum);
}
void push(int pos, int l, int r) {
    if (!node[pos].lazy) return;
    node[pos].sum = add(pre[r], -add((l ? pre[l - 1] : 0), node[pos].sum));
    if (l < r) {
        node[lpos].lazy ^= 1;
        node[rpos].lazy ^= 1;
    }
    node[pos].lazy = 0;
}
void pull(int pos, int l, int r) {
    int mid = (l + r) / 2;
    push(lpos, l, mid);
    push(rpos, mid + 1, r);
    node[pos].sum = add(node[lpos].sum, node[rpos].sum);
}
void upd(int pos, int l, int r, int L, int R) {
    if (l == L && r == R) {
        node[pos].lazy ^= 1;
        return;
    }
    push(pos, L, R);
    int mid = (L + R) / 2;
    if (r <= mid) upd(lpos, l, r, L, mid);
    else if (l > mid) upd(rpos, l, r, mid + 1, R);
    else {
        upd(lpos, l, mid, L, mid);
        upd(rpos, mid + 1, r, mid + 1, R);
    }
    pull(pos, L, R);
}

void dfs0(int pos) {
    int pro = 1;
    for (int np : adj[pos]) {
        dfs0(np);
        pro = mul(pro, all[np]);
    }
    if (adj[pos].size()) pro = mul(pro, adj[pos].size());
    all[pos] = pro;
}
void dfs(int pos, int cur) {
    if (adj[pos].size() == 0) {
        coef[pos - n] = cur;
        return;
    }
    int sz = adj[pos].size();
    vector<int> pL(sz), pR(sz);
    FOR (i, 0, sz - 1) pL[i] = pR[i] = all[adj[pos][i]];
    FOR (i, 1, sz - 1) pL[i] = mul(pL[i - 1], pL[i]);
    for (int i = sz - 2; i >= 0; i--) pR[i] = mul(pR[i + 1], pR[i]);
    FOR (i, 0, sz - 1) {
        int pro = cur;
        if (i > 0) pro = mul(pro, pL[i - 1]);
        if (i < sz - 1) pro = mul(pro, pR[i + 1]);
        dfs(adj[pos][i], pro);
    }
}

void init(int N, int M, vector<int> P, vector<int> A) {
    n = N, m = M;
    FOR (i, 1, n + m - 1) adj[P[i]].pb(i);
    dfs0(0);
    dfs(0, 1);
    FOR (i, 0, m - 1) {
        a[i] = A[i];
        pre[i] = add((i ? pre[i - 1] : 0), coef[i]);
    }
    build(1, 0, m - 1);
}

int count_ways(int L, int R) {
    L -= n, R -= n;
    upd(1, L, R, 0, m - 1);
    push(1, 0, m - 1);
    return node[1].sum;
}

/*
in1
3 4 3
-1 0 1 2 1 1 0
1 0 1 0
3 4
4 5
3 6
out1
2
0
6
*/

#ifdef WAIMAI
int main() {
  int N, M, Q;
  assert(3 == scanf("%d %d %d", &N, &M, &Q));
  vector<int> P(N + M), A(M);
  for (int i = 0; i < N + M; ++i) {
    assert(1 == scanf("%d", &P[i]));
  }
  for (int j = 0; j < M; ++j) {
    assert(1 == scanf("%d", &A[j]));
  }
  init(N, M, P, A);

  for (int i = 0; i < Q; ++i) {
    int L, R;
    assert(2 == scanf("%d %d", &L, &R));
    printf("%d\n", count_ways(L, R));
  }
  return 0;
}
#endif
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 4 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 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 4 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 4 ms 5084 KB Output is correct
8 Correct 4 ms 5088 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 4 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 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 4 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 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 4 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 4 ms 5072 KB Output is correct
15 Correct 4 ms 5084 KB Output is correct
16 Correct 4 ms 5088 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 4988 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5044 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 4 ms 5092 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 4 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 4 ms 5152 KB Output is correct
32 Correct 3 ms 5016 KB Output is correct
33 Correct 3 ms 5072 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 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 5 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 4 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 510 ms 7948 KB Output is correct
2 Correct 760 ms 10876 KB Output is correct
3 Correct 765 ms 10900 KB Output is correct
4 Correct 891 ms 10352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 510 ms 7948 KB Output is correct
2 Correct 760 ms 10876 KB Output is correct
3 Correct 765 ms 10900 KB Output is correct
4 Correct 891 ms 10352 KB Output is correct
5 Correct 599 ms 7888 KB Output is correct
6 Correct 977 ms 10896 KB Output is correct
7 Correct 1028 ms 10864 KB Output is correct
8 Correct 690 ms 10864 KB Output is correct
9 Correct 328 ms 5200 KB Output is correct
10 Correct 605 ms 5328 KB Output is correct
11 Correct 661 ms 5328 KB Output is correct
12 Correct 848 ms 5328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 4 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 4 ms 5084 KB Output is correct
8 Correct 4 ms 5088 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 4 ms 5200 KB Output is correct
11 Correct 3 ms 5200 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 510 ms 7948 KB Output is correct
14 Correct 760 ms 10876 KB Output is correct
15 Correct 765 ms 10900 KB Output is correct
16 Correct 891 ms 10352 KB Output is correct
17 Correct 599 ms 7888 KB Output is correct
18 Correct 977 ms 10896 KB Output is correct
19 Correct 1028 ms 10864 KB Output is correct
20 Correct 690 ms 10864 KB Output is correct
21 Correct 328 ms 5200 KB Output is correct
22 Correct 605 ms 5328 KB Output is correct
23 Correct 661 ms 5328 KB Output is correct
24 Correct 848 ms 5328 KB Output is correct
25 Correct 1025 ms 14344 KB Output is correct
26 Correct 987 ms 14476 KB Output is correct
27 Correct 883 ms 14492 KB Output is correct
28 Correct 732 ms 14464 KB Output is correct
29 Correct 777 ms 30068 KB Output is correct
30 Correct 796 ms 30080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 4 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 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 4 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 4 ms 5072 KB Output is correct
15 Correct 4 ms 5084 KB Output is correct
16 Correct 4 ms 5088 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 4988 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5044 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 4 ms 5092 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 4 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 4 ms 5152 KB Output is correct
32 Correct 3 ms 5016 KB Output is correct
33 Correct 3 ms 5072 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 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 5 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 4 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 637 ms 5200 KB Output is correct
44 Correct 656 ms 5328 KB Output is correct
45 Correct 770 ms 5200 KB Output is correct
46 Correct 702 ms 5456 KB Output is correct
47 Correct 763 ms 5456 KB Output is correct
48 Correct 843 ms 5464 KB Output is correct
49 Correct 843 ms 5456 KB Output is correct
50 Correct 652 ms 5456 KB Output is correct
51 Correct 717 ms 5328 KB Output is correct
52 Correct 656 ms 5328 KB Output is correct
53 Correct 702 ms 5968 KB Output is correct
54 Correct 825 ms 5456 KB Output is correct
55 Correct 738 ms 5328 KB Output is correct
56 Correct 572 ms 5328 KB Output is correct
57 Correct 719 ms 5296 KB Output is correct
58 Correct 789 ms 6224 KB Output is correct
59 Correct 715 ms 6352 KB Output is correct
60 Correct 648 ms 6352 KB Output is correct
61 Correct 786 ms 5456 KB Output is correct
62 Correct 793 ms 5200 KB Output is correct
63 Correct 833 ms 5200 KB Output is correct
64 Correct 672 ms 5292 KB Output is correct
65 Correct 361 ms 5072 KB Output is correct
66 Correct 611 ms 5328 KB Output is correct
67 Correct 699 ms 5328 KB Output is correct
68 Correct 583 ms 5328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 4 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 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 4 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 4 ms 5072 KB Output is correct
15 Correct 4 ms 5084 KB Output is correct
16 Correct 4 ms 5088 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 3 ms 5200 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 4988 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5044 KB Output is correct
24 Correct 3 ms 5072 KB Output is correct
25 Correct 3 ms 5072 KB Output is correct
26 Correct 4 ms 5092 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 4 ms 5072 KB Output is correct
30 Correct 3 ms 5072 KB Output is correct
31 Correct 4 ms 5152 KB Output is correct
32 Correct 3 ms 5016 KB Output is correct
33 Correct 3 ms 5072 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 5200 KB Output is correct
37 Correct 3 ms 5200 KB Output is correct
38 Correct 5 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 4 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 510 ms 7948 KB Output is correct
44 Correct 760 ms 10876 KB Output is correct
45 Correct 765 ms 10900 KB Output is correct
46 Correct 891 ms 10352 KB Output is correct
47 Correct 599 ms 7888 KB Output is correct
48 Correct 977 ms 10896 KB Output is correct
49 Correct 1028 ms 10864 KB Output is correct
50 Correct 690 ms 10864 KB Output is correct
51 Correct 328 ms 5200 KB Output is correct
52 Correct 605 ms 5328 KB Output is correct
53 Correct 661 ms 5328 KB Output is correct
54 Correct 848 ms 5328 KB Output is correct
55 Correct 1025 ms 14344 KB Output is correct
56 Correct 987 ms 14476 KB Output is correct
57 Correct 883 ms 14492 KB Output is correct
58 Correct 732 ms 14464 KB Output is correct
59 Correct 777 ms 30068 KB Output is correct
60 Correct 796 ms 30080 KB Output is correct
61 Correct 637 ms 5200 KB Output is correct
62 Correct 656 ms 5328 KB Output is correct
63 Correct 770 ms 5200 KB Output is correct
64 Correct 702 ms 5456 KB Output is correct
65 Correct 763 ms 5456 KB Output is correct
66 Correct 843 ms 5464 KB Output is correct
67 Correct 843 ms 5456 KB Output is correct
68 Correct 652 ms 5456 KB Output is correct
69 Correct 717 ms 5328 KB Output is correct
70 Correct 656 ms 5328 KB Output is correct
71 Correct 702 ms 5968 KB Output is correct
72 Correct 825 ms 5456 KB Output is correct
73 Correct 738 ms 5328 KB Output is correct
74 Correct 572 ms 5328 KB Output is correct
75 Correct 719 ms 5296 KB Output is correct
76 Correct 789 ms 6224 KB Output is correct
77 Correct 715 ms 6352 KB Output is correct
78 Correct 648 ms 6352 KB Output is correct
79 Correct 786 ms 5456 KB Output is correct
80 Correct 793 ms 5200 KB Output is correct
81 Correct 833 ms 5200 KB Output is correct
82 Correct 672 ms 5292 KB Output is correct
83 Correct 361 ms 5072 KB Output is correct
84 Correct 611 ms 5328 KB Output is correct
85 Correct 699 ms 5328 KB Output is correct
86 Correct 583 ms 5328 KB Output is correct
87 Correct 3 ms 4944 KB Output is correct
88 Correct 576 ms 13680 KB Output is correct
89 Correct 995 ms 10848 KB Output is correct
90 Correct 713 ms 10688 KB Output is correct
91 Correct 719 ms 14592 KB Output is correct
92 Correct 978 ms 14616 KB Output is correct
93 Correct 925 ms 13556 KB Output is correct
94 Correct 871 ms 14580 KB Output is correct
95 Correct 911 ms 14556 KB Output is correct
96 Correct 657 ms 10624 KB Output is correct
97 Correct 1016 ms 10728 KB Output is correct
98 Correct 885 ms 24860 KB Output is correct
99 Correct 933 ms 14484 KB Output is correct
100 Correct 986 ms 12280 KB Output is correct
101 Correct 1037 ms 11760 KB Output is correct
102 Correct 723 ms 10648 KB Output is correct
103 Correct 952 ms 30104 KB Output is correct
104 Correct 726 ms 30484 KB Output is correct
105 Correct 653 ms 30500 KB Output is correct
106 Correct 742 ms 13944 KB Output is correct
107 Correct 759 ms 10840 KB Output is correct
108 Correct 791 ms 10852 KB Output is correct
109 Correct 792 ms 10768 KB Output is correct