Submission #710534

# Submission time Handle Problem Language Result Execution time Memory
710534 2023-03-15T10:27:57 Z myrcella Digital Circuit (IOI22_circuit) C++17
34 / 100
1159 ms 13816 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 sum[maxn];

void initt(int c,int cl,int cr) {
	if (cl==cr) {
		tree[c] = {a[cl],a[cl]^1};
		sum[c]=1;
		return;
	}
	int mid=cl+cr>>1;
	initt(c<<1,cl,mid);
	initt(c<<1|1,mid+1,cr);
	sum[c] = 2ll*sum[c<<1]*sum[c<<1|1]%mod;
	tree[c].fi = (1ll*tree[c<<1].fi*sum[c<<1|1]%mod + 1ll*tree[c<<1|1].fi*sum[c<<1]%mod)%mod;
	tree[c].se = (1ll*tree[c<<1].se*sum[c<<1|1]%mod + 1ll*tree[c<<1|1].se*sum[c<<1]%mod)%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 = (1ll*tree[c<<1].fi*sum[c<<1|1]%mod + 1ll*tree[c<<1|1].fi*sum[c<<1]%mod)%mod;
	tree[c].se = (1ll*tree[c<<1].se*sum[c<<1|1]%mod + 1ll*tree[c<<1|1].se*sum[c<<1]%mod)%mod;
	return;
}

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];
	initt(1,N,N+M-1);
}

pii solve(int u) {
	if (SZ(edge[u])==0) {
		if (a[u]==0) return {0,1};
		else return {1,0};
	}
	vector <pii> ans;
	for (int v:edge[u]) {
		ans.pb(solve(v));
	}
	vector <int> f;
	f.pb(1);
	rep(i,0,SZ(ans)) {
		f.pb(1ll*f.back()*ans[i].fi%mod);
		for (int j = i;j>=0;j--) {
			f[j] = 1ll*f[j]*ans[i].se%mod;
			if (j>0) inc(f[j],1ll*f[j-1]*ans[i].fi%mod);
		}
	}
	pii ret = {0,0};
	rep(i,0,SZ(f)) {
		inc(ret.se,1ll*f[i]*(SZ(f)-1-i)%mod);
		inc(ret.fi,1ll*f[i]*i%mod);
	}
	return ret;
}

