답안 #791559

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
791559 2023-07-24T07:24:19 Z WongChun1234 디지털 회로 (IOI22_circuit) C++17
100 / 100
925 ms 40048 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200050;
const ll MOD=1000002022;
int n,m,lz[N<<2];
ll dp[N],rdp[N],seg[N<<2],iseg[N<<2];
vector<int> p,a;
vector<ll> ch[N],pref[N],suff[N];
void build(int id,int l,int r){
	if (l==r){
		seg[id]=a[l-1]*rdp[l+n-1];
		iseg[id]=(!a[l-1])*rdp[l+n-1];
		//cout<<id<<" "<<l<<" "<<r<<" "<<seg[id]<<" "<<iseg[id]<<"\n";
		return;
	}
	int m=(l+r)/2;
	build(id*2,l,m);
	build(id*2+1,m+1,r);
	seg[id]=(seg[id*2]+seg[id*2+1])%MOD;
	iseg[id]=(iseg[id*2]+iseg[id*2+1])%MOD;
	//cout<<id<<" "<<l<<" "<<r<<" "<<seg[id]<<" "<<iseg[id]<<"\n";
}
void pushdown(int id){
	lz[id]^=1;
	swap(seg[id],iseg[id]);
}
void update(int id,int l,int r,int ql,int qr){
	if (l>=ql&&r<=qr){
		pushdown(id);
		return;
	}
	if (l>qr||r<ql) return;
	if (lz[id]){
		pushdown(id*2);
		pushdown(id*2+1);
		lz[id]=0;
	}
	int m=(l+r)/2;
	update(id*2,l,m,ql,qr);
	update(id*2+1,m+1,r,ql,qr);
	seg[id]=(seg[id*2]+seg[id*2+1])%MOD;
	iseg[id]=(iseg[id*2]+iseg[id*2+1])%MOD;
}
void init(int N, int M, vector<int> P, vector<int> A) {
	n=N,m=M,p=P,a=A;
	for (int i=1;i<n+m;i++) ch[p[i]].push_back(i);
	for (int i=n+m-1;i>=n;i--){
		dp[i]=1;
	}
	for (int i=n-1;i>=0;i--){
		pref[i].push_back(1),suff[i].push_back(1);
		for (int j:ch[i]) pref[i].push_back(dp[j]),suff[i].push_back(dp[j]);
		pref[i].push_back(1),suff[i].push_back(1);
		for (int j=1;j<=ch[i].size();j++) pref[i][j]=pref[i][j-1]*pref[i][j]%MOD;
		for (int j=ch[i].size();j>=1;j--) suff[i][j]=suff[i][j+1]*suff[i][j]%MOD;
		dp[i]=suff[i][1]*ch[i].size()%MOD;
	}
	rdp[0]=1;
	for (int i=0;i<n;i++){
		for (int j=1;j<=ch[i].size();j++) rdp[ch[i][j-1]]=rdp[i]*(pref[i][j-1]*suff[i][j+1]%MOD)%MOD;
	}
	//for (int i=0;i<n+m;i++) cout<<dp[i]<<" "<<rdp[i]<<"\n";
	build(1,1,m);
}

int count_ways(int L, int R) {
	update(1,1,m,L-n+1,R-n+1);
	return seg[1];
}

Compilation message

circuit.cpp: In function 'void init(int, int, std::vector<int>, std::vector<int>)':
circuit.cpp:56:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |   for (int j=1;j<=ch[i].size();j++) pref[i][j]=pref[i][j-1]*pref[i][j]%MOD;
      |                ~^~~~~~~~~~~~~~
circuit.cpp:62:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   62 |   for (int j=1;j<=ch[i].size();j++) rdp[ch[i][j-1]]=rdp[i]*(pref[i][j-1]*suff[i][j+1]%MOD)%MOD;
      |                ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 8 ms 14332 KB Output is correct
