답안 #710664

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
710664 2023-03-15T14:11:32 Z myrcella 디지털 회로 (IOI22_circuit) C++17
100 / 100
1137 ms 36536 KB
//by szh
#include<bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000002022
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}

#include "circuit.h"

const int maxn = 200010;
int a[maxn];
vector <int> edge[maxn];
int NN,MM;
pii tree[maxn*4];
int add[maxn*4];
int prod[maxn],cont[maxn];

void initt(int c,int cl,int cr) {
	if (cl==cr) {
		tree[c] = {a[cl]*cont[cl],(a[cl]^1)*cont[cl]};
		return;
	}
	int mid=cl+cr>>1;
	initt(c<<1,cl,mid);
	initt(c<<1|1,mid+1,cr);
	tree[c].fi = (tree[c<<1].fi + tree[c<<1|1].fi)%mod;
	tree[c].se = (tree[c<<1].se + tree[c<<1|1].se)%mod;
//	cout<<cl<<" "<<cr<<" "<<tree[c].fi<<" "<<tree[c].se<<endl;
}

void update(int c,int cl,int cr,int l,int r) {
	if (l<=cl and cr<=r) {
		add[c]^=1;
		swap(tree[c].fi,tree[c].se);
		return;
	}
	if (add[c]==1) {
		add[c<<1]^=1,add[c<<1|1]^=1;
		swap(tree[c<<1].fi,tree[c<<1].se);
		swap(tree[c<<1|1].fi,tree[c<<1|1].se);
		add[c] = 0;
	}
	int mid=cl+cr>>1;
	if (l<=mid) update(c<<1,cl,mid,l,r);
	if (r>mid) update(c<<1|1,mid+1,cr,l,r);
	tree[c].fi = (tree[c<<1].fi + tree[c<<1|1].fi)%mod;
	tree[c].se = (tree[c<<1].se + tree[c<<1|1].se)%mod;
	return;
}

void dfs1(int u) {
	prod[u] = SZ(edge[u]);
	if (prod[u]==0) prod[u]=1;
	for (int v:edge[u]) {
		dfs1(v);
		prod[u] = 1ll*prod[u]*prod[v]%mod;
	}
	return;
}

void dfs2(int u,int cur) {
	if (SZ(edge[u])==0) {
		cont[u]=cur;
		return;
	}
	vector <int> pre,suf;
	for (int v:edge[u]) {
		pre.pb(prod[v]);
		suf.pb(prod[v]);
	}
	rep(i,1,SZ(pre)) pre[i] = 1ll*pre[i-1]*pre[i]%mod;
	for (int i = SZ(suf)-2;i>=0;i--) suf[i] = 1ll*suf[i+1]*suf[i]%mod;	
	rep(i,0,SZ(edge[u])) {
		int tmp = 1;
		if (i>0) tmp = 1ll*tmp*pre[i-1]%mod;
		if (i+1<SZ(edge[u])) tmp = 1ll*tmp*suf[i+1]%mod;
		dfs2(edge[u][i],1ll*cur*tmp%mod);
	}
}

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
	NN=N,MM=M;
	rep(i,1,SZ(P)) {
		edge[P[i]].pb(i);
	}
	rep(i,0,SZ(A)) a[i+N]=A[i];
	dfs1(0);
	dfs2(0,1);
	initt(1,N,N+M-1);
}

int count_ways(int L, int R) {
	update(1,NN,NN+MM-1,L,R);
	return tree[1].fi;
}

Compilation message

circuit.cpp: In function 'void initt(int, int, int)':
circuit.cpp:39:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   39 |  int mid=cl+cr>>1;
      |          ~~^~~
circuit.cpp: In function 'void update(int, int, int, int, int)':
circuit.cpp:59:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |  int mid=cl+cr>>1;
      |          ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 4968 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5048 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 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 4 ms 5072 KB Output is correct
