답안 #966091

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966091 2024-04-19T11:16:59 Z bachhoangxuan 디지털 회로 (IOI22_circuit) C++17
100 / 100
746 ms 29076 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn = 2e5+5;
const int mod = 1e9+2022;
int N,M,sz[maxn],suf[maxn],dp[maxn];
vector<int> A;
vector<int> edge[maxn];

struct node{
    int lazy=0;
    int total[2];
    node(){
        memset(total,0,sizeof(total));
    }
    friend node operator+(node a,node b){
        node res;
        for(int i=0;i<=1;i++) res.total[i]=(a.total[i]+b.total[i])%mod;
        return res;
    }
}tree[2*maxn];

void build(int l,int r,int id){
    if(l==r){
        tree[id].total[A[l]]=dp[N+l];
        return;
    }
    int mid=(l+r)>>1;
    build(l,mid,id<<1);build(mid+1,r,id<<1|1);
    tree[id]=tree[id<<1]+tree[id<<1|1];
}

void getnew(int id){
    tree[id].lazy^=1;
    swap(tree[id].total[0],tree[id].total[1]);
}
void pushdown(int id){
    if(tree[id].lazy){
        getnew(id<<1);
        getnew(id<<1|1);
        tree[id].lazy=0;
    }
}
void update(int l,int r,int id,int tl,int tr){
    if(tr<l || r<tl) return;
    if(tl<=l && r<=tr){
        getnew(id);
        return;
    }
    pushdown(id);
    int mid=(l+r)>>1;
    update(l,mid,id<<1,tl,tr);update(mid+1,r,id<<1|1,tl,tr);
    tree[id]=tree[id<<1]+tree[id<<1|1];
}

void init(int _N, int _M, vector<int> P, vector<int> _A) {
    N=_N;M=_M;A=_A;
    for(int i=1;i<N+M;i++){
        edge[P[i]].push_back(i);
        sz[P[i]]++;
    }
    function<void(int)> pre_dfs = [&](int u){
        dp[u]=max(sz[u],1);
        for(int v:edge[u]) pre_dfs(v),dp[u]=1LL*dp[u]*dp[v]%mod;
        //cout << "dp " << u << ' ' << dp[u] << '\n';
    };
    pre_dfs(0);
    function<void(int)> dfs = [&](int u){
        int cur=1;
        for(int i=(int)edge[u].size()-1;i>=0;i--){
            int v=edge[u][i];suf[v]=cur;
            cur=1LL*cur*dp[v]%mod;
        }
        cur=1;
        for(int v:edge[u]){
            int cc=dp[v];
            dp[v]=1LL*cur*suf[v]%mod*dp[u]%mod;
            dfs(v);cur=1LL*cur*cc%mod;
        }
    };
    dp[0]=1;dfs(0);
    //for(int i=0;i<N+M;i++) cout << dp[i] << ' ';
    //cout << '\n';
    build(0,M-1,1);
}

