Submission #640759

# Submission time Handle Problem Language Result Execution time Memory
640759 2022-09-15T07:46:52 Z jamezzz Digital Circuit (IOI22_circuit) C++17
100 / 100
1232 ms 56604 KB
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define maxn 200005
#define mod 1000002022

struct node{
	int s,e,m,lz,on;ll v,sm;
	node *l,*r;
	node(int _s,int _e){
		s=_s;e=_e;m=(s+e)>>1;lz=0;v=0;sm=0;on=0;
		if(s!=e)l=new node(s,m),r=new node(m+1,e);
	}
	void ppo(){
		if(lz)v=(sm-v+mod)%mod;
		if(s!=e){
			l->lz^=lz;
			r->lz^=lz;
		}
		lz=0;
	}
	void set(int x,ll nv){
		if(s==x&&e==x){sm=nv;return;}
		if(x<=m)l->set(x,nv);
		else r->set(x,nv);
		l->ppo(),r->ppo();
		v=(l->v+r->v)%mod;
		sm=(l->sm+r->sm)%mod;
	}
	void flip(int x,int y){
		if(s==x&&e==y){lz^=1;return;}
		if(y<=m)l->flip(x,y);
		else if(x>m)r->flip(x,y);
		else l->flip(x,m),r->flip(m+1,y);
		l->ppo(),r->ppo();
		v=(l->v+r->v)%mod;
		sm=(l->sm+r->sm)%mod;
	}
	ll qry(int x,int y){
		ppo();
		if(s==x&&e==y)return v;
		if(y<=m)return l->qry(x,y);
		if(x>m)return r->qry(x,y);
		return l->qry(x,m),r->qry(m+1,y);
	}
}*rt;

int n,m;
ll s[maxn],c[maxn];
vector<int> AL[maxn];

void dfs(int u){
	if(u<n){
		s[u]=AL[u].size();
		for(int v:AL[u]){
			dfs(v);
			s[u]=(s[u]*s[v])%mod;
		}
	}
	else s[u]=1;
	//printf("dfs: %d %lld\n",u,s[u]);
}

void dfs2(int u,ll tot){
	//printf("dfs2: %d %lld\n",u,tot);
	if(u<n){
		vector<ll> vals;
		for(int v:AL[u])vals.push_back(s[v]);
		vector<ll> pfx={1},sfx={1};
		for(int i=0;i<vals.size();++i){
			pfx.push_back((pfx.back()*vals[i])%mod);
		}
		for(int i=vals.size()-1;i>=0;--i){
			sfx.push_back((sfx.back()*vals[i])%mod);
		}
		reverse(sfx.begin(),sfx.end());
		for(int i=0;i<vals.size();++i){
			dfs2(AL[u][i],(((tot*pfx[i])%mod)*sfx[i+1])%mod);
		}
	}
	else c[u]=tot;
}

void init(int N,int M,vector<int> P,vector<int> A){
	n=N,m=M;
	rt=new node(0,m-1);
	for(int i=1;i<n+m;++i){
		AL[P[i]].push_back(i);
	}
	dfs(0);
	dfs2(0,1);
	for(int i=0;i<m;++i){
		rt->set(i,c[i+n]);
		if(A[i])rt->flip(i,i);
	}
}

int count_ways(int L, int R){
	rt->flip(L-n,R-n);
	return (int)rt->qry(0,m-1);
}

Compilation message

