답안 #869245

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
869245 2023-11-03T16:38:57 Z abcvuitunggio 디지털 회로 (IOI22_circuit) C++17
100 / 100
681 ms 34732 KB
#include "circuit.h"
#include <vector>
using namespace std;
const int mod=1000002022;
struct T{
    int sum,val;
}st[800001];
T operator +(T a, T b){
    return {(a.sum+b.sum)%mod,(a.val+b.val)%mod};
}
int n,a[200001],b[200001],lazy[800001],c[200001];
void down(int node, int l, int r){
    if (!lazy[node]||l==r)
        return;
    st[node<<1].val=(st[node<<1].sum-st[node<<1].val+mod)%mod;
    lazy[node<<1]^=1;
    st[node<<1|1].val=(st[node<<1|1].sum-st[node<<1|1].val+mod)%mod;
    lazy[node<<1|1]^=1;
    lazy[node]=0;
}
void build(int node, int l, int r){
    if (l==r){
        st[node]={b[l],a[l]*b[l]};
        return;
    }
    int mid=(l+r)>>1;
    build(node<<1,l,mid);
    build(node<<1|1,mid+1,r);
    st[node]=st[node<<1]+st[node<<1|1];
}
void update(int node, int l, int r, int u, int v){
    if (l>v||r<u||l>r||u>v)
        return;
    if (l>=u&&r<=v){
        lazy[node]^=1;
        st[node].val=(st[node].sum-st[node].val+mod)%mod;
        return;
    }
    down(node,l,r);
    int mid=(l+r)>>1;
    update(node<<1,l,mid,u,v);
    update(node<<1|1,mid+1,r,u,v);
    st[node]=st[node<<1]+st[node<<1|1];
}
vector <int> ke[200001];
void dfs(int u){
    if (ke[u].empty()){
        c[u]=1;
        return;
    }
    c[u]=ke[u].size();
    for (int v:ke[u]){
        dfs(v);
        c[u]=1LL*c[u]*c[v]%mod;
    }
}
void dfs2(int u, int val){
    if (ke[u].empty()){
        b[u]=val;
        return;
    }
    int d[ke[u].size()];
    for (int i=0;i<ke[u].size();i++)
        d[i]=1LL*(i?d[i-1]:1)*c[ke[u][i]]%mod;
    int cur=1;
    for (int i=ke[u].size()-1;i>=0;i--){
        dfs2(ke[u][i],(1LL*cur*(i?d[i-1]:1)%mod*val)%mod);
        cur=1LL*cur*c[ke[u][i]]%mod;
    }
}
void init(int N, int M, vector <int> P, vector <int> A){
    n=N+M;
    for (int i=0;i<M;i++)
        a[N+i]=A[i];
    for (int i=1;i<N+M;i++)
        ke[P[i]].push_back(i);
    dfs(0);
    dfs2(0,1);
    build(1,0,n-1);
}
int count_ways(int L, int R){
    update(1,0,n-1,L,R);
    return st[1].val;
}

Compilation message

circuit.cpp: In function 'void dfs2(int, int)':
circuit.cpp:63:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   63 |     for (int i=0;i<ke[u].size();i++)
      |                  ~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9560 KB Output is correct
