Submission #791668

# Submission time Handle Problem Language Result Execution time Memory
791668 2023-07-24T08:41:38 Z firewater Digital Circuit (IOI22_circuit) C++17
100 / 100
1027 ms 47896 KB
#include "circuit.h"
#include<cstdio>
#include<vector>
#include<cstring>
#include<cassert>
#include<iostream>
#include<algorithm>
#define ll long long
#define MX 202300
#define mod 1000002022
using namespace std;
ll n,m,a[MX],b[MX],sz[MX];
vector<ll>to[MX],pre[MX],suf[MX];

struct Tree
{
	#define ls x*2
	#define rs x*2+1
	ll c[MX<<2],s[MX<<2],lazy[MX<<2];
	void push_up(ll x)
	{
		c[x]=(c[ls]+c[rs])%mod;
		s[x]=(s[ls]+s[rs])%mod;
		return;
	}
	void get(ll x)
	{
		s[x]=(c[x]-s[x]+mod)%mod;
		lazy[x]^=1;
		return;
	}
	void push_down(ll x)
	{
		if(lazy[x]){
			get(ls);
			get(rs);
			lazy[x]=0;
		}
		return;
	}
	void build(ll x,ll l,ll r)
	{
		if(l==r){
			c[x]=a[l];
			s[x]=a[l]*b[l];
			return;
		}
		ll mid=l+r>>1;
		build(ls,l,mid);
		build(rs,mid+1,r);
		push_up(x);
		return;
	}
	void change(ll x,ll L,ll R,ll l,ll r)
	{
		if(L==l&&R==r){
			get(x);
			return;
		}
		push_down(x);
		ll mid=L+R>>1;
		if(r<=mid)change(ls,L,mid,l,r);
		else if(l>mid)change(rs,mid+1,R,l,r);
		else change(ls,L,mid,l,mid),change(rs,mid+1,R,mid+1,r);
		push_up(x);
		return;
	}
}T;
void dfs(ll x)
{
	sz[x]=to[x].size();
	if(!sz[x])sz[x]=1;
	ll sav=to[x].size();
	for(ll i=0;i<sav;++i){
		dfs(to[x][i]);
		sz[x]=sz[x]*sz[to[x][i]]%mod;
	}
	return;
}
void dfs1(ll x,ll num)
{
	if(x>=n)a[x-n+1]=num;
	ll sav=to[x].size();
	for(ll i=0;i<sav;++i){
		pre[x].push_back(sz[to[x][i]]);
		suf[x].push_back(sz[to[x][i]]);
	}
	for(ll i=1;i<sav;++i)
		pre[x][i]=pre[x][i]*pre[x][i-1]%mod;
	for(ll i=sav-2;i>=0;--i)
		suf[x][i]=suf[x][i]*suf[x][i+1]%mod;
	for(ll i=0;i<sav;++i)
		dfs1(to[x][i],(i>0?pre[x][i-1]:1)*(i<sav-1?suf[x][i+1]:1)%mod*num%mod);
	return;
}
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
	n=N;m=M;
	for(ll i=1;i<n+m;++i)
		to[P[i]].push_back(i);
	for(ll i=1;i<=m;++i)
		b[i]=A[i-1];
	dfs(0);
	dfs1(0,1);
	T.build(1,1,m);
	return;
}

int count_ways(int L, int R) {
	L=L-n+1;
	R=R-n+1;
	T.change(1,1,m,L,R);
  	return T.s[1];
}
//int main() {
//  ll N, M, Q;
//  assert(3 == scanf("%d %d %d", &N, &M, &Q));
//  std::vector<int> P(N + M), A(M);
//  for (ll i = 0; i < N + M; ++i) {
//    assert(1 == scanf("%d", &P[i]));
//  }
//  for (ll j = 0; j < M; ++j) {
//    assert(1 == scanf("%d", &A[j]));
//  }
//  init(N, M, P, A);
//
//  for (ll i = 0; i < Q; ++i) {
//    ll L, R;
//    assert(2 == scanf("%d %d", &L, &R));
//    printf("%d\n", count_ways(L, R));
//  }
//  return 0;
//}

Compilation message

circuit.cpp: In member function 'void Tree::build(long long int, long long int, long long int)':
circuit.cpp:48:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   48 |   ll mid=l+r>>1;
      |          ~^~
circuit.cpp: In member function 'void Tree::change(long long int, long long int, long long int, long long int, long long int)':
circuit.cpp:61:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |   ll mid=L+R>>1;
      |          ~^~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14544 KB Output is correct
2 Correct 7 ms 14552 KB Output is correct
3 Correct 7 ms 14672 KB Output is correct
4 Correct 7 ms 14704 KB Output is correct
5 Correct 7 ms 14672 KB Output is correct
6 Correct 7 ms 14672 KB Output is correct
7 Correct 7 ms 14684 KB Output is correct
8 Correct 7 ms 14672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14544 KB Output is correct
2 Correct 7 ms 14624 KB Output is correct
3 Correct 7 ms 14672 KB Output is correct
4 Correct 7 ms 14688 KB Output is correct
5 Correct 8 ms 14628 KB Output is correct
6 Correct 7 ms 14696 KB Output is correct
7 Correct 7 ms 14672 KB Output is correct
8 Correct 7 ms 14672 KB Output is correct
9 Correct 8 ms 14732 KB Output is correct
10 Correct 7 ms 14820 KB Output is correct
11 Correct 7 ms 14820 KB Output is correct
12 Correct 7 ms 14672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14544 KB Output is correct
2 Correct 7 ms 14552 KB Output is correct
3 Correct 7 ms 14672 KB Output is correct
4 Correct 7 ms 14704 KB Output is correct
5 Correct 7 ms 14672 KB Output is correct
6 Correct 7 ms 14672 KB Output is correct
7 Correct 7 ms 14684 KB Output is correct
8 Correct 7 ms 14672 KB Output is correct
9 Correct 6 ms 14544 KB Output is correct
10 Correct 7 ms 14624 KB Output is correct
11 Correct 7 ms 14672 KB Output is correct
12 Correct 7 ms 14688 KB Output is correct
13 Correct 8 ms 14628 KB Output is correct
14 Correct 7 ms 14696 KB Output is correct
15 Correct 7 ms 14672 KB Output is correct
16 Correct 7 ms 14672 KB Output is correct
17 Correct 8 ms 14732 KB Output is correct
18 Correct 7 ms 14820 KB Output is correct
19 Correct 7 ms 14820 KB Output is correct
20 Correct 7 ms 14672 KB Output is correct
21 Correct 7 ms 14664 KB Output is correct
22 Correct 7 ms 14672 KB Output is correct
23 Correct 6 ms 14672 KB Output is correct
24 Correct 7 ms 14796 KB Output is correct
25 Correct 10 ms 14800 KB Output is correct
26 Correct 7 ms 14672 KB Output is correct
27 Correct 7 ms 14800 KB Output is correct
28 Correct 7 ms 14800 KB Output is correct
29 Correct 7 ms 14672 KB Output is correct
30 Correct 7 ms 14712 KB Output is correct
31 Correct 7 ms 14704 KB Output is correct
32 Correct 7 ms 14672 KB Output is correct
33 Correct 7 ms 14672 KB Output is correct
34 Correct 7 ms 14672 KB Output is correct
35 Correct 7 ms 14672 KB Output is correct
36 Correct 7 ms 14876 KB Output is correct
37 Correct 8 ms 14800 KB Output is correct
38 Correct 7 ms 14900 KB Output is correct
39 Correct 7 ms 14824 KB Output is correct
40 Correct 7 ms 14672 KB Output is correct
41 Correct 8 ms 14724 KB Output is correct
42 Correct 7 ms 14672 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 517 ms 20412 KB Output is correct
2 Correct 732 ms 26324 KB Output is correct
3 Correct 690 ms 26276 KB Output is correct
4 Correct 774 ms 26344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 517 ms 20412 KB Output is correct
2 Correct 732 ms 26324 KB Output is correct
3 Correct 690 ms 26276 KB Output is correct
4 Correct 774 ms 26344 KB Output is correct
5 Correct 561 ms 20616 KB Output is correct
6 Correct 804 ms 26644 KB Output is correct
7 Correct 791 ms 26652 KB Output is correct
8 Correct 699 ms 26332 KB Output is correct
9 Correct 349 ms 14928 KB Output is correct
10 Correct 584 ms 15312 KB Output is correct
11 Correct 656 ms 15312 KB Output is correct
12 Correct 681 ms 15312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 14544 KB Output is correct
2 Correct 7 ms 14624 KB Output is correct
3 Correct 7 ms 14672 KB Output is correct
4 Correct 7 ms 14688 KB Output is correct
5 Correct 8 ms 14628 KB Output is correct
6 Correct 7 ms 14696 KB Output is correct
7 Correct 7 ms 14672 KB Output is correct
8 Correct 7 ms 14672 KB Output is correct
9 Correct 8 ms 14732 KB Output is correct
10 Correct 7 ms 14820 KB Output is correct
11 Correct 7 ms 14820 KB Output is correct
12 Correct 7 ms 14672 KB Output is correct
13 Correct 517 ms 20412 KB Output is correct
14 Correct 732 ms 26324 KB Output is correct
15 Correct 690 ms 26276 KB Output is correct
16 Correct 774 ms 26344 KB Output is correct
17 Correct 561 ms 20616 KB Output is correct
18 Correct 804 ms 26644 KB Output is correct
19 Correct 791 ms 26652 KB Output is correct
20 Correct 699 ms 26332 KB Output is correct
21 Correct 349 ms 14928 KB Output is correct
22 Correct 584 ms 15312 KB Output is correct
23 Correct 656 ms 15312 KB Output is correct
24 Correct 681 ms 15312 KB Output is correct
25 Correct 843 ms 34196 KB Output is correct
26 Correct 791 ms 34704 KB Output is correct
27 Correct 810 ms 34444 KB Output is correct
28 Correct 766 ms 33496 KB Output is correct
29 Correct 1027 ms 45396 KB Output is correct
30 Correct 705 ms 44404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14544 KB Output is correct
2 Correct 7 ms 14552 KB Output is correct
3 Correct 7 ms 14672 KB Output is correct
4 Correct 7 ms 14704 KB Output is correct
5 Correct 7 ms 14672 KB Output is correct
6 Correct 7 ms 14672 KB Output is correct
7 Correct 7 ms 14684 KB Output is correct
8 Correct 7 ms 14672 KB Output is correct
9 Correct 6 ms 14544 KB Output is correct
10 Correct 7 ms 14624 KB Output is correct
11 Correct 7 ms 14672 KB Output is correct
12 Correct 7 ms 14688 KB Output is correct
13 Correct 8 ms 14628 KB Output is correct
14 Correct 7 ms 14696 KB Output is correct
15 Correct 7 ms 14672 KB Output is correct
16 Correct 7 ms 14672 KB Output is correct
17 Correct 8 ms 14732 KB Output is correct
18 Correct 7 ms 14820 KB Output is correct
19 Correct 7 ms 14820 KB Output is correct
20 Correct 7 ms 14672 KB Output is correct
21 Correct 7 ms 14664 KB Output is correct
22 Correct 7 ms 14672 KB Output is correct
23 Correct 6 ms 14672 KB Output is correct
24 Correct 7 ms 14796 KB Output is correct
25 Correct 10 ms 14800 KB Output is correct
26 Correct 7 ms 14672 KB Output is correct
27 Correct 7 ms 14800 KB Output is correct
28 Correct 7 ms 14800 KB Output is correct
29 Correct 7 ms 14672 KB Output is correct
30 Correct 7 ms 14712 KB Output is correct
31 Correct 7 ms 14704 KB Output is correct
32 Correct 7 ms 14672 KB Output is correct
33 Correct 7 ms 14672 KB Output is correct
34 Correct 7 ms 14672 KB Output is correct
35 Correct 7 ms 14672 KB Output is correct
36 Correct 7 ms 14876 KB Output is correct
37 Correct 8 ms 14800 KB Output is correct
38 Correct 7 ms 14900 KB Output is correct
39 Correct 7 ms 14824 KB Output is correct
40 Correct 7 ms 14672 KB Output is correct
41 Correct 8 ms 14724 KB Output is correct
42 Correct 7 ms 14672 KB Output is correct
43 Correct 613 ms 15260 KB Output is correct
44 Correct 524 ms 15312 KB Output is correct
45 Correct 718 ms 15272 KB Output is correct
46 Correct 845 ms 15684 KB Output is correct
47 Correct 653 ms 15824 KB Output is correct
48 Correct 601 ms 15708 KB Output is correct
49 Correct 819 ms 15684 KB Output is correct
50 Correct 474 ms 15592 KB Output is correct
51 Correct 642 ms 15268 KB Output is correct
52 Correct 755 ms 15364 KB Output is correct
53 Correct 632 ms 15568 KB Output is correct
54 Correct 648 ms 15696 KB Output is correct
55 Correct 648 ms 15440 KB Output is correct
56 Correct 651 ms 15440 KB Output is correct
57 Correct 731 ms 15312 KB Output is correct
58 Correct 730 ms 16208 KB Output is correct
59 Correct 674 ms 16460 KB Output is correct
60 Correct 739 ms 16356 KB Output is correct
61 Correct 578 ms 15440 KB Output is correct
62 Correct 612 ms 15184 KB Output is correct
63 Correct 689 ms 15184 KB Output is correct
64 Correct 631 ms 15312 KB Output is correct
65 Correct 372 ms 15000 KB Output is correct
66 Correct 669 ms 15344 KB Output is correct
67 Correct 670 ms 15312 KB Output is correct
68 Correct 567 ms 15312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 14544 KB Output is correct
2 Correct 7 ms 14552 KB Output is correct
3 Correct 7 ms 14672 KB Output is correct
4 Correct 7 ms 14704 KB Output is correct
5 Correct 7 ms 14672 KB Output is correct
6 Correct 7 ms 14672 KB Output is correct
7 Correct 7 ms 14684 KB Output is correct
8 Correct 7 ms 14672 KB Output is correct
9 Correct 6 ms 14544 KB Output is correct
10 Correct 7 ms 14624 KB Output is correct
11 Correct 7 ms 14672 KB Output is correct
12 Correct 7 ms 14688 KB Output is correct
13 Correct 8 ms 14628 KB Output is correct
14 Correct 7 ms 14696 KB Output is correct
15 Correct 7 ms 14672 KB Output is correct
16 Correct 7 ms 14672 KB Output is correct
17 Correct 8 ms 14732 KB Output is correct
18 Correct 7 ms 14820 KB Output is correct
19 Correct 7 ms 14820 KB Output is correct
20 Correct 7 ms 14672 KB Output is correct
21 Correct 7 ms 14664 KB Output is correct
22 Correct 7 ms 14672 KB Output is correct
23 Correct 6 ms 14672 KB Output is correct
24 Correct 7 ms 14796 KB Output is correct
25 Correct 10 ms 14800 KB Output is correct
26 Correct 7 ms 14672 KB Output is correct
27 Correct 7 ms 14800 KB Output is correct
28 Correct 7 ms 14800 KB Output is correct
29 Correct 7 ms 14672 KB Output is correct
30 Correct 7 ms 14712 KB Output is correct
31 Correct 7 ms 14704 KB Output is correct
32 Correct 7 ms 14672 KB Output is correct
33 Correct 7 ms 14672 KB Output is correct
34 Correct 7 ms 14672 KB Output is correct
35 Correct 7 ms 14672 KB Output is correct
36 Correct 7 ms 14876 KB Output is correct
37 Correct 8 ms 14800 KB Output is correct
38 Correct 7 ms 14900 KB Output is correct
39 Correct 7 ms 14824 KB Output is correct
40 Correct 7 ms 14672 KB Output is correct
41 Correct 8 ms 14724 KB Output is correct
42 Correct 7 ms 14672 KB Output is correct
43 Correct 517 ms 20412 KB Output is correct
44 Correct 732 ms 26324 KB Output is correct
45 Correct 690 ms 26276 KB Output is correct
46 Correct 774 ms 26344 KB Output is correct
47 Correct 561 ms 20616 KB Output is correct
48 Correct 804 ms 26644 KB Output is correct
49 Correct 791 ms 26652 KB Output is correct
50 Correct 699 ms 26332 KB Output is correct
51 Correct 349 ms 14928 KB Output is correct
52 Correct 584 ms 15312 KB Output is correct
53 Correct 656 ms 15312 KB Output is correct
54 Correct 681 ms 15312 KB Output is correct
55 Correct 843 ms 34196 KB Output is correct
56 Correct 791 ms 34704 KB Output is correct
57 Correct 810 ms 34444 KB Output is correct
58 Correct 766 ms 33496 KB Output is correct
59 Correct 1027 ms 45396 KB Output is correct
60 Correct 705 ms 44404 KB Output is correct
61 Correct 613 ms 15260 KB Output is correct
62 Correct 524 ms 15312 KB Output is correct
63 Correct 718 ms 15272 KB Output is correct
64 Correct 845 ms 15684 KB Output is correct
65 Correct 653 ms 15824 KB Output is correct
66 Correct 601 ms 15708 KB Output is correct
67 Correct 819 ms 15684 KB Output is correct
68 Correct 474 ms 15592 KB Output is correct
69 Correct 642 ms 15268 KB Output is correct
70 Correct 755 ms 15364 KB Output is correct
71 Correct 632 ms 15568 KB Output is correct
72 Correct 648 ms 15696 KB Output is correct
73 Correct 648 ms 15440 KB Output is correct
74 Correct 651 ms 15440 KB Output is correct
75 Correct 731 ms 15312 KB Output is correct
76 Correct 730 ms 16208 KB Output is correct
77 Correct 674 ms 16460 KB Output is correct
78 Correct 739 ms 16356 KB Output is correct
79 Correct 578 ms 15440 KB Output is correct
80 Correct 612 ms 15184 KB Output is correct
81 Correct 689 ms 15184 KB Output is correct
82 Correct 631 ms 15312 KB Output is correct
83 Correct 372 ms 15000 KB Output is correct
84 Correct 669 ms 15344 KB Output is correct
85 Correct 670 ms 15312 KB Output is correct
86 Correct 567 ms 15312 KB Output is correct
87 Correct 7 ms 14544 KB Output is correct
88 Correct 592 ms 34656 KB Output is correct
89 Correct 798 ms 27528 KB Output is correct
90 Correct 833 ms 27568 KB Output is correct
91 Correct 696 ms 35768 KB Output is correct
92 Correct 770 ms 36284 KB Output is correct
93 Correct 913 ms 36300 KB Output is correct
94 Correct 898 ms 36272 KB Output is correct
95 Correct 762 ms 35332 KB Output is correct
96 Correct 722 ms 25064 KB Output is correct
97 Correct 757 ms 26364 KB Output is correct
98 Correct 614 ms 36404 KB Output is correct
99 Correct 990 ms 34448 KB Output is correct
100 Correct 808 ms 31684 KB Output is correct
101 Correct 611 ms 30168 KB Output is correct
102 Correct 609 ms 26648 KB Output is correct
103 Correct 872 ms 45404 KB Output is correct
104 Correct 688 ms 47896 KB Output is correct
105 Correct 721 ms 46872 KB Output is correct
106 Correct 835 ms 29936 KB Output is correct
107 Correct 582 ms 28192 KB Output is correct
108 Correct 760 ms 28404 KB Output is correct
109 Correct 658 ms 27336 KB Output is correct