답안 #681114

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
681114 2023-01-12T11:13:47 Z AngusWong 디지털 회로 (IOI22_circuit) C++17
100 / 100
1223 ms 45380 KB
#include "circuit.h"
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define f first
#define s second
using namespace std;

const ll mod=1e9+2022;
const ll N=2e5+9;
ll n, m, a[N], pw[N], cnt[N], ps[N], seg[N*4], lazy[N*4], ans=0;
vector<ll> v[N], pre[N], suf[N];

void dfs(ll x){
    if (x>=n){
        pw[x]=1;
        return;
    }
    pw[x]=v[x].size();
    for (ll i: v[x]){
        dfs(i);
        pw[x]=pw[x]*pw[i]%mod;
    }
}

void dfs2(ll x, ll now=1){
    if (x>=n){
        cnt[x-n+1]=ps[x-n+1]=now;
        return;
    }
    ll sz=v[x].size();
    pre[x].resize(sz);
    pre[x][0]=pw[v[x][0]];
    for (int i=1; i<sz; i++) pre[x][i]=pre[x][i-1]*pw[v[x][i]]%mod;
    suf[x].resize(sz);
    suf[x][sz-1]=pw[v[x][sz-1]];
    for (int i=sz-2; i>=0; i--) suf[x][i]=suf[x][i+1]*pw[v[x][i]]%mod;
    for (int i=0; i<sz; i++){
        ll tmp=now;
        if (i) tmp=tmp*pre[x][i-1]%mod;
        if (i<sz-1) tmp=tmp*suf[x][i+1]%mod;
        dfs2(v[x][i], tmp);
    }
}

void push(ll id, ll x, ll y){
    if (!lazy[id]) return;
    lazy[id]=0;
    seg[id]=((ps[y]-ps[x-1]-seg[id])%mod+mod)%mod;
    if (x!=y){
        lazy[id*2]^=1;
        lazy[id*2+1]^=1;
    }
}

void build(ll id=1, ll x=1, ll y=m){
    if (x==y){
        seg[id]=cnt[x]*a[x];
        lazy[id]=0;
        return;
    }
    ll mid=(x+y)/2;
    build(id*2, x, mid);
    build(id*2+1, mid+1, y);
    seg[id]=(seg[id*2]+seg[id*2+1])%mod;
}

void update(ll l, ll r, ll id=1, ll x=1, ll y=m){
    push(id, x, y);
    if (l<=x && y<=r){
        lazy[id]^=1;
        push(id, x, y);
        return;
    }
    if (l>y || r<x) return;
    ll mid=(x+y)/2;
    update(l, r, id*2, x, mid);
    update(l, r, id*2+1, mid+1, y);
    seg[id]=(seg[id*2]+seg[id*2+1])%mod;
}

ll qry(ll p, ll id=1, ll x=1, ll y=m){
    push(id, x, y);
    if (x==y) return seg[id];
    ll mid=(x+y)/2;
    if (p<=mid) return qry(p, id*2, x, mid);
    return qry(p, id*2+1, mid+1, y);
}

void init(int N, int M, vector<int> P, vector<int> A){
    n=N, m=M;
    for (int i=1; i<n+m; i++) v[P[i]].push_back(i);
    for (int i=0; i<m; i++) a[i+1]=A[i];
    dfs(0);
    dfs2(0);
    for (int i=2; i<=m; i++) ps[i]=(ps[i]+ps[i-1])%mod;
    build();
}

int count_ways(int L, int R){
    update(L-n+1, R-n+1);
    push(1, 1, m);
    return seg[1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 8 ms 14416 KB Output is correct
3 Correct 8 ms 14544 KB Output is correct
4 Correct 9 ms 14532 KB Output is correct
5 Correct 8 ms 14416 KB Output is correct
6 Correct 8 ms 14544 KB Output is correct
7 Correct 10 ms 14544 KB Output is correct
8 Correct 9 ms 14544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14416 KB Output is correct
2 Correct 9 ms 14416 KB Output is correct
3 Correct 9 ms 14416 KB Output is correct
4 Correct 9 ms 14480 KB Output is correct
5 Correct 9 ms 14416 KB Output is correct
6 Correct 8 ms 14544 KB Output is correct
7 Correct 8 ms 14544 KB Output is correct
8 Correct 8 ms 14544 KB Output is correct
9 Correct 10 ms 14544 KB Output is correct
10 Correct 9 ms 14696 KB Output is correct
11 Correct 9 ms 14672 KB Output is correct
12 Correct 9 ms 14544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 8 ms 14416 KB Output is correct
3 Correct 8 ms 14544 KB Output is correct
4 Correct 9 ms 14532 KB Output is correct
5 Correct 8 ms 14416 KB Output is correct
6 Correct 8 ms 14544 KB Output is correct
7 Correct 10 ms 14544 KB Output is correct
8 Correct 9 ms 14544 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 9 ms 14416 KB Output is correct
11 Correct 9 ms 14416 KB Output is correct
12 Correct 9 ms 14480 KB Output is correct
13 Correct 9 ms 14416 KB Output is correct
14 Correct 8 ms 14544 KB Output is correct
15 Correct 8 ms 14544 KB Output is correct
16 Correct 8 ms 14544 KB Output is correct
17 Correct 10 ms 14544 KB Output is correct
18 Correct 9 ms 14696 KB Output is correct
19 Correct 9 ms 14672 KB Output is correct
20 Correct 9 ms 14544 KB Output is correct
21 Correct 9 ms 14544 KB Output is correct
22 Correct 8 ms 14540 KB Output is correct
23 Correct 7 ms 14544 KB Output is correct
24 Correct 8 ms 14628 KB Output is correct
25 Correct 9 ms 14536 KB Output is correct
26 Correct 8 ms 14548 KB Output is correct
27 Correct 8 ms 14544 KB Output is correct
28 Correct 8 ms 14544 KB Output is correct
29 Correct 7 ms 14416 KB Output is correct
30 Correct 7 ms 14544 KB Output is correct
31 Correct 7 ms 14544 KB Output is correct
32 Correct 8 ms 14544 KB Output is correct
33 Correct 8 ms 14544 KB Output is correct
34 Correct 7 ms 14488 KB Output is correct
35 Correct 8 ms 14416 KB Output is correct
36 Correct 8 ms 14644 KB Output is correct
37 Correct 8 ms 14692 KB Output is correct
38 Correct 8 ms 14632 KB Output is correct
39 Correct 7 ms 14544 KB Output is correct
40 Correct 8 ms 14436 KB Output is correct
41 Correct 8 ms 14544 KB Output is correct
42 Correct 8 ms 14416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 667 ms 20296 KB Output is correct
2 Correct 846 ms 26184 KB Output is correct
3 Correct 922 ms 26180 KB Output is correct
4 Correct 762 ms 26168 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 667 ms 20296 KB Output is correct
2 Correct 846 ms 26184 KB Output is correct
3 Correct 922 ms 26180 KB Output is correct
4 Correct 762 ms 26168 KB Output is correct
5 Correct 792 ms 20296 KB Output is correct
6 Correct 949 ms 26184 KB Output is correct
7 Correct 997 ms 26164 KB Output is correct
8 Correct 791 ms 26172 KB Output is correct
9 Correct 333 ms 14800 KB Output is correct
10 Correct 862 ms 15184 KB Output is correct
11 Correct 925 ms 15184 KB Output is correct
12 Correct 953 ms 15056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 14416 KB Output is correct
2 Correct 9 ms 14416 KB Output is correct
3 Correct 9 ms 14416 KB Output is correct
4 Correct 9 ms 14480 KB Output is correct
5 Correct 9 ms 14416 KB Output is correct
6 Correct 8 ms 14544 KB Output is correct
7 Correct 8 ms 14544 KB Output is correct
8 Correct 8 ms 14544 KB Output is correct
9 Correct 10 ms 14544 KB Output is correct
10 Correct 9 ms 14696 KB Output is correct
11 Correct 9 ms 14672 KB Output is correct
12 Correct 9 ms 14544 KB Output is correct
13 Correct 667 ms 20296 KB Output is correct
14 Correct 846 ms 26184 KB Output is correct
15 Correct 922 ms 26180 KB Output is correct
16 Correct 762 ms 26168 KB Output is correct
17 Correct 792 ms 20296 KB Output is correct
18 Correct 949 ms 26184 KB Output is correct
19 Correct 997 ms 26164 KB Output is correct
20 Correct 791 ms 26172 KB Output is correct
21 Correct 333 ms 14800 KB Output is correct
22 Correct 862 ms 15184 KB Output is correct
23 Correct 925 ms 15184 KB Output is correct
24 Correct 953 ms 15056 KB Output is correct
25 Correct 833 ms 33368 KB Output is correct
26 Correct 1096 ms 33604 KB Output is correct
27 Correct 1004 ms 33584 KB Output is correct
28 Correct 764 ms 33588 KB Output is correct
29 Correct 1045 ms 43060 KB Output is correct
30 Correct 932 ms 42960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 8 ms 14416 KB Output is correct
3 Correct 8 ms 14544 KB Output is correct
4 Correct 9 ms 14532 KB Output is correct
5 Correct 8 ms 14416 KB Output is correct
6 Correct 8 ms 14544 KB Output is correct
7 Correct 10 ms 14544 KB Output is correct
8 Correct 9 ms 14544 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 9 ms 14416 KB Output is correct
11 Correct 9 ms 14416 KB Output is correct
12 Correct 9 ms 14480 KB Output is correct
13 Correct 9 ms 14416 KB Output is correct
14 Correct 8 ms 14544 KB Output is correct
15 Correct 8 ms 14544 KB Output is correct
16 Correct 8 ms 14544 KB Output is correct
17 Correct 10 ms 14544 KB Output is correct
18 Correct 9 ms 14696 KB Output is correct
19 Correct 9 ms 14672 KB Output is correct
20 Correct 9 ms 14544 KB Output is correct
21 Correct 9 ms 14544 KB Output is correct
22 Correct 8 ms 14540 KB Output is correct
23 Correct 7 ms 14544 KB Output is correct
24 Correct 8 ms 14628 KB Output is correct
25 Correct 9 ms 14536 KB Output is correct
26 Correct 8 ms 14548 KB Output is correct
27 Correct 8 ms 14544 KB Output is correct
28 Correct 8 ms 14544 KB Output is correct
29 Correct 7 ms 14416 KB Output is correct
30 Correct 7 ms 14544 KB Output is correct
31 Correct 7 ms 14544 KB Output is correct
32 Correct 8 ms 14544 KB Output is correct
33 Correct 8 ms 14544 KB Output is correct
34 Correct 7 ms 14488 KB Output is correct
35 Correct 8 ms 14416 KB Output is correct
36 Correct 8 ms 14644 KB Output is correct
37 Correct 8 ms 14692 KB Output is correct
38 Correct 8 ms 14632 KB Output is correct
39 Correct 7 ms 14544 KB Output is correct
40 Correct 8 ms 14436 KB Output is correct
41 Correct 8 ms 14544 KB Output is correct
42 Correct 8 ms 14416 KB Output is correct
43 Correct 610 ms 14940 KB Output is correct
44 Correct 643 ms 15056 KB Output is correct
45 Correct 1180 ms 15056 KB Output is correct
46 Correct 1223 ms 15440 KB Output is correct
47 Correct 992 ms 15440 KB Output is correct
48 Correct 811 ms 15440 KB Output is correct
49 Correct 756 ms 15440 KB Output is correct
50 Correct 681 ms 15568 KB Output is correct
51 Correct 744 ms 15036 KB Output is correct
52 Correct 900 ms 15056 KB Output is correct
53 Correct 893 ms 15440 KB Output is correct
54 Correct 834 ms 15440 KB Output is correct
55 Correct 648 ms 15184 KB Output is correct
56 Correct 776 ms 15056 KB Output is correct
57 Correct 719 ms 15056 KB Output is correct
58 Correct 764 ms 15824 KB Output is correct
59 Correct 761 ms 16080 KB Output is correct
60 Correct 755 ms 16036 KB Output is correct
61 Correct 1018 ms 15252 KB Output is correct
62 Correct 714 ms 14928 KB Output is correct
63 Correct 1052 ms 14924 KB Output is correct
64 Correct 690 ms 15056 KB Output is correct
65 Correct 442 ms 14800 KB Output is correct
66 Correct 969 ms 15184 KB Output is correct
67 Correct 1024 ms 15184 KB Output is correct
68 Correct 922 ms 15056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 14416 KB Output is correct
2 Correct 8 ms 14416 KB Output is correct
3 Correct 8 ms 14544 KB Output is correct
4 Correct 9 ms 14532 KB Output is correct
5 Correct 8 ms 14416 KB Output is correct
6 Correct 8 ms 14544 KB Output is correct
7 Correct 10 ms 14544 KB Output is correct
8 Correct 9 ms 14544 KB Output is correct
9 Correct 9 ms 14416 KB Output is correct
10 Correct 9 ms 14416 KB Output is correct
11 Correct 9 ms 14416 KB Output is correct
12 Correct 9 ms 14480 KB Output is correct
13 Correct 9 ms 14416 KB Output is correct
14 Correct 8 ms 14544 KB Output is correct
15 Correct 8 ms 14544 KB Output is correct
16 Correct 8 ms 14544 KB Output is correct
17 Correct 10 ms 14544 KB Output is correct
18 Correct 9 ms 14696 KB Output is correct
19 Correct 9 ms 14672 KB Output is correct
20 Correct 9 ms 14544 KB Output is correct
21 Correct 9 ms 14544 KB Output is correct
22 Correct 8 ms 14540 KB Output is correct
23 Correct 7 ms 14544 KB Output is correct
24 Correct 8 ms 14628 KB Output is correct
25 Correct 9 ms 14536 KB Output is correct
26 Correct 8 ms 14548 KB Output is correct
27 Correct 8 ms 14544 KB Output is correct
28 Correct 8 ms 14544 KB Output is correct
29 Correct 7 ms 14416 KB Output is correct
30 Correct 7 ms 14544 KB Output is correct
31 Correct 7 ms 14544 KB Output is correct
32 Correct 8 ms 14544 KB Output is correct
33 Correct 8 ms 14544 KB Output is correct
34 Correct 7 ms 14488 KB Output is correct
35 Correct 8 ms 14416 KB Output is correct
36 Correct 8 ms 14644 KB Output is correct
37 Correct 8 ms 14692 KB Output is correct
38 Correct 8 ms 14632 KB Output is correct
39 Correct 7 ms 14544 KB Output is correct
40 Correct 8 ms 14436 KB Output is correct
41 Correct 8 ms 14544 KB Output is correct
42 Correct 8 ms 14416 KB Output is correct
43 Correct 667 ms 20296 KB Output is correct
44 Correct 846 ms 26184 KB Output is correct
45 Correct 922 ms 26180 KB Output is correct
46 Correct 762 ms 26168 KB Output is correct
47 Correct 792 ms 20296 KB Output is correct
48 Correct 949 ms 26184 KB Output is correct
49 Correct 997 ms 26164 KB Output is correct
50 Correct 791 ms 26172 KB Output is correct
51 Correct 333 ms 14800 KB Output is correct
52 Correct 862 ms 15184 KB Output is correct
53 Correct 925 ms 15184 KB Output is correct
54 Correct 953 ms 15056 KB Output is correct
55 Correct 833 ms 33368 KB Output is correct
56 Correct 1096 ms 33604 KB Output is correct
57 Correct 1004 ms 33584 KB Output is correct
58 Correct 764 ms 33588 KB Output is correct
59 Correct 1045 ms 43060 KB Output is correct
60 Correct 932 ms 42960 KB Output is correct
61 Correct 610 ms 14940 KB Output is correct
62 Correct 643 ms 15056 KB Output is correct
63 Correct 1180 ms 15056 KB Output is correct
64 Correct 1223 ms 15440 KB Output is correct
65 Correct 992 ms 15440 KB Output is correct
66 Correct 811 ms 15440 KB Output is correct
67 Correct 756 ms 15440 KB Output is correct
68 Correct 681 ms 15568 KB Output is correct
69 Correct 744 ms 15036 KB Output is correct
70 Correct 900 ms 15056 KB Output is correct
71 Correct 893 ms 15440 KB Output is correct
72 Correct 834 ms 15440 KB Output is correct
73 Correct 648 ms 15184 KB Output is correct
74 Correct 776 ms 15056 KB Output is correct
75 Correct 719 ms 15056 KB Output is correct
76 Correct 764 ms 15824 KB Output is correct
77 Correct 761 ms 16080 KB Output is correct
78 Correct 755 ms 16036 KB Output is correct
79 Correct 1018 ms 15252 KB Output is correct
80 Correct 714 ms 14928 KB Output is correct
81 Correct 1052 ms 14924 KB Output is correct
82 Correct 690 ms 15056 KB Output is correct
83 Correct 442 ms 14800 KB Output is correct
84 Correct 969 ms 15184 KB Output is correct
85 Correct 1024 ms 15184 KB Output is correct
86 Correct 922 ms 15056 KB Output is correct
87 Correct 15 ms 14416 KB Output is correct
88 Correct 609 ms 33008 KB Output is correct
89 Correct 1090 ms 27128 KB Output is correct
90 Correct 1089 ms 26624 KB Output is correct
91 Correct 902 ms 34772 KB Output is correct
92 Correct 1054 ms 34764 KB Output is correct
93 Correct 1039 ms 34764 KB Output is correct
94 Correct 951 ms 34784 KB Output is correct
95 Correct 962 ms 34760 KB Output is correct
96 Correct 909 ms 25116 KB Output is correct
97 Correct 873 ms 25140 KB Output is correct
98 Correct 891 ms 34744 KB Output is correct
99 Correct 1004 ms 33580 KB Output is correct
100 Correct 1034 ms 29128 KB Output is correct
101 Correct 998 ms 27444 KB Output is correct
102 Correct 980 ms 25160 KB Output is correct
103 Correct 992 ms 43060 KB Output is correct
104 Correct 1000 ms 45348 KB Output is correct
105 Correct 966 ms 45380 KB Output is correct
106 Correct 1006 ms 28872 KB Output is correct
107 Correct 1047 ms 26168 KB Output is correct
108 Correct 782 ms 26056 KB Output is correct
109 Correct 1045 ms 25392 KB Output is correct