3 Correct 2 ms 9560 KB Output is correct
4 Correct 2 ms 9560 KB Output is correct
5 Correct 2 ms 9560 KB Output is correct
6 Correct 2 ms 9560 KB Output is correct
7 Correct 2 ms 9560 KB Output is correct
8 Correct 2 ms 9560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9560 KB Output is correct
3 Correct 2 ms 9560 KB Output is correct
4 Correct 2 ms 9560 KB Output is correct
5 Correct 2 ms 9560 KB Output is correct
6 Correct 2 ms 9560 KB Output is correct
7 Correct 2 ms 9560 KB Output is correct
8 Correct 2 ms 9560 KB Output is correct
9 Correct 2 ms 9604 KB Output is correct
10 Correct 3 ms 9816 KB Output is correct
11 Correct 2 ms 9816 KB Output is correct
12 Correct 2 ms 9560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9560 KB Output is correct
3 Correct 2 ms 9560 KB Output is correct
4 Correct 2 ms 9560 KB Output is correct
5 Correct 2 ms 9560 KB Output is correct
6 Correct 2 ms 9560 KB Output is correct
7 Correct 2 ms 9560 KB Output is correct
8 Correct 2 ms 9560 KB Output is correct
9 Correct 2 ms 9560 KB Output is correct
10 Correct 2 ms 9560 KB Output is correct
11 Correct 2 ms 9560 KB Output is correct
12 Correct 2 ms 9560 KB Output is correct
13 Correct 2 ms 9560 KB Output is correct
14 Correct 2 ms 9560 KB Output is correct
15 Correct 2 ms 9560 KB Output is correct
16 Correct 2 ms 9560 KB Output is correct
17 Correct 2 ms 9604 KB Output is correct
18 Correct 3 ms 9816 KB Output is correct
19 Correct 2 ms 9816 KB Output is correct
20 Correct 2 ms 9560 KB Output is correct
21 Correct 2 ms 9560 KB Output is correct
22 Correct 2 ms 9560 KB Output is correct
23 Correct 2 ms 9560 KB Output is correct
24 Correct 2 ms 9560 KB Output is correct
25 Correct 2 ms 9560 KB Output is correct
26 Correct 2 ms 9560 KB Output is correct
27 Correct 2 ms 9560 KB Output is correct
28 Correct 2 ms 9560 KB Output is correct
29 Correct 2 ms 9560 KB Output is correct
30 Correct 2 ms 9560 KB Output is correct
31 Correct 2 ms 9816 KB Output is correct
32 Correct 2 ms 9560 KB Output is correct
33 Correct 2 ms 9560 KB Output is correct
34 Correct 2 ms 9560 KB Output is correct
35 Correct 2 ms 9560 KB Output is correct
36 Correct 2 ms 9816 KB Output is correct
37 Correct 2 ms 9816 KB Output is correct
38 Correct 2 ms 9816 KB Output is correct
39 Correct 2 ms 9560 KB Output is correct
40 Correct 2 ms 9560 KB Output is correct
41 Correct 2 ms 9560 KB Output is correct
42 Correct 2 ms 9560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 366 ms 11324 KB Output is correct
2 Correct 546 ms 17348 KB Output is correct
3 Correct 537 ms 17608 KB Output is correct
4 Correct 546 ms 17344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 366 ms 11324 KB Output is correct
2 Correct 546 ms 17348 KB Output is correct
3 Correct 537 ms 17608 KB Output is correct
4 Correct 546 ms 17344 KB Output is correct
5 Correct 454 ms 11364 KB Output is correct
6 Correct 579 ms 17340 KB Output is correct
7 Correct 583 ms 17252 KB Output is correct
8 Correct 558 ms 17340 KB Output is correct
9 Correct 266 ms 9560 KB Output is correct
10 Correct 514 ms 9816 KB Output is correct
11 Correct 538 ms 9816 KB Output is correct
12 Correct 520 ms 9816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9560 KB Output is correct
3 Correct 2 ms 9560 KB Output is correct
4 Correct 2 ms 9560 KB Output is correct
5 Correct 2 ms 9560 KB Output is correct
6 Correct 2 ms 9560 KB Output is correct
7 Correct 2 ms 9560 KB Output is correct
8 Correct 2 ms 9560 KB Output is correct
9 Correct 2 ms 9604 KB Output is correct
10 Correct 3 ms 9816 KB Output is correct
11 Correct 2 ms 9816 KB Output is correct
12 Correct 2 ms 9560 KB Output is correct
13 Correct 366 ms 11324 KB Output is correct
14 Correct 546 ms 17348 KB Output is correct
15 Correct 537 ms 17608 KB Output is correct
16 Correct 546 ms 17344 KB Output is correct
17 Correct 454 ms 11364 KB Output is correct
18 Correct 579 ms 17340 KB Output is correct
19 Correct 583 ms 17252 KB Output is correct
20 Correct 558 ms 17340 KB Output is correct
21 Correct 266 ms 9560 KB Output is correct
22 Correct 514 ms 9816 KB Output is correct
23 Correct 538 ms 9816 KB Output is correct
24 Correct 520 ms 9816 KB Output is correct
25 Correct 566 ms 21024 KB Output is correct
26 Correct 628 ms 21240 KB Output is correct
27 Correct 611 ms 21288 KB Output is correct
28 Correct 455 ms 21056 KB Output is correct
29 Correct 613 ms 33592 KB Output is correct
30 Correct 623 ms 33848 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9560 KB Output is correct
3 Correct 2 ms 9560 KB Output is correct
4 Correct 2 ms 9560 KB Output is correct
5 Correct 2 ms 9560 KB Output is correct
6 Correct 2 ms 9560 KB Output is correct
7 Correct 2 ms 9560 KB Output is correct
8 Correct 2 ms 9560 KB Output is correct
9 Correct 2 ms 9560 KB Output is correct
10 Correct 2 ms 9560 KB Output is correct
11 Correct 2 ms 9560 KB Output is correct
12 Correct 2 ms 9560 KB Output is correct
13 Correct 2 ms 9560 KB Output is correct
14 Correct 2 ms 9560 KB Output is correct
15 Correct 2 ms 9560 KB Output is correct
16 Correct 2 ms 9560 KB Output is correct
17 Correct 2 ms 9604 KB Output is correct
18 Correct 3 ms 9816 KB Output is correct
19 Correct 2 ms 9816 KB Output is correct
20 Correct 2 ms 9560 KB Output is correct
21 Correct 2 ms 9560 KB Output is correct
22 Correct 2 ms 9560 KB Output is correct
23 Correct 2 ms 9560 KB Output is correct
24 Correct 2 ms 9560 KB Output is correct
25 Correct 2 ms 9560 KB Output is correct
26 Correct 2 ms 9560 KB Output is correct
27 Correct 2 ms 9560 KB Output is correct
28 Correct 2 ms 9560 KB Output is correct
29 Correct 2 ms 9560 KB Output is correct
30 Correct 2 ms 9560 KB Output is correct
31 Correct 2 ms 9816 KB Output is correct
32 Correct 2 ms 9560 KB Output is correct
33 Correct 2 ms 9560 KB Output is correct
34 Correct 2 ms 9560 KB Output is correct
35 Correct 2 ms 9560 KB Output is correct
36 Correct 2 ms 9816 KB Output is correct
37 Correct 2 ms 9816 KB Output is correct
38 Correct 2 ms 9816 KB Output is correct
39 Correct 2 ms 9560 KB Output is correct
40 Correct 2 ms 9560 KB Output is correct
41 Correct 2 ms 9560 KB Output is correct
42 Correct 2 ms 9560 KB Output is correct
43 Correct 347 ms 10072 KB Output is correct
44 Correct 541 ms 9816 KB Output is correct
45 Correct 530 ms 9816 KB Output is correct
46 Correct 548 ms 10072 KB Output is correct
47 Correct 525 ms 10072 KB Output is correct
48 Correct 525 ms 10076 KB Output is correct
49 Correct 516 ms 9816 KB Output is correct
50 Correct 514 ms 9816 KB Output is correct
51 Correct 500 ms 9816 KB Output is correct
52 Correct 503 ms 10072 KB Output is correct
53 Correct 511 ms 10324 KB Output is correct
54 Correct 586 ms 9816 KB Output is correct
55 Correct 544 ms 10072 KB Output is correct
56 Correct 570 ms 9816 KB Output is correct
57 Correct 535 ms 10072 KB Output is correct
58 Correct 577 ms 10656 KB Output is correct
59 Correct 548 ms 10692 KB Output is correct
60 Correct 561 ms 10840 KB Output is correct
61 Correct 532 ms 9816 KB Output is correct
62 Correct 577 ms 9816 KB Output is correct
63 Correct 558 ms 9816 KB Output is correct
64 Correct 539 ms 10072 KB Output is correct
65 Correct 275 ms 9560 KB Output is correct
66 Correct 545 ms 9816 KB Output is correct
67 Correct 520 ms 9816 KB Output is correct
68 Correct 547 ms 9816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9560 KB Output is correct
2 Correct 2 ms 9560 KB Output is correct
3 Correct 2 ms 9560 KB Output is correct
4 Correct 2 ms 9560 KB Output is correct
5 Correct 2 ms 9560 KB Output is correct
6 Correct 2 ms 9560 KB Output is correct
7 Correct 2 ms 9560 KB Output is correct
8 Correct 2 ms 9560 KB Output is correct
9 Correct 2 ms 9560 KB Output is correct
10 Correct 2 ms 9560 KB Output is correct
11 Correct 2 ms 9560 KB Output is correct
12 Correct 2 ms 9560 KB Output is correct
13 Correct 2 ms 9560 KB Output is correct
14 Correct 2 ms 9560 KB Output is correct
15 Correct 2 ms 9560 KB Output is correct
16 Correct 2 ms 9560 KB Output is correct
17 Correct 2 ms 9604 KB Output is correct
18 Correct 3 ms 9816 KB Output is correct
19 Correct 2 ms 9816 KB Output is correct
20 Correct 2 ms 9560 KB Output is correct
21 Correct 2 ms 9560 KB Output is correct
22 Correct 2 ms 9560 KB Output is correct
23 Correct 2 ms 9560 KB Output is correct
24 Correct 2 ms 9560 KB Output is correct
25 Correct 2 ms 9560 KB Output is correct
26 Correct 2 ms 9560 KB Output is correct
27 Correct 2 ms 9560 KB Output is correct
28 Correct 2 ms 9560 KB Output is correct
29 Correct 2 ms 9560 KB Output is correct
30 Correct 2 ms 9560 KB Output is correct
31 Correct 2 ms 9816 KB Output is correct
32 Correct 2 ms 9560 KB Output is correct
33 Correct 2 ms 9560 KB Output is correct
34 Correct 2 ms 9560 KB Output is correct
35 Correct 2 ms 9560 KB Output is correct
36 Correct 2 ms 9816 KB Output is correct
37 Correct 2 ms 9816 KB Output is correct
38 Correct 2 ms 9816 KB Output is correct
39 Correct 2 ms 9560 KB Output is correct
40 Correct 2 ms 9560 KB Output is correct
41 Correct 2 ms 9560 KB Output is correct
42 Correct 2 ms 9560 KB Output is correct
43 Correct 366 ms 11324 KB Output is correct
44 Correct 546 ms 17348 KB Output is correct
45 Correct 537 ms 17608 KB Output is correct
46 Correct 546 ms 17344 KB Output is correct
47 Correct 454 ms 11364 KB Output is correct
48 Correct 579 ms 17340 KB Output is correct
49 Correct 583 ms 17252 KB Output is correct
50 Correct 558 ms 17340 KB Output is correct
51 Correct 266 ms 9560 KB Output is correct
52 Correct 514 ms 9816 KB Output is correct
53 Correct 538 ms 9816 KB Output is correct
54 Correct 520 ms 9816 KB Output is correct
55 Correct 566 ms 21024 KB Output is correct
56 Correct 628 ms 21240 KB Output is correct
57 Correct 611 ms 21288 KB Output is correct
58 Correct 455 ms 21056 KB Output is correct
59 Correct 613 ms 33592 KB Output is correct
60 Correct 623 ms 33848 KB Output is correct
61 Correct 347 ms 10072 KB Output is correct
62 Correct 541 ms 9816 KB Output is correct
63 Correct 530 ms 9816 KB Output is correct
64 Correct 548 ms 10072 KB Output is correct
65 Correct 525 ms 10072 KB Output is correct
66 Correct 525 ms 10076 KB Output is correct
67 Correct 516 ms 9816 KB Output is correct
68 Correct 514 ms 9816 KB Output is correct
69 Correct 500 ms 9816 KB Output is correct
70 Correct 503 ms 10072 KB Output is correct
71 Correct 511 ms 10324 KB Output is correct
72 Correct 586 ms 9816 KB Output is correct
73 Correct 544 ms 10072 KB Output is correct
74 Correct 570 ms 9816 KB Output is correct
75 Correct 535 ms 10072 KB Output is correct
76 Correct 577 ms 10656 KB Output is correct
77 Correct 548 ms 10692 KB Output is correct
78 Correct 561 ms 10840 KB Output is correct
79 Correct 532 ms 9816 KB Output is correct
80 Correct 577 ms 9816 KB Output is correct
81 Correct 558 ms 9816 KB Output is correct
82 Correct 539 ms 10072 KB Output is correct
83 Correct 275 ms 9560 KB Output is correct
84 Correct 545 ms 9816 KB Output is correct
85 Correct 520 ms 9816 KB Output is correct
86 Correct 547 ms 9816 KB Output is correct
87 Correct 2 ms 9560 KB Output is correct
88 Correct 365 ms 20644 KB Output is correct
89 Correct 624 ms 17500 KB Output is correct
90 Correct 568 ms 17240 KB Output is correct
91 Correct 616 ms 21728 KB Output is correct
92 Correct 657 ms 21320 KB Output is correct
93 Correct 666 ms 21316 KB Output is correct
94 Correct 679 ms 21328 KB Output is correct
95 Correct 631 ms 21328 KB Output is correct
96 Correct 552 ms 14032 KB Output is correct
97 Correct 565 ms 14520 KB Output is correct
98 Correct 520 ms 27956 KB Output is correct
99 Correct 586 ms 21052 KB Output is correct
100 Correct 589 ms 19316 KB Output is correct
101 Correct 597 ms 17068 KB Output is correct
102 Correct 610 ms 14012 KB Output is correct
103 Correct 681 ms 33616 KB Output is correct
104 Correct 609 ms 34732 KB Output is correct
105 Correct 596 ms 34716 KB Output is correct
106 Correct 577 ms 20012 KB Output is correct
107 Correct 574 ms 15024 KB Output is correct
108 Correct 573 ms 14260 KB Output is correct
109 Correct 623 ms 14264 KB Output is correct