int count_ways(int L, int R) {
	if (NN<=1000) {
		rep(i,L,R+1) a[i]^=1;
		return solve(0).fi;
	}
	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:40:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |  int mid=cl+cr>>1;
      |          ~~^~~
circuit.cpp: In function 'void update(int, int, int, int, int)':
circuit.cpp:61:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   61 |  int mid=cl+cr>>1;
      |          ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4944 KB Output is correct
2 Correct 4 ms 4944 KB Output is correct
3 Correct 16 ms 5008 KB Output is correct
4 Correct 18 ms 5072 KB Output is correct
5 Correct 15 ms 5072 KB Output is correct
6 Correct 15 ms 5072 KB Output is correct
7 Correct 16 ms 5072 KB Output is correct
8 Correct 15 ms 5072 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 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 4 ms 5072 KB Output is correct
8 Correct 5 ms 5072 KB Output is correct
9 Correct 4 ms 5072 KB Output is correct
10 Correct 4 ms 5200 KB Output is correct
11 Correct 4 ms 5200 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4944 KB Output is correct
2 Correct 4 ms 4944 KB Output is correct
3 Correct 16 ms 5008 KB Output is correct
4 Correct 18 ms 5072 KB Output is correct
5 Correct 15 ms 5072 KB Output is correct
6 Correct 15 ms 5072 KB Output is correct
7 Correct 16 ms 5072 KB Output is correct
8 Correct 15 ms 5072 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 4 ms 5072 KB Output is correct
16 Correct 5 ms 5072 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 4 ms 5200 KB Output is correct
20 Correct 4 ms 5072 KB Output is correct
21 Correct 5 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 5 ms 5072 KB Output is correct
24 Correct 4 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 4 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 15 ms 5072 KB Output is correct
30 Correct 16 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 4 ms 5072 KB Output is correct
33 Correct 4 ms 5072 KB Output is correct
34 Correct 4 ms 5072 KB Output is correct
35 Correct 5 ms 4944 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 16 ms 5252 KB Output is correct
38 Correct 15 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 4 ms 5072 KB Output is correct
41 Correct 4 ms 5072 KB Output is correct
42 Correct 4 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 637 ms 7704 KB Output is correct
2 Correct 721 ms 10364 KB Output is correct
3 Correct 754 ms 10332 KB Output is correct
4 Correct 850 ms 10368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 637 ms 7704 KB Output is correct
2 Correct 721 ms 10364 KB Output is correct
3 Correct 754 ms 10332 KB Output is correct
4 Correct 850 ms 10368 KB Output is correct
5 Correct 827 ms 7632 KB Output is correct
6 Correct 1038 ms 10340 KB Output is correct
7 Correct 1016 ms 10312 KB Output is correct
8 Correct 692 ms 10376 KB Output is correct
9 Correct 459 ms 5200 KB Output is correct
10 Correct 1159 ms 5336 KB Output is correct
11 Correct 1020 ms 5328 KB Output is correct
12 Correct 706 ms 5328 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 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 4 ms 5072 KB Output is correct
8 Correct 5 ms 5072 KB Output is correct
9 Correct 4 ms 5072 KB Output is correct
10 Correct 4 ms 5200 KB Output is correct
11 Correct 4 ms 5200 KB Output is correct
12 Correct 4 ms 5072 KB Output is correct
13 Correct 637 ms 7704 KB Output is correct
14 Correct 721 ms 10364 KB Output is correct
15 Correct 754 ms 10332 KB Output is correct
16 Correct 850 ms 10368 KB Output is correct
17 Correct 827 ms 7632 KB Output is correct
18 Correct 1038 ms 10340 KB Output is correct
19 Correct 1016 ms 10312 KB Output is correct
20 Correct 692 ms 10376 KB Output is correct
21 Correct 459 ms 5200 KB Output is correct
22 Correct 1159 ms 5336 KB Output is correct
23 Correct 1020 ms 5328 KB Output is correct
24 Correct 706 ms 5328 KB Output is correct
25 Incorrect 984 ms 13816 KB 1st lines differ - on the 1st token, expected: '732332002', found: '589743074'
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4944 KB Output is correct
2 Correct 4 ms 4944 KB Output is correct
3 Correct 16 ms 5008 KB Output is correct
4 Correct 18 ms 5072 KB Output is correct
5 Correct 15 ms 5072 KB Output is correct
6 Correct 15 ms 5072 KB Output is correct
7 Correct 16 ms 5072 KB Output is correct
8 Correct 15 ms 5072 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 4 ms 5072 KB Output is correct
16 Correct 5 ms 5072 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 4 ms 5200 KB Output is correct
20 Correct 4 ms 5072 KB Output is correct
21 Correct 5 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 5 ms 5072 KB Output is correct
24 Correct 4 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 4 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 15 ms 5072 KB Output is correct
30 Correct 16 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 4 ms 5072 KB Output is correct
33 Correct 4 ms 5072 KB Output is correct
34 Correct 4 ms 5072 KB Output is correct
35 Correct 5 ms 4944 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 16 ms 5252 KB Output is correct
38 Correct 15 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 4 ms 5072 KB Output is correct
41 Correct 4 ms 5072 KB Output is correct
42 Correct 4 ms 4944 KB Output is correct
43 Incorrect 607 ms 5216 KB 1st lines differ - on the 1st token, expected: '196037954', found: '769336250'
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4944 KB Output is correct
2 Correct 4 ms 4944 KB Output is correct
3 Correct 16 ms 5008 KB Output is correct
4 Correct 18 ms 5072 KB Output is correct
5 Correct 15 ms 5072 KB Output is correct
6 Correct 15 ms 5072 KB Output is correct
7 Correct 16 ms 5072 KB Output is correct
8 Correct 15 ms 5072 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 4 ms 5072 KB Output is correct
16 Correct 5 ms 5072 KB Output is correct
17 Correct 4 ms 5072 KB Output is correct
18 Correct 4 ms 5200 KB Output is correct
19 Correct 4 ms 5200 KB Output is correct
20 Correct 4 ms 5072 KB Output is correct
21 Correct 5 ms 5072 KB Output is correct
22 Correct 4 ms 5072 KB Output is correct
23 Correct 5 ms 5072 KB Output is correct
24 Correct 4 ms 5072 KB Output is correct
25 Correct 4 ms 5072 KB Output is correct
26 Correct 4 ms 5072 KB Output is correct
27 Correct 4 ms 5072 KB Output is correct
28 Correct 4 ms 5072 KB Output is correct
29 Correct 15 ms 5072 KB Output is correct
30 Correct 16 ms 5072 KB Output is correct
31 Correct 3 ms 5200 KB Output is correct
32 Correct 4 ms 5072 KB Output is correct
33 Correct 4 ms 5072 KB Output is correct
34 Correct 4 ms 5072 KB Output is correct
35 Correct 5 ms 4944 KB Output is correct
36 Correct 3 ms 5200 KB Output is correct
37 Correct 16 ms 5252 KB Output is correct
38 Correct 15 ms 5200 KB Output is correct
39 Correct 3 ms 5072 KB Output is correct
40 Correct 4 ms 5072 KB Output is correct
41 Correct 4 ms 5072 KB Output is correct
42 Correct 4 ms 4944 KB Output is correct
43 Correct 637 ms 7704 KB Output is correct
44 Correct 721 ms 10364 KB Output is correct
45 Correct 754 ms 10332 KB Output is correct
46 Correct 850 ms 10368 KB Output is correct
47 Correct 827 ms 7632 KB Output is correct
48 Correct 1038 ms 10340 KB Output is correct
49 Correct 1016 ms 10312 KB Output is correct
50 Correct 692 ms 10376 KB Output is correct
51 Correct 459 ms 5200 KB Output is correct
52 Correct 1159 ms 5336 KB Output is correct
53 Correct 1020 ms 5328 KB Output is correct
54 Correct 706 ms 5328 KB Output is correct
55 Incorrect 984 ms 13816 KB 1st lines differ - on the 1st token, expected: '732332002', found: '589743074'
56 Halted 0 ms 0 KB -