답안 #630943

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
630943 2022-08-17T11:18:19 Z garam1732 디지털 회로 (IOI22_circuit) C++17
100 / 100
1173 ms 22856 KB
#include "circuit.h"

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
const ll MOD = 1000002022;
const int MAXN = 200200;

vector<int> adj[MAXN];
vector<ll> tree;
vector<int> lazy;
ll d[MAXN], sum[MAXN];
int in[MAXN], out[MAXN], cnt;
int x, y;

void update1(int node, int s, int e, int l, int r, int val) {
    if(l > r || e < l || r < s) return;
    if(l <= s && e <= r) {
        tree[node] = tree[node]*val%MOD;
        return;
    }

    int mid = s+e>>1;
    update1(node<<1, s, mid, l, r, val); update1(node<<1|1, mid+1, e, l, r, val);
}

ll solve1(int node, int s, int e, int idx) {
    if(e < idx || idx < s) return 1;
    ll ans = tree[node];
    if(s != e) {
        int mid = s+e>>1;
        ans = ans*solve1(node<<1, s, mid, idx)%MOD;
        ans = ans*solve1(node<<1|1, mid+1, e, idx)%MOD;
    }

    return ans;
}

void update_lazy(int node, int s, int e) {
    if(lazy[node]) {
        tree[node] = (sum[e]-sum[s-1]-tree[node]+2*MOD)%MOD;
        if(s != e) {
            lazy[node<<1] = 1-lazy[node<<1];
            lazy[node<<1|1] = 1-lazy[node<<1|1];
        }
        lazy[node] = 0;
    }
}

void update2(int node, int s, int e, int l, int r) {
    update_lazy(node, s, e);
    if(l > r || e < l || r < s) return;
    if(l <= s && e <= r) {
        tree[node] = (sum[e]-sum[s-1]-tree[node]+2*MOD)%MOD;
        if(s != e) {
            lazy[node<<1] = 1-lazy[node<<1];
            lazy[node<<1|1] = 1-lazy[node<<1|1];
        }
        return;
    }

    int mid = s+e>>1;
    update2(node<<1, s, mid, l, r); update2(node<<1|1, mid+1, e, l, r);
    tree[node] = (tree[node<<1] + tree[node<<1|1])%MOD;
}

void dfs(int here) {
    in[here] = ++cnt;
    for(int there : adj[here]) dfs(there);
    out[here] = cnt;
}

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

    x = N, y = M;
    dfs(0);

    int h = (int)ceil(log2(x+y));
    tree.resize(1 << (h+1), 1);

    for(int i = 0; i < N; i++) {
        update1(1, 1, cnt, 1, in[i]-1, adj[i].size());
        update1(1, 1, cnt, out[i]+1, cnt, adj[i].size());
    }

    for(int i = N; i < N+M; i++) {
        d[i] = solve1(1, 1, cnt, in[i]);
        sum[i] = (sum[i-1] + d[i])%MOD;
    }

    tree.clear();
    tree.resize(1 << (h+1));
    lazy.resize(1 << (h+1));

    for(int i = N; i < N+M; i++)
        if(A[i-N])
            update2(1, 1, x+y-1, i, i);
}

int count_ways(int L, int R) {
    update2(1, 1, x+y-1, L, R);
    update_lazy(1, 1, x+y-1);
    return tree[1];
}

Compilation message

circuit.cpp: In function 'void update1(int, int, int, int, int, int)':
circuit.cpp:27:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   27 |     int mid = s+e>>1;
      |               ~^~
circuit.cpp: In function 'll solve1(int, int, int, int)':
circuit.cpp:35:20: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   35 |         int mid = s+e>>1;
      |                   ~^~
circuit.cpp: In function 'void update2(int, int, int, int, int)':
circuit.cpp:66:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   66 |     int mid = s+e>>1;
      |               ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4944 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 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 4 ms 5072 KB Output is correct