3 Correct 7 ms 14556 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 8 ms 14512 KB Output is correct
6 Correct 9 ms 14416 KB Output is correct
7 Correct 7 ms 14544 KB Output is correct
8 Correct 8 ms 14492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 8 ms 14424 KB Output is correct
3 Correct 8 ms 14468 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 8 ms 14544 KB Output is correct
6 Correct 8 ms 14544 KB Output is correct
7 Correct 8 ms 14560 KB Output is correct
8 Correct 9 ms 14544 KB Output is correct
9 Correct 9 ms 14544 KB Output is correct
10 Correct 8 ms 14644 KB Output is correct
11 Correct 8 ms 14544 KB Output is correct
12 Correct 7 ms 14544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 8 ms 14332 KB Output is correct
3 Correct 7 ms 14556 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 8 ms 14512 KB Output is correct
6 Correct 9 ms 14416 KB Output is correct
7 Correct 7 ms 14544 KB Output is correct
8 Correct 8 ms 14492 KB Output is correct
9 Correct 7 ms 14416 KB Output is correct
10 Correct 8 ms 14424 KB Output is correct
11 Correct 8 ms 14468 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
13 Correct 8 ms 14544 KB Output is correct
14 Correct 8 ms 14544 KB Output is correct
15 Correct 8 ms 14560 KB Output is correct
16 Correct 9 ms 14544 KB Output is correct
17 Correct 9 ms 14544 KB Output is correct
18 Correct 8 ms 14644 KB Output is correct
19 Correct 8 ms 14544 KB Output is correct
20 Correct 7 ms 14544 KB Output is correct
21 Correct 7 ms 14636 KB Output is correct
22 Correct 9 ms 14588 KB Output is correct
23 Correct 7 ms 14528 KB Output is correct
24 Correct 9 ms 14672 KB Output is correct
25 Correct 10 ms 14648 KB Output is correct
26 Correct 8 ms 14672 KB Output is correct
27 Correct 8 ms 14672 KB Output is correct
28 Correct 10 ms 14672 KB Output is correct
29 Correct 7 ms 14544 KB Output is correct
30 Correct 7 ms 14544 KB Output is correct
31 Correct 8 ms 14536 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 14544 KB Output is correct
35 Correct 7 ms 14488 KB Output is correct
36 Correct 7 ms 14652 KB Output is correct
37 Correct 8 ms 14672 KB Output is correct
38 Correct 7 ms 14672 KB Output is correct
39 Correct 7 ms 14456 KB Output is correct
40 Correct 8 ms 14568 KB Output is correct
41 Correct 7 ms 14544 KB Output is correct
42 Correct 7 ms 14544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 447 ms 21676 KB Output is correct
2 Correct 854 ms 28972 KB Output is correct
3 Correct 842 ms 29000 KB Output is correct
4 Correct 638 ms 28996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 447 ms 21676 KB Output is correct
2 Correct 854 ms 28972 KB Output is correct
3 Correct 842 ms 29000 KB Output is correct
4 Correct 638 ms 28996 KB Output is correct
5 Correct 619 ms 21704 KB Output is correct
6 Correct 721 ms 29000 KB Output is correct
7 Correct 741 ms 29052 KB Output is correct
8 Correct 674 ms 28964 KB Output is correct
9 Correct 395 ms 14800 KB Output is correct
10 Correct 728 ms 15352 KB Output is correct
11 Correct 796 ms 15348 KB Output is correct
12 Correct 797 ms 15344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 8 ms 14424 KB Output is correct
3 Correct 8 ms 14468 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 8 ms 14544 KB Output is correct
6 Correct 8 ms 14544 KB Output is correct
7 Correct 8 ms 14560 KB Output is correct
8 Correct 9 ms 14544 KB Output is correct
9 Correct 9 ms 14544 KB Output is correct
10 Correct 8 ms 14644 KB Output is correct
11 Correct 8 ms 14544 KB Output is correct
12 Correct 7 ms 14544 KB Output is correct
13 Correct 447 ms 21676 KB Output is correct
14 Correct 854 ms 28972 KB Output is correct
15 Correct 842 ms 29000 KB Output is correct
16 Correct 638 ms 28996 KB Output is correct
17 Correct 619 ms 21704 KB Output is correct
18 Correct 721 ms 29000 KB Output is correct
19 Correct 741 ms 29052 KB Output is correct
20 Correct 674 ms 28964 KB Output is correct
21 Correct 395 ms 14800 KB Output is correct
22 Correct 728 ms 15352 KB Output is correct
23 Correct 796 ms 15348 KB Output is correct
24 Correct 797 ms 15344 KB Output is correct
25 Correct 908 ms 37296 KB Output is correct
26 Correct 770 ms 37680 KB Output is correct
27 Correct 925 ms 37680 KB Output is correct
28 Correct 683 ms 37684 KB Output is correct
29 Correct 784 ms 37644 KB Output is correct
30 Correct 861 ms 37668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 8 ms 14332 KB Output is correct
3 Correct 7 ms 14556 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 8 ms 14512 KB Output is correct
6 Correct 9 ms 14416 KB Output is correct
7 Correct 7 ms 14544 KB Output is correct
8 Correct 8 ms 14492 KB Output is correct
9 Correct 7 ms 14416 KB Output is correct
10 Correct 8 ms 14424 KB Output is correct
11 Correct 8 ms 14468 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
13 Correct 8 ms 14544 KB Output is correct
14 Correct 8 ms 14544 KB Output is correct
15 Correct 8 ms 14560 KB Output is correct
16 Correct 9 ms 14544 KB Output is correct
17 Correct 9 ms 14544 KB Output is correct
18 Correct 8 ms 14644 KB Output is correct
19 Correct 8 ms 14544 KB Output is correct
20 Correct 7 ms 14544 KB Output is correct
21 Correct 7 ms 14636 KB Output is correct
22 Correct 9 ms 14588 KB Output is correct
23 Correct 7 ms 14528 KB Output is correct
24 Correct 9 ms 14672 KB Output is correct
25 Correct 10 ms 14648 KB Output is correct
26 Correct 8 ms 14672 KB Output is correct
27 Correct 8 ms 14672 KB Output is correct
28 Correct 10 ms 14672 KB Output is correct
29 Correct 7 ms 14544 KB Output is correct
30 Correct 7 ms 14544 KB Output is correct
31 Correct 8 ms 14536 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 14544 KB Output is correct
35 Correct 7 ms 14488 KB Output is correct
36 Correct 7 ms 14652 KB Output is correct
37 Correct 8 ms 14672 KB Output is correct
38 Correct 7 ms 14672 KB Output is correct
39 Correct 7 ms 14456 KB Output is correct
40 Correct 8 ms 14568 KB Output is correct
41 Correct 7 ms 14544 KB Output is correct
42 Correct 7 ms 14544 KB Output is correct
43 Correct 478 ms 15184 KB Output is correct
44 Correct 695 ms 15292 KB Output is correct
45 Correct 735 ms 15312 KB Output is correct
46 Correct 826 ms 15668 KB Output is correct
47 Correct 815 ms 15696 KB Output is correct
48 Correct 534 ms 15736 KB Output is correct
49 Correct 622 ms 15696 KB Output is correct
50 Correct 583 ms 15696 KB Output is correct
51 Correct 787 ms 15112 KB Output is correct
52 Correct 799 ms 15148 KB Output is correct
53 Correct 726 ms 15156 KB Output is correct
54 Correct 791 ms 15680 KB Output is correct
55 Correct 650 ms 15548 KB Output is correct
56 Correct 496 ms 15256 KB Output is correct
57 Correct 752 ms 15060 KB Output is correct
58 Correct 776 ms 15680 KB Output is correct
59 Correct 708 ms 15820 KB Output is correct
60 Correct 724 ms 15776 KB Output is correct
61 Correct 652 ms 15328 KB Output is correct
62 Correct 581 ms 15036 KB Output is correct
63 Correct 646 ms 15028 KB Output is correct
64 Correct 599 ms 15028 KB Output is correct
65 Correct 340 ms 14800 KB Output is correct
66 Correct 709 ms 15348 KB Output is correct
67 Correct 660 ms 15356 KB Output is correct
68 Correct 585 ms 15340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14416 KB Output is correct
2 Correct 8 ms 14332 KB Output is correct
3 Correct 7 ms 14556 KB Output is correct
4 Correct 7 ms 14416 KB Output is correct
5 Correct 8 ms 14512 KB Output is correct
6 Correct 9 ms 14416 KB Output is correct
7 Correct 7 ms 14544 KB Output is correct
8 Correct 8 ms 14492 KB Output is correct
9 Correct 7 ms 14416 KB Output is correct
10 Correct 8 ms 14424 KB Output is correct
11 Correct 8 ms 14468 KB Output is correct
12 Correct 7 ms 14416 KB Output is correct
13 Correct 8 ms 14544 KB Output is correct
14 Correct 8 ms 14544 KB Output is correct
15 Correct 8 ms 14560 KB Output is correct
16 Correct 9 ms 14544 KB Output is correct
17 Correct 9 ms 14544 KB Output is correct
18 Correct 8 ms 14644 KB Output is correct
19 Correct 8 ms 14544 KB Output is correct
20 Correct 7 ms 14544 KB Output is correct
21 Correct 7 ms 14636 KB Output is correct
22 Correct 9 ms 14588 KB Output is correct
23 Correct 7 ms 14528 KB Output is correct
24 Correct 9 ms 14672 KB Output is correct
25 Correct 10 ms 14648 KB Output is correct
26 Correct 8 ms 14672 KB Output is correct
27 Correct 8 ms 14672 KB Output is correct
28 Correct 10 ms 14672 KB Output is correct
29 Correct 7 ms 14544 KB Output is correct
30 Correct 7 ms 14544 KB Output is correct
31 Correct 8 ms 14536 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 14544 KB Output is correct
35 Correct 7 ms 14488 KB Output is correct
36 Correct 7 ms 14652 KB Output is correct
37 Correct 8 ms 14672 KB Output is correct
38 Correct 7 ms 14672 KB Output is correct
39 Correct 7 ms 14456 KB Output is correct
40 Correct 8 ms 14568 KB Output is correct
41 Correct 7 ms 14544 KB Output is correct
42 Correct 7 ms 14544 KB Output is correct
43 Correct 447 ms 21676 KB Output is correct
44 Correct 854 ms 28972 KB Output is correct
45 Correct 842 ms 29000 KB Output is correct
46 Correct 638 ms 28996 KB Output is correct
47 Correct 619 ms 21704 KB Output is correct
48 Correct 721 ms 29000 KB Output is correct
49 Correct 741 ms 29052 KB Output is correct
50 Correct 674 ms 28964 KB Output is correct
51 Correct 395 ms 14800 KB Output is correct
52 Correct 728 ms 15352 KB Output is correct
53 Correct 796 ms 15348 KB Output is correct
54 Correct 797 ms 15344 KB Output is correct
55 Correct 908 ms 37296 KB Output is correct
56 Correct 770 ms 37680 KB Output is correct
57 Correct 925 ms 37680 KB Output is correct
58 Correct 683 ms 37684 KB Output is correct
59 Correct 784 ms 37644 KB Output is correct
60 Correct 861 ms 37668 KB Output is correct
61 Correct 478 ms 15184 KB Output is correct
62 Correct 695 ms 15292 KB Output is correct
63 Correct 735 ms 15312 KB Output is correct
64 Correct 826 ms 15668 KB Output is correct
65 Correct 815 ms 15696 KB Output is correct
66 Correct 534 ms 15736 KB Output is correct
67 Correct 622 ms 15696 KB Output is correct
68 Correct 583 ms 15696 KB Output is correct
69 Correct 787 ms 15112 KB Output is correct
70 Correct 799 ms 15148 KB Output is correct
71 Correct 726 ms 15156 KB Output is correct
72 Correct 791 ms 15680 KB Output is correct
73 Correct 650 ms 15548 KB Output is correct
74 Correct 496 ms 15256 KB Output is correct
75 Correct 752 ms 15060 KB Output is correct
76 Correct 776 ms 15680 KB Output is correct
77 Correct 708 ms 15820 KB Output is correct
78 Correct 724 ms 15776 KB Output is correct
79 Correct 652 ms 15328 KB Output is correct
80 Correct 581 ms 15036 KB Output is correct
81 Correct 646 ms 15028 KB Output is correct
82 Correct 599 ms 15028 KB Output is correct
83 Correct 340 ms 14800 KB Output is correct
84 Correct 709 ms 15348 KB Output is correct
85 Correct 660 ms 15356 KB Output is correct
86 Correct 585 ms 15340 KB Output is correct
87 Correct 6 ms 14416 KB Output is correct
88 Correct 534 ms 37920 KB Output is correct
89 Correct 770 ms 30380 KB Output is correct
90 Correct 691 ms 30616 KB Output is correct
91 Correct 859 ms 39980 KB Output is correct
92 Correct 826 ms 39992 KB Output is correct
93 Correct 707 ms 40048 KB Output is correct
94 Correct 830 ms 40008 KB Output is correct
95 Correct 713 ms 40024 KB Output is correct
96 Correct 721 ms 24800 KB Output is correct
97 Correct 772 ms 25180 KB Output is correct
98 Correct 682 ms 29628 KB Output is correct
99 Correct 687 ms 37584 KB Output is correct
100 Correct 729 ms 34228 KB Output is correct
101 Correct 844 ms 29272 KB Output is correct
102 Correct 730 ms 25468 KB Output is correct
103 Correct 754 ms 37592 KB Output is correct
104 Correct 826 ms 40048 KB Output is correct
105 Correct 679 ms 40048 KB Output is correct
106 Correct 788 ms 30472 KB Output is correct
107 Correct 695 ms 29192 KB Output is correct
108 Correct 858 ms 29536 KB Output is correct
109 Correct 766 ms 26068 KB Output is correct