int count_ways(int L, int R) {
    update(0,M-1,1,L-N,R-N);
    return tree[1].total[1];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 3 ms 10860 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 2 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10836 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 3 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 3 ms 10840 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 3 ms 10840 KB Output is correct
12 Correct 2 ms 10840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 3 ms 10860 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 2 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 2 ms 10836 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 2 ms 10840 KB Output is correct
13 Correct 2 ms 10840 KB Output is correct
14 Correct 2 ms 10840 KB Output is correct
15 Correct 3 ms 10840 KB Output is correct
16 Correct 2 ms 10840 KB Output is correct
17 Correct 3 ms 10840 KB Output is correct
18 Correct 2 ms 10840 KB Output is correct
19 Correct 3 ms 10840 KB Output is correct
20 Correct 2 ms 10840 KB Output is correct
21 Correct 2 ms 10840 KB Output is correct
22 Correct 2 ms 10664 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 2 ms 10884 KB Output is correct
25 Correct 4 ms 10840 KB Output is correct
26 Correct 3 ms 10840 KB Output is correct
27 Correct 3 ms 10840 KB Output is correct
28 Correct 3 ms 10840 KB Output is correct
29 Correct 2 ms 10840 KB Output is correct
30 Correct 2 ms 10864 KB Output is correct
31 Correct 2 ms 10840 KB Output is correct
32 Correct 2 ms 10840 KB Output is correct
33 Correct 3 ms 10676 KB Output is correct
34 Correct 2 ms 10840 KB Output is correct
35 Correct 2 ms 10840 KB Output is correct
36 Correct 3 ms 10840 KB Output is correct
37 Correct 3 ms 10840 KB Output is correct
38 Correct 3 ms 10840 KB Output is correct
39 Correct 2 ms 10840 KB Output is correct
40 Correct 2 ms 10840 KB Output is correct
41 Correct 2 ms 10840 KB Output is correct
42 Correct 2 ms 10840 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 439 ms 12892 KB Output is correct
2 Correct 640 ms 15236 KB Output is correct
3 Correct 573 ms 15184 KB Output is correct
4 Correct 612 ms 15192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 439 ms 12892 KB Output is correct
2 Correct 640 ms 15236 KB Output is correct
3 Correct 573 ms 15184 KB Output is correct
4 Correct 612 ms 15192 KB Output is correct
5 Correct 460 ms 12804 KB Output is correct
6 Correct 635 ms 15240 KB Output is correct
7 Correct 618 ms 15192 KB Output is correct
8 Correct 551 ms 15192 KB Output is correct
9 Correct 303 ms 10840 KB Output is correct
10 Correct 603 ms 11104 KB Output is correct
11 Correct 607 ms 11096 KB Output is correct
12 Correct 601 ms 11096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10836 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 2 ms 10840 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 3 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 3 ms 10840 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 3 ms 10840 KB Output is correct
12 Correct 2 ms 10840 KB Output is correct
13 Correct 439 ms 12892 KB Output is correct
14 Correct 640 ms 15236 KB Output is correct
15 Correct 573 ms 15184 KB Output is correct
16 Correct 612 ms 15192 KB Output is correct
17 Correct 460 ms 12804 KB Output is correct
18 Correct 635 ms 15240 KB Output is correct
19 Correct 618 ms 15192 KB Output is correct
20 Correct 551 ms 15192 KB Output is correct
21 Correct 303 ms 10840 KB Output is correct
22 Correct 603 ms 11104 KB Output is correct
23 Correct 607 ms 11096 KB Output is correct
24 Correct 601 ms 11096 KB Output is correct
25 Correct 655 ms 17660 KB Output is correct
26 Correct 681 ms 17412 KB Output is correct
27 Correct 643 ms 17660 KB Output is correct
28 Correct 490 ms 17408 KB Output is correct
29 Correct 649 ms 28752 KB Output is correct
30 Correct 616 ms 28432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 3 ms 10860 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 2 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 2 ms 10836 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 2 ms 10840 KB Output is correct
13 Correct 2 ms 10840 KB Output is correct
14 Correct 2 ms 10840 KB Output is correct
15 Correct 3 ms 10840 KB Output is correct
16 Correct 2 ms 10840 KB Output is correct
17 Correct 3 ms 10840 KB Output is correct
18 Correct 2 ms 10840 KB Output is correct
19 Correct 3 ms 10840 KB Output is correct
20 Correct 2 ms 10840 KB Output is correct
21 Correct 2 ms 10840 KB Output is correct
22 Correct 2 ms 10664 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 2 ms 10884 KB Output is correct
25 Correct 4 ms 10840 KB Output is correct
26 Correct 3 ms 10840 KB Output is correct
27 Correct 3 ms 10840 KB Output is correct
28 Correct 3 ms 10840 KB Output is correct
29 Correct 2 ms 10840 KB Output is correct
30 Correct 2 ms 10864 KB Output is correct
31 Correct 2 ms 10840 KB Output is correct
32 Correct 2 ms 10840 KB Output is correct
33 Correct 3 ms 10676 KB Output is correct
34 Correct 2 ms 10840 KB Output is correct
35 Correct 2 ms 10840 KB Output is correct
36 Correct 3 ms 10840 KB Output is correct
37 Correct 3 ms 10840 KB Output is correct
38 Correct 3 ms 10840 KB Output is correct
39 Correct 2 ms 10840 KB Output is correct
40 Correct 2 ms 10840 KB Output is correct
41 Correct 2 ms 10840 KB Output is correct
42 Correct 2 ms 10840 KB Output is correct
43 Correct 402 ms 10840 KB Output is correct
44 Correct 570 ms 11096 KB Output is correct
45 Correct 595 ms 10840 KB Output is correct
46 Correct 533 ms 11096 KB Output is correct
47 Correct 565 ms 11096 KB Output is correct
48 Correct 592 ms 11096 KB Output is correct
49 Correct 572 ms 11096 KB Output is correct
50 Correct 532 ms 11096 KB Output is correct
51 Correct 561 ms 10840 KB Output is correct
52 Correct 612 ms 10840 KB Output is correct
53 Correct 526 ms 11608 KB Output is correct
54 Correct 548 ms 11096 KB Output is correct
55 Correct 620 ms 10840 KB Output is correct
56 Correct 574 ms 10840 KB Output is correct
57 Correct 589 ms 10840 KB Output is correct
58 Correct 584 ms 11608 KB Output is correct
59 Correct 549 ms 11856 KB Output is correct
60 Correct 555 ms 11764 KB Output is correct
61 Correct 593 ms 11096 KB Output is correct
62 Correct 556 ms 10840 KB Output is correct
63 Correct 553 ms 10840 KB Output is correct
64 Correct 568 ms 10840 KB Output is correct
65 Correct 294 ms 10840 KB Output is correct
66 Correct 552 ms 11096 KB Output is correct
67 Correct 582 ms 11096 KB Output is correct
68 Correct 523 ms 11096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10840 KB Output is correct
2 Correct 2 ms 10840 KB Output is correct
3 Correct 3 ms 10860 KB Output is correct
4 Correct 2 ms 10840 KB Output is correct
5 Correct 2 ms 10840 KB Output is correct
6 Correct 2 ms 10840 KB Output is correct
7 Correct 2 ms 10840 KB Output is correct
8 Correct 2 ms 10840 KB Output is correct
9 Correct 2 ms 10836 KB Output is correct
10 Correct 2 ms 10840 KB Output is correct
11 Correct 2 ms 10840 KB Output is correct
12 Correct 2 ms 10840 KB Output is correct
13 Correct 2 ms 10840 KB Output is correct
14 Correct 2 ms 10840 KB Output is correct
15 Correct 3 ms 10840 KB Output is correct
16 Correct 2 ms 10840 KB Output is correct
17 Correct 3 ms 10840 KB Output is correct
18 Correct 2 ms 10840 KB Output is correct
19 Correct 3 ms 10840 KB Output is correct
20 Correct 2 ms 10840 KB Output is correct
21 Correct 2 ms 10840 KB Output is correct
22 Correct 2 ms 10664 KB Output is correct
23 Correct 2 ms 10840 KB Output is correct
24 Correct 2 ms 10884 KB Output is correct
25 Correct 4 ms 10840 KB Output is correct
26 Correct 3 ms 10840 KB Output is correct
27 Correct 3 ms 10840 KB Output is correct
28 Correct 3 ms 10840 KB Output is correct
29 Correct 2 ms 10840 KB Output is correct
30 Correct 2 ms 10864 KB Output is correct
31 Correct 2 ms 10840 KB Output is correct
32 Correct 2 ms 10840 KB Output is correct
33 Correct 3 ms 10676 KB Output is correct
34 Correct 2 ms 10840 KB Output is correct
35 Correct 2 ms 10840 KB Output is correct
36 Correct 3 ms 10840 KB Output is correct
37 Correct 3 ms 10840 KB Output is correct
38 Correct 3 ms 10840 KB Output is correct
39 Correct 2 ms 10840 KB Output is correct
40 Correct 2 ms 10840 KB Output is correct
41 Correct 2 ms 10840 KB Output is correct
42 Correct 2 ms 10840 KB Output is correct
43 Correct 439 ms 12892 KB Output is correct
44 Correct 640 ms 15236 KB Output is correct
45 Correct 573 ms 15184 KB Output is correct
46 Correct 612 ms 15192 KB Output is correct
47 Correct 460 ms 12804 KB Output is correct
48 Correct 635 ms 15240 KB Output is correct
49 Correct 618 ms 15192 KB Output is correct
50 Correct 551 ms 15192 KB Output is correct
51 Correct 303 ms 10840 KB Output is correct
52 Correct 603 ms 11104 KB Output is correct
53 Correct 607 ms 11096 KB Output is correct
54 Correct 601 ms 11096 KB Output is correct
55 Correct 655 ms 17660 KB Output is correct
56 Correct 681 ms 17412 KB Output is correct
57 Correct 643 ms 17660 KB Output is correct
58 Correct 490 ms 17408 KB Output is correct
59 Correct 649 ms 28752 KB Output is correct
60 Correct 616 ms 28432 KB Output is correct
61 Correct 402 ms 10840 KB Output is correct
62 Correct 570 ms 11096 KB Output is correct
63 Correct 595 ms 10840 KB Output is correct
64 Correct 533 ms 11096 KB Output is correct
65 Correct 565 ms 11096 KB Output is correct
66 Correct 592 ms 11096 KB Output is correct
67 Correct 572 ms 11096 KB Output is correct
68 Correct 532 ms 11096 KB Output is correct
69 Correct 561 ms 10840 KB Output is correct
70 Correct 612 ms 10840 KB Output is correct
71 Correct 526 ms 11608 KB Output is correct
72 Correct 548 ms 11096 KB Output is correct
73 Correct 620 ms 10840 KB Output is correct
74 Correct 574 ms 10840 KB Output is correct
75 Correct 589 ms 10840 KB Output is correct
76 Correct 584 ms 11608 KB Output is correct
77 Correct 549 ms 11856 KB Output is correct
78 Correct 555 ms 11764 KB Output is correct
79 Correct 593 ms 11096 KB Output is correct
80 Correct 556 ms 10840 KB Output is correct
81 Correct 553 ms 10840 KB Output is correct
82 Correct 568 ms 10840 KB Output is correct
83 Correct 294 ms 10840 KB Output is correct
84 Correct 552 ms 11096 KB Output is correct
85 Correct 582 ms 11096 KB Output is correct
86 Correct 523 ms 11096 KB Output is correct
87 Correct 2 ms 10840 KB Output is correct
88 Correct 417 ms 16748 KB Output is correct
89 Correct 659 ms 15236 KB Output is correct
90 Correct 637 ms 14936 KB Output is correct
91 Correct 632 ms 17744 KB Output is correct
92 Correct 725 ms 17760 KB Output is correct
93 Correct 722 ms 17656 KB Output is correct
94 Correct 664 ms 17680 KB Output is correct
95 Correct 617 ms 17744 KB Output is correct
96 Correct 550 ms 13268 KB Output is correct
97 Correct 664 ms 13540 KB Output is correct
98 Correct 550 ms 26292 KB Output is correct
99 Correct 708 ms 17728 KB Output is correct
100 Correct 685 ms 15188 KB Output is correct
101 Correct 627 ms 14424 KB Output is correct
102 Correct 625 ms 13240 KB Output is correct
103 Correct 746 ms 28440 KB Output is correct
104 Correct 636 ms 29076 KB Output is correct
105 Correct 592 ms 29056 KB Output is correct
106 Correct 629 ms 17388 KB Output is correct
107 Correct 618 ms 13912 KB Output is correct
108 Correct 669 ms 13912 KB Output is correct
109 Correct 624 ms 13456 KB Output is correct