5 Correct 3 ms 4972 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 5 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5152 KB Output is correct
11 Correct 4 ms 5148 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4944 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 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5036 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 3 ms 4972 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 5 ms 5072 KB Output is correct
16 Correct 4 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5152 KB Output is correct
19 Correct 4 ms 5148 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 4 ms 5048 KB Output is correct
25 Correct 4 ms 5152 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 3 ms 5072 KB Output is correct
31 Correct 3 ms 5072 KB Output is correct
32 Correct 3 ms 5160 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 4 ms 5064 KB Output is correct
36 Correct 4 ms 5072 KB Output is correct
37 Correct 3 ms 5072 KB Output is correct
38 Correct 4 ms 5144 KB Output is correct
39 Correct 3 ms 5124 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
# 결과 실행 시간 메모리 Grader output
1 Correct 640 ms 9360 KB Output is correct
2 Correct 704 ms 13644 KB Output is correct
3 Correct 1040 ms 13696 KB Output is correct
4 Correct 912 ms 13640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 640 ms 9360 KB Output is correct
2 Correct 704 ms 13644 KB Output is correct
3 Correct 1040 ms 13696 KB Output is correct
4 Correct 912 ms 13640 KB Output is correct
5 Correct 786 ms 9344 KB Output is correct
6 Correct 954 ms 13712 KB Output is correct
7 Correct 788 ms 13768 KB Output is correct
8 Correct 796 ms 13732 KB Output is correct
9 Correct 452 ms 5272 KB Output is correct
10 Correct 852 ms 5456 KB Output is correct
11 Correct 911 ms 5456 KB Output is correct
12 Correct 884 ms 5456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 4 ms 5072 KB Output is correct
5 Correct 3 ms 4972 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 5 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 3 ms 5072 KB Output is correct
10 Correct 3 ms 5152 KB Output is correct
11 Correct 4 ms 5148 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 640 ms 9360 KB Output is correct
14 Correct 704 ms 13644 KB Output is correct
15 Correct 1040 ms 13696 KB Output is correct
16 Correct 912 ms 13640 KB Output is correct
17 Correct 786 ms 9344 KB Output is correct
18 Correct 954 ms 13712 KB Output is correct
19 Correct 788 ms 13768 KB Output is correct
20 Correct 796 ms 13732 KB Output is correct
21 Correct 452 ms 5272 KB Output is correct
22 Correct 852 ms 5456 KB Output is correct
23 Correct 911 ms 5456 KB Output is correct
24 Correct 884 ms 5456 KB Output is correct
25 Correct 1000 ms 19640 KB Output is correct
26 Correct 933 ms 19740 KB Output is correct
27 Correct 1125 ms 19780 KB Output is correct
28 Correct 688 ms 19820 KB Output is correct
29 Correct 1096 ms 22432 KB Output is correct
30 Correct 1012 ms 22388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4944 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 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5036 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 3 ms 4972 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 5 ms 5072 KB Output is correct
16 Correct 4 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5152 KB Output is correct
19 Correct 4 ms 5148 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 4 ms 5048 KB Output is correct
25 Correct 4 ms 5152 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 3 ms 5072 KB Output is correct
31 Correct 3 ms 5072 KB Output is correct
32 Correct 3 ms 5160 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 4 ms 5064 KB Output is correct
36 Correct 4 ms 5072 KB Output is correct
37 Correct 3 ms 5072 KB Output is correct
38 Correct 4 ms 5144 KB Output is correct
39 Correct 3 ms 5124 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 678 ms 5456 KB Output is correct
44 Correct 724 ms 5504 KB Output is correct
45 Correct 788 ms 5512 KB Output is correct
46 Correct 955 ms 5840 KB Output is correct
47 Correct 1008 ms 5848 KB Output is correct
48 Correct 925 ms 5840 KB Output is correct
49 Correct 1012 ms 5960 KB Output is correct
50 Correct 539 ms 5848 KB Output is correct
51 Correct 907 ms 5464 KB Output is correct
52 Correct 750 ms 5468 KB Output is correct
53 Correct 755 ms 5584 KB Output is correct
54 Correct 946 ms 5840 KB Output is correct
55 Correct 782 ms 5528 KB Output is correct
56 Correct 943 ms 5508 KB Output is correct
57 Correct 778 ms 5328 KB Output is correct
58 Correct 862 ms 5968 KB Output is correct
59 Correct 845 ms 5968 KB Output is correct
60 Correct 692 ms 5968 KB Output is correct
61 Correct 795 ms 5520 KB Output is correct
62 Correct 750 ms 5584 KB Output is correct
63 Correct 829 ms 5328 KB Output is correct
64 Correct 707 ms 5456 KB Output is correct
65 Correct 532 ms 5276 KB Output is correct
66 Correct 973 ms 5456 KB Output is correct
67 Correct 818 ms 5584 KB Output is correct
68 Correct 912 ms 5456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4944 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 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5036 KB Output is correct
9 Correct 3 ms 4944 KB Output is correct
10 Correct 3 ms 4944 KB Output is correct
11 Correct 3 ms 5072 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 3 ms 4972 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 5 ms 5072 KB Output is correct
16 Correct 4 ms 5072 KB Output is correct
17 Correct 3 ms 5072 KB Output is correct
18 Correct 3 ms 5152 KB Output is correct
19 Correct 4 ms 5148 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 4 ms 5048 KB Output is correct
25 Correct 4 ms 5152 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 3 ms 5072 KB Output is correct
31 Correct 3 ms 5072 KB Output is correct
32 Correct 3 ms 5160 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 4 ms 5064 KB Output is correct
36 Correct 4 ms 5072 KB Output is correct
37 Correct 3 ms 5072 KB Output is correct
38 Correct 4 ms 5144 KB Output is correct
39 Correct 3 ms 5124 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 640 ms 9360 KB Output is correct
44 Correct 704 ms 13644 KB Output is correct
45 Correct 1040 ms 13696 KB Output is correct
46 Correct 912 ms 13640 KB Output is correct
47 Correct 786 ms 9344 KB Output is correct
48 Correct 954 ms 13712 KB Output is correct
49 Correct 788 ms 13768 KB Output is correct
50 Correct 796 ms 13732 KB Output is correct
51 Correct 452 ms 5272 KB Output is correct
52 Correct 852 ms 5456 KB Output is correct
53 Correct 911 ms 5456 KB Output is correct
54 Correct 884 ms 5456 KB Output is correct
55 Correct 1000 ms 19640 KB Output is correct
56 Correct 933 ms 19740 KB Output is correct
57 Correct 1125 ms 19780 KB Output is correct
58 Correct 688 ms 19820 KB Output is correct
59 Correct 1096 ms 22432 KB Output is correct
60 Correct 1012 ms 22388 KB Output is correct
61 Correct 678 ms 5456 KB Output is correct
62 Correct 724 ms 5504 KB Output is correct
63 Correct 788 ms 5512 KB Output is correct
64 Correct 955 ms 5840 KB Output is correct
65 Correct 1008 ms 5848 KB Output is correct
66 Correct 925 ms 5840 KB Output is correct
67 Correct 1012 ms 5960 KB Output is correct
68 Correct 539 ms 5848 KB Output is correct
69 Correct 907 ms 5464 KB Output is correct
70 Correct 750 ms 5468 KB Output is correct
71 Correct 755 ms 5584 KB Output is correct
72 Correct 946 ms 5840 KB Output is correct
73 Correct 782 ms 5528 KB Output is correct
74 Correct 943 ms 5508 KB Output is correct
75 Correct 778 ms 5328 KB Output is correct
76 Correct 862 ms 5968 KB Output is correct
77 Correct 845 ms 5968 KB Output is correct
78 Correct 692 ms 5968 KB Output is correct
79 Correct 795 ms 5520 KB Output is correct
80 Correct 750 ms 5584 KB Output is correct
81 Correct 829 ms 5328 KB Output is correct
82 Correct 707 ms 5456 KB Output is correct
83 Correct 532 ms 5276 KB Output is correct
84 Correct 973 ms 5456 KB Output is correct
85 Correct 818 ms 5584 KB Output is correct
86 Correct 912 ms 5456 KB Output is correct
87 Correct 3 ms 4944 KB Output is correct
88 Correct 669 ms 18812 KB Output is correct
89 Correct 1103 ms 13708 KB Output is correct
90 Correct 1129 ms 13624 KB Output is correct
91 Correct 1022 ms 19784 KB Output is correct
92 Correct 1164 ms 19856 KB Output is correct
93 Correct 1163 ms 19836 KB Output is correct
94 Correct 1154 ms 19896 KB Output is correct
95 Correct 1048 ms 19844 KB Output is correct
96 Correct 651 ms 12480 KB Output is correct
97 Correct 985 ms 12480 KB Output is correct
98 Correct 737 ms 15400 KB Output is correct
99 Correct 1173 ms 19784 KB Output is correct
100 Correct 991 ms 17500 KB Output is correct
101 Correct 1121 ms 13636 KB Output is correct
102 Correct 824 ms 12508 KB Output is correct
103 Correct 958 ms 22388 KB Output is correct
104 Correct 801 ms 22824 KB Output is correct
105 Correct 997 ms 22856 KB Output is correct
106 Correct 809 ms 13912 KB Output is correct
107 Correct 1002 ms 12656 KB Output is correct
108 Correct 948 ms 12636 KB Output is correct
109 Correct 961 ms 12572 KB Output is correct