10 Correct 4 ms 5328 KB Output is correct
11 Correct 4 ms 5220 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 4968 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5048 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 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 4 ms 5072 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 4 ms 5328 KB Output is correct
19 Correct 4 ms 5220 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 5 ms 5068 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 4 ms 5072 KB Output is correct
27 Correct 3 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 4 ms 5072 KB Output is correct
31 Correct 4 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 4 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5080 KB Output is correct
36 Correct 4 ms 5376 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 4 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 4 ms 5072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 491 ms 7828 KB Output is correct
2 Correct 567 ms 10628 KB Output is correct
3 Correct 990 ms 10628 KB Output is correct
4 Correct 886 ms 10556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 491 ms 7828 KB Output is correct
2 Correct 567 ms 10628 KB Output is correct
3 Correct 990 ms 10628 KB Output is correct
4 Correct 886 ms 10556 KB Output is correct
5 Correct 687 ms 7804 KB Output is correct
6 Correct 762 ms 10624 KB Output is correct
7 Correct 840 ms 10556 KB Output is correct
8 Correct 1018 ms 10568 KB Output is correct
9 Correct 406 ms 5200 KB Output is correct
10 Correct 982 ms 5328 KB Output is correct
11 Correct 780 ms 5392 KB Output is correct
12 Correct 1067 ms 5328 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 4944 KB Output is correct
4 Correct 3 ms 4944 KB Output is correct
5 Correct 3 ms 4944 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5072 KB Output is correct
9 Correct 4 ms 5072 KB Output is correct
10 Correct 4 ms 5328 KB Output is correct
11 Correct 4 ms 5220 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 491 ms 7828 KB Output is correct
14 Correct 567 ms 10628 KB Output is correct
15 Correct 990 ms 10628 KB Output is correct
16 Correct 886 ms 10556 KB Output is correct
17 Correct 687 ms 7804 KB Output is correct
18 Correct 762 ms 10624 KB Output is correct
19 Correct 840 ms 10556 KB Output is correct
20 Correct 1018 ms 10568 KB Output is correct
21 Correct 406 ms 5200 KB Output is correct
22 Correct 982 ms 5328 KB Output is correct
23 Correct 780 ms 5392 KB Output is correct
24 Correct 1067 ms 5328 KB Output is correct
25 Correct 943 ms 13888 KB Output is correct
26 Correct 1126 ms 14080 KB Output is correct
27 Correct 1042 ms 14080 KB Output is correct
28 Correct 775 ms 14068 KB Output is correct
29 Correct 965 ms 35972 KB Output is correct
30 Correct 719 ms 35976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 4968 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5048 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 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 4 ms 5072 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 4 ms 5328 KB Output is correct
19 Correct 4 ms 5220 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 5 ms 5068 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 4 ms 5072 KB Output is correct
27 Correct 3 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 4 ms 5072 KB Output is correct
31 Correct 4 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 4 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5080 KB Output is correct
36 Correct 4 ms 5376 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 4 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 4 ms 5072 KB Output is correct
43 Correct 480 ms 5328 KB Output is correct
44 Correct 844 ms 5372 KB Output is correct
45 Correct 922 ms 5328 KB Output is correct
46 Correct 833 ms 5520 KB Output is correct
47 Correct 797 ms 5568 KB Output is correct
48 Correct 905 ms 5560 KB Output is correct
49 Correct 773 ms 5532 KB Output is correct
50 Correct 566 ms 5420 KB Output is correct
51 Correct 886 ms 5404 KB Output is correct
52 Correct 755 ms 5456 KB Output is correct
53 Correct 790 ms 6224 KB Output is correct
54 Correct 650 ms 5456 KB Output is correct
55 Correct 954 ms 5456 KB Output is correct
56 Correct 689 ms 5328 KB Output is correct
57 Correct 812 ms 5384 KB Output is correct
58 Correct 876 ms 6608 KB Output is correct
59 Correct 877 ms 6744 KB Output is correct
60 Correct 1000 ms 6608 KB Output is correct
61 Correct 796 ms 5512 KB Output is correct
62 Correct 1050 ms 5256 KB Output is correct
63 Correct 847 ms 5200 KB Output is correct
64 Correct 1081 ms 5328 KB Output is correct
65 Correct 402 ms 5200 KB Output is correct
66 Correct 745 ms 5384 KB Output is correct
67 Correct 1010 ms 5328 KB Output is correct
68 Correct 946 ms 5328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 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 4968 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 4 ms 5048 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 4944 KB Output is correct
12 Correct 3 ms 4944 KB Output is correct
13 Correct 3 ms 4944 KB Output is correct
14 Correct 3 ms 5072 KB Output is correct
15 Correct 3 ms 5072 KB Output is correct
16 Correct 4 ms 5072 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 4 ms 5328 KB Output is correct
19 Correct 4 ms 5220 KB Output is correct
20 Correct 3 ms 5072 KB Output is correct
21 Correct 4 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 5 ms 5068 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 4 ms 5072 KB Output is correct
27 Correct 3 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 4 ms 5072 KB Output is correct
31 Correct 4 ms 5200 KB Output is correct
32 Correct 3 ms 5072 KB Output is correct
33 Correct 4 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5080 KB Output is correct
36 Correct 4 ms 5376 KB Output is correct
37 Correct 4 ms 5328 KB Output is correct
38 Correct 3 ms 5328 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 4 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 4 ms 5072 KB Output is correct
43 Correct 491 ms 7828 KB Output is correct
44 Correct 567 ms 10628 KB Output is correct
45 Correct 990 ms 10628 KB Output is correct
46 Correct 886 ms 10556 KB Output is correct
47 Correct 687 ms 7804 KB Output is correct
48 Correct 762 ms 10624 KB Output is correct
49 Correct 840 ms 10556 KB Output is correct
50 Correct 1018 ms 10568 KB Output is correct
51 Correct 406 ms 5200 KB Output is correct
52 Correct 982 ms 5328 KB Output is correct
53 Correct 780 ms 5392 KB Output is correct
54 Correct 1067 ms 5328 KB Output is correct
55 Correct 943 ms 13888 KB Output is correct
56 Correct 1126 ms 14080 KB Output is correct
57 Correct 1042 ms 14080 KB Output is correct
58 Correct 775 ms 14068 KB Output is correct
59 Correct 965 ms 35972 KB Output is correct
60 Correct 719 ms 35976 KB Output is correct
61 Correct 480 ms 5328 KB Output is correct
62 Correct 844 ms 5372 KB Output is correct
63 Correct 922 ms 5328 KB Output is correct
64 Correct 833 ms 5520 KB Output is correct
65 Correct 797 ms 5568 KB Output is correct
66 Correct 905 ms 5560 KB Output is correct
67 Correct 773 ms 5532 KB Output is correct
68 Correct 566 ms 5420 KB Output is correct
69 Correct 886 ms 5404 KB Output is correct
70 Correct 755 ms 5456 KB Output is correct
71 Correct 790 ms 6224 KB Output is correct
72 Correct 650 ms 5456 KB Output is correct
73 Correct 954 ms 5456 KB Output is correct
74 Correct 689 ms 5328 KB Output is correct
75 Correct 812 ms 5384 KB Output is correct
76 Correct 876 ms 6608 KB Output is correct
77 Correct 877 ms 6744 KB Output is correct
78 Correct 1000 ms 6608 KB Output is correct
79 Correct 796 ms 5512 KB Output is correct
80 Correct 1050 ms 5256 KB Output is correct
81 Correct 847 ms 5200 KB Output is correct
82 Correct 1081 ms 5328 KB Output is correct
83 Correct 402 ms 5200 KB Output is correct
84 Correct 745 ms 5384 KB Output is correct
85 Correct 1010 ms 5328 KB Output is correct
86 Correct 946 ms 5328 KB Output is correct
87 Correct 3 ms 4944 KB Output is correct
88 Correct 546 ms 13460 KB Output is correct
89 Correct 1024 ms 10756 KB Output is correct
90 Correct 1006 ms 10516 KB Output is correct
91 Correct 866 ms 14152 KB Output is correct
92 Correct 1137 ms 14208 KB Output is correct
93 Correct 1069 ms 14108 KB Output is correct
94 Correct 789 ms 14236 KB Output is correct
95 Correct 1061 ms 14208 KB Output is correct
96 Correct 870 ms 10264 KB Output is correct
97 Correct 1059 ms 10588 KB Output is correct
98 Correct 766 ms 31248 KB Output is correct
99 Correct 1000 ms 14048 KB Output is correct
100 Correct 1046 ms 12032 KB Output is correct
101 Correct 1031 ms 11548 KB Output is correct
102 Correct 890 ms 10572 KB Output is correct
103 Correct 1058 ms 35960 KB Output is correct
104 Correct 953 ms 36536 KB Output is correct
105 Correct 827 ms 36504 KB Output is correct
106 Correct 918 ms 15240 KB Output is correct
107 Correct 869 ms 11092 KB Output is correct
108 Correct 775 ms 10916 KB Output is correct
109 Correct 784 ms 10604 KB Output is correct