circuit.cpp: In function 'void dfs2(int, ll)':
circuit.cpp:72:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |   for(int i=0;i<vals.size();++i){
      |               ~^~~~~~~~~~~~
circuit.cpp:79:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   79 |   for(int i=0;i<vals.size();++i){
      |               ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5200 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 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 5132 KB Output is correct
7 Correct 4 ms 5200 KB Output is correct
8 Correct 4 ms 5200 KB Output is correct
9 Correct 4 ms 5200 KB Output is correct
10 Correct 4 ms 5456 KB Output is correct
11 Correct 4 ms 5456 KB Output is correct
12 Correct 4 ms 5160 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5200 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5200 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 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5132 KB Output is correct
15 Correct 4 ms 5200 KB Output is correct
16 Correct 4 ms 5200 KB Output is correct
17 Correct 4 ms 5200 KB Output is correct
18 Correct 4 ms 5456 KB Output is correct
19 Correct 4 ms 5456 KB Output is correct
20 Correct 4 ms 5160 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 4 ms 5180 KB Output is correct
25 Correct 4 ms 5140 KB Output is correct
26 Correct 3 ms 5200 KB Output is correct
27 Correct 4 ms 5200 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 3 ms 5200 KB Output is correct
30 Correct 4 ms 5100 KB Output is correct
31 Correct 3 ms 5328 KB Output is correct
32 Correct 3 ms 5200 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 4 ms 5456 KB Output is correct
37 Correct 3 ms 5456 KB Output is correct
38 Correct 3 ms 5456 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 632 ms 11648 KB Output is correct
2 Correct 720 ms 18348 KB Output is correct
3 Correct 746 ms 18432 KB Output is correct
4 Correct 834 ms 18348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 632 ms 11648 KB Output is correct
2 Correct 720 ms 18348 KB Output is correct
3 Correct 746 ms 18432 KB Output is correct
4 Correct 834 ms 18348 KB Output is correct
5 Correct 860 ms 11600 KB Output is correct
6 Correct 1018 ms 18308 KB Output is correct
7 Correct 914 ms 18356 KB Output is correct
8 Correct 1020 ms 18328 KB Output is correct
9 Correct 446 ms 5328 KB Output is correct
10 Correct 983 ms 5736 KB Output is correct
11 Correct 976 ms 5772 KB Output is correct
12 Correct 855 ms 5712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 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 5132 KB Output is correct
7 Correct 4 ms 5200 KB Output is correct
8 Correct 4 ms 5200 KB Output is correct
9 Correct 4 ms 5200 KB Output is correct
10 Correct 4 ms 5456 KB Output is correct
11 Correct 4 ms 5456 KB Output is correct
12 Correct 4 ms 5160 KB Output is correct
13 Correct 632 ms 11648 KB Output is correct
14 Correct 720 ms 18348 KB Output is correct
15 Correct 746 ms 18432 KB Output is correct
16 Correct 834 ms 18348 KB Output is correct
17 Correct 860 ms 11600 KB Output is correct
18 Correct 1018 ms 18308 KB Output is correct
19 Correct 914 ms 18356 KB Output is correct
20 Correct 1020 ms 18328 KB Output is correct
21 Correct 446 ms 5328 KB Output is correct
22 Correct 983 ms 5736 KB Output is correct
23 Correct 976 ms 5772 KB Output is correct
24 Correct 855 ms 5712 KB Output is correct
25 Correct 929 ms 25004 KB Output is correct
26 Correct 1063 ms 25344 KB Output is correct
27 Correct 1177 ms 25244 KB Output is correct
28 Correct 806 ms 25404 KB Output is correct
29 Correct 1185 ms 56572 KB Output is correct
30 Correct 903 ms 56544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5200 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5200 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 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5132 KB Output is correct
15 Correct 4 ms 5200 KB Output is correct
16 Correct 4 ms 5200 KB Output is correct
17 Correct 4 ms 5200 KB Output is correct
18 Correct 4 ms 5456 KB Output is correct
19 Correct 4 ms 5456 KB Output is correct
20 Correct 4 ms 5160 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 4 ms 5180 KB Output is correct
25 Correct 4 ms 5140 KB Output is correct
26 Correct 3 ms 5200 KB Output is correct
27 Correct 4 ms 5200 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 3 ms 5200 KB Output is correct
30 Correct 4 ms 5100 KB Output is correct
31 Correct 3 ms 5328 KB Output is correct
32 Correct 3 ms 5200 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 4 ms 5456 KB Output is correct
37 Correct 3 ms 5456 KB Output is correct
38 Correct 3 ms 5456 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 465 ms 5456 KB Output is correct
44 Correct 909 ms 5584 KB Output is correct
45 Correct 964 ms 5584 KB Output is correct
46 Correct 690 ms 5968 KB Output is correct
47 Correct 923 ms 6084 KB Output is correct
48 Correct 962 ms 5968 KB Output is correct
49 Correct 903 ms 5968 KB Output is correct
50 Correct 931 ms 5952 KB Output is correct
51 Correct 906 ms 5968 KB Output is correct
52 Correct 873 ms 6000 KB Output is correct
53 Correct 948 ms 6608 KB Output is correct
54 Correct 965 ms 5968 KB Output is correct
55 Correct 746 ms 5840 KB Output is correct
56 Correct 886 ms 5840 KB Output is correct
57 Correct 985 ms 5712 KB Output is correct
58 Correct 902 ms 7504 KB Output is correct
59 Correct 909 ms 7632 KB Output is correct
60 Correct 853 ms 7632 KB Output is correct
61 Correct 943 ms 5840 KB Output is correct
62 Correct 806 ms 5584 KB Output is correct
63 Correct 838 ms 5584 KB Output is correct
64 Correct 955 ms 5840 KB Output is correct
65 Correct 467 ms 5328 KB Output is correct
66 Correct 1014 ms 5840 KB Output is correct
67 Correct 800 ms 5772 KB Output is correct
68 Correct 566 ms 5752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 2 ms 4944 KB Output is correct
3 Correct 3 ms 5072 KB Output is correct
4 Correct 3 ms 5200 KB Output is correct
5 Correct 3 ms 5072 KB Output is correct
6 Correct 3 ms 5072 KB Output is correct
7 Correct 3 ms 5072 KB Output is correct
8 Correct 3 ms 5200 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 5072 KB Output is correct
12 Correct 3 ms 5072 KB Output is correct
13 Correct 3 ms 5072 KB Output is correct
14 Correct 3 ms 5132 KB Output is correct
15 Correct 4 ms 5200 KB Output is correct
16 Correct 4 ms 5200 KB Output is correct
17 Correct 4 ms 5200 KB Output is correct
18 Correct 4 ms 5456 KB Output is correct
19 Correct 4 ms 5456 KB Output is correct
20 Correct 4 ms 5160 KB Output is correct
21 Correct 3 ms 5072 KB Output is correct
22 Correct 3 ms 5072 KB Output is correct
23 Correct 3 ms 5072 KB Output is correct
24 Correct 4 ms 5180 KB Output is correct
25 Correct 4 ms 5140 KB Output is correct
26 Correct 3 ms 5200 KB Output is correct
27 Correct 4 ms 5200 KB Output is correct
28 Correct 3 ms 5200 KB Output is correct
29 Correct 3 ms 5200 KB Output is correct
30 Correct 4 ms 5100 KB Output is correct
31 Correct 3 ms 5328 KB Output is correct
32 Correct 3 ms 5200 KB Output is correct
33 Correct 3 ms 5072 KB Output is correct
34 Correct 3 ms 5072 KB Output is correct
35 Correct 3 ms 5072 KB Output is correct
36 Correct 4 ms 5456 KB Output is correct
37 Correct 3 ms 5456 KB Output is correct
38 Correct 3 ms 5456 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 3 ms 5072 KB Output is correct
41 Correct 3 ms 5072 KB Output is correct
42 Correct 3 ms 5072 KB Output is correct
43 Correct 632 ms 11648 KB Output is correct
44 Correct 720 ms 18348 KB Output is correct
45 Correct 746 ms 18432 KB Output is correct
46 Correct 834 ms 18348 KB Output is correct
47 Correct 860 ms 11600 KB Output is correct
48 Correct 1018 ms 18308 KB Output is correct
49 Correct 914 ms 18356 KB Output is correct
50 Correct 1020 ms 18328 KB Output is correct
51 Correct 446 ms 5328 KB Output is correct
52 Correct 983 ms 5736 KB Output is correct
53 Correct 976 ms 5772 KB Output is correct
54 Correct 855 ms 5712 KB Output is correct
55 Correct 929 ms 25004 KB Output is correct
56 Correct 1063 ms 25344 KB Output is correct
57 Correct 1177 ms 25244 KB Output is correct
58 Correct 806 ms 25404 KB Output is correct
59 Correct 1185 ms 56572 KB Output is correct
60 Correct 903 ms 56544 KB Output is correct
61 Correct 465 ms 5456 KB Output is correct
62 Correct 909 ms 5584 KB Output is correct
63 Correct 964 ms 5584 KB Output is correct
64 Correct 690 ms 5968 KB Output is correct
65 Correct 923 ms 6084 KB Output is correct
66 Correct 962 ms 5968 KB Output is correct
67 Correct 903 ms 5968 KB Output is correct
68 Correct 931 ms 5952 KB Output is correct
69 Correct 906 ms 5968 KB Output is correct
70 Correct 873 ms 6000 KB Output is correct
71 Correct 948 ms 6608 KB Output is correct
72 Correct 965 ms 5968 KB Output is correct
73 Correct 746 ms 5840 KB Output is correct
74 Correct 886 ms 5840 KB Output is correct
75 Correct 985 ms 5712 KB Output is correct
76 Correct 902 ms 7504 KB Output is correct
77 Correct 909 ms 7632 KB Output is correct
78 Correct 853 ms 7632 KB Output is correct
79 Correct 943 ms 5840 KB Output is correct
80 Correct 806 ms 5584 KB Output is correct
81 Correct 838 ms 5584 KB Output is correct
82 Correct 955 ms 5840 KB Output is correct
83 Correct 467 ms 5328 KB Output is correct
84 Correct 1014 ms 5840 KB Output is correct
85 Correct 800 ms 5772 KB Output is correct
86 Correct 566 ms 5752 KB Output is correct
87 Correct 3 ms 4944 KB Output is correct
88 Correct 659 ms 22268 KB Output is correct
89 Correct 1072 ms 16252 KB Output is correct
90 Correct 1094 ms 17156 KB Output is correct
91 Correct 1065 ms 25468 KB Output is correct
92 Correct 1129 ms 25352 KB Output is correct
93 Correct 1016 ms 25724 KB Output is correct
94 Correct 1104 ms 25416 KB Output is correct
95 Correct 1000 ms 25416 KB Output is correct
96 Correct 958 ms 23504 KB Output is correct
97 Correct 922 ms 23448 KB Output is correct
98 Correct 966 ms 37832 KB Output is correct
99 Correct 1049 ms 25352 KB Output is correct
100 Correct 1182 ms 22984 KB Output is correct
101 Correct 1061 ms 22340 KB Output is correct
102 Correct 983 ms 21212 KB Output is correct
103 Correct 1232 ms 56604 KB Output is correct
104 Correct 861 ms 56360 KB Output is correct
105 Correct 1049 ms 56384 KB Output is correct
106 Correct 683 ms 21744 KB Output is correct
107 Correct 1112 ms 17292 KB Output is correct
108 Correct 1006 ms 18612 KB Output is correct
109 Correct 1030 ms 21248 KB Output is correct