Submission #636744

# Submission time Handle Problem Language Result Execution time Memory
636744 2022-08-30T02:07:27 Z sentheta Digital Circuit (IOI22_circuit) C++17
62 / 100
1127 ms 28676 KB
#include "circuit.h"
// author : sentheta aka vanwij
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<random>
#include<chrono>
#include<cmath>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;

#define Int long long
#define V vector
#define pii pair<int,int>
#define ff first
#define ss second

#define rand() (uniform_int_distribution<int>(0,1<<30)(rng))
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

#define pow2(x) (1LL<<(x))
#define msb(x) (63-__builtin_clzll(x))
#define bitcnt(x) (__builtin_popcountll(x))

#define nl '\n'
#define _ << ' ' <<
#define all(x) (x).begin(), (x).end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define dbg(x) if(1) cout << "?" << #x << " : " << (x) << endl << flush;

const Int MOD = 1e9+2022;



const int N = 1e5+5;

int n, m;
V<int> p;


#define mid (tl+tr)/2
#define lc v+1
#define rc v+2*(mid-tl+1)

struct Multree{
	Int st[4*N];
	Multree(){
		rep(i,0,4*N) st[i] = 1;
	}
	void upd(int l,int r,int x,int v=0,int tl=0,int tr=n+m-1){
		if(r<tl || tr<l) return;
		if(l<=tl && tr<=r){
			(st[v] *= x )%=MOD; return;
		}
		upd(l,r,x, lc,tl,mid);
		upd(l,r,x, rc,mid+1,tr);
	}
	Int qry(int i,int v=0,int tl=0,int tr=n+m-1){
		if(tl==tr) return st[v];
		if(i<=mid) return st[v] *qry(i, lc,tl,mid)%MOD ;
		else return st[v] *qry(i, rc,mid+1,tr)%MOD;
	}
} multree;


struct Fliptree{
	int st[2*N][2];
	bool lz[2*N];
	void assign(int i,int x,int v=0,int tl=0,int tr=m-1){
		if(tl==tr){
			st[v][0] = x; return;
		}
		if(i<=mid) assign(i,x, lc,tl,mid);
		else assign(i,x, rc,mid+1,tr);
		rep(i,0,2)
			(st[v][i] = st[lc][i] + st[rc][i] )%=MOD;
	}
	void flip(int l,int r,int v=0,int tl=0,int tr=m-1){
		if(r<tl || tr<l) return;
		if(l<=tl && tr<=r){
			swap(st[v][0], st[v][1]);
			lz[v] ^= 1; return;
		}
		if(lz[v]){
			flip(tl,tr, lc,tl,mid);
			flip(tl,tr, rc,mid+1,tr);
			lz[v] = 0;
		}
		flip(l,r, lc,tl,mid);
		flip(l,r, rc,mid+1,tr);
		rep(i,0,2)
			(st[v][i] = st[lc][i] + st[rc][i] )%=MOD;
	}
	int qry(){
		return st[0][1];
	}
} fliptree;


V<int> adj[N];
int in[2*N], out[2*N], timer=0;
Int dp[2*N];
void dfs(int x=0){
	in[x] = timer++;

	if(adj[x].size()==0) dp[x] = 1;
	else dp[x] = adj[x].size();

	for(int y : adj[x]){
		dfs(y);
		(dp[x] *= dp[y] )%=MOD;
	}
	out[x] = timer-1;
}


void init(int _n,int _m,V<int> _p,V<int> a){
	n = _n; m = _m; p.swap(_p);

	rep(i,1,n+m){
		adj[p[i]].push_back(i);
	}
	dfs();

	rep(i,1,n+m){
		// dbg(i); dbg(dp[i]);
		// dbg(in[i]); dbg(out[i]);
		if(in[p[i]]+1 <= in[i]-1){
			// cout << in[p[i]]+1 _ in[i]-1 << nl;
			multree.upd(in[p[i]]+1,in[i]-1, dp[i]);
		}
		if(out[i]+1 <= out[p[i]]){
			// cout << out[i]+1 _ out[p[i]] << nl;
			multree.upd(out[i]+1, out[p[i]], dp[i]);
		}
		// cout << nl;
	}

	rep(i,0,m){
		// dbg(in[n+i]);
		// dbg(multree.qry(in[n+i]));
		fliptree.assign(i, multree.qry(in[n+i]));
		if(a[i]){
			fliptree.flip(i,i);
		}
	}

	// dbg(fliptree.qry());
}

int count_ways(int l,int r){
	// return -1;
	l -= n; r -= n;
	fliptree.flip(l, r);
	return fliptree.qry();
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 3 ms 5840 KB Output is correct
4 Correct 3 ms 5840 KB Output is correct
5 Correct 4 ms 5840 KB Output is correct
6 Correct 3 ms 5840 KB Output is correct
7 Correct 4 ms 5832 KB Output is correct
8 Correct 3 ms 5840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 4 ms 5840 KB Output is correct
4 Correct 3 ms 5840 KB Output is correct
5 Correct 5 ms 5840 KB Output is correct
6 Correct 3 ms 5840 KB Output is correct
7 Correct 4 ms 5780 KB Output is correct
8 Correct 4 ms 5840 KB Output is correct
9 Correct 4 ms 5840 KB Output is correct
10 Correct 4 ms 5880 KB Output is correct
11 Correct 3 ms 5840 KB Output is correct
12 Correct 4 ms 5840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 3 ms 5840 KB Output is correct
4 Correct 3 ms 5840 KB Output is correct
5 Correct 4 ms 5840 KB Output is correct
6 Correct 3 ms 5840 KB Output is correct
7 Correct 4 ms 5832 KB Output is correct
8 Correct 3 ms 5840 KB Output is correct
9 Correct 3 ms 5712 KB Output is correct
10 Correct 3 ms 5712 KB Output is correct
11 Correct 4 ms 5840 KB Output is correct
12 Correct 3 ms 5840 KB Output is correct
13 Correct 5 ms 5840 KB Output is correct
14 Correct 3 ms 5840 KB Output is correct
15 Correct 4 ms 5780 KB Output is correct
16 Correct 4 ms 5840 KB Output is correct
17 Correct 4 ms 5840 KB Output is correct
18 Correct 4 ms 5880 KB Output is correct
19 Correct 3 ms 5840 KB Output is correct
20 Correct 4 ms 5840 KB Output is correct
21 Correct 4 ms 5784 KB Output is correct
22 Correct 4 ms 5840 KB Output is correct
23 Correct 3 ms 5840 KB Output is correct
24 Correct 4 ms 5844 KB Output is correct
25 Correct 4 ms 5840 KB Output is correct
26 Correct 4 ms 5892 KB Output is correct
27 Correct 4 ms 5872 KB Output is correct
28 Correct 5 ms 5840 KB Output is correct
29 Correct 4 ms 5852 KB Output is correct
30 Correct 4 ms 5840 KB Output is correct
31 Correct 4 ms 5840 KB Output is correct
32 Correct 5 ms 5860 KB Output is correct
33 Correct 4 ms 5840 KB Output is correct
34 Correct 3 ms 5840 KB Output is correct
35 Correct 3 ms 5840 KB Output is correct
36 Correct 4 ms 5840 KB Output is correct
37 Correct 3 ms 5968 KB Output is correct
38 Correct 4 ms 5968 KB Output is correct
39 Correct 3 ms 5844 KB Output is correct
40 Correct 3 ms 5848 KB Output is correct
41 Correct 3 ms 5848 KB Output is correct
42 Correct 3 ms 5848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 612 ms 9128 KB Output is correct
2 Correct 914 ms 12504 KB Output is correct
3 Correct 1034 ms 12568 KB Output is correct
4 Correct 724 ms 12356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 612 ms 9128 KB Output is correct
2 Correct 914 ms 12504 KB Output is correct
3 Correct 1034 ms 12568 KB Output is correct
4 Correct 724 ms 12356 KB Output is correct
5 Correct 698 ms 9160 KB Output is correct
6 Correct 888 ms 12508 KB Output is correct
7 Correct 1127 ms 12596 KB Output is correct
8 Correct 974 ms 12556 KB Output is correct
9 Correct 503 ms 5968 KB Output is correct
10 Correct 751 ms 6224 KB Output is correct
11 Correct 788 ms 6224 KB Output is correct
12 Correct 826 ms 6168 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 4 ms 5840 KB Output is correct
4 Correct 3 ms 5840 KB Output is correct
5 Correct 5 ms 5840 KB Output is correct
6 Correct 3 ms 5840 KB Output is correct
7 Correct 4 ms 5780 KB Output is correct
8 Correct 4 ms 5840 KB Output is correct
9 Correct 4 ms 5840 KB Output is correct
10 Correct 4 ms 5880 KB Output is correct
11 Correct 3 ms 5840 KB Output is correct
12 Correct 4 ms 5840 KB Output is correct
13 Correct 612 ms 9128 KB Output is correct
14 Correct 914 ms 12504 KB Output is correct
15 Correct 1034 ms 12568 KB Output is correct
16 Correct 724 ms 12356 KB Output is correct
17 Correct 698 ms 9160 KB Output is correct
18 Correct 888 ms 12508 KB Output is correct
19 Correct 1127 ms 12596 KB Output is correct
20 Correct 974 ms 12556 KB Output is correct
21 Correct 503 ms 5968 KB Output is correct
22 Correct 751 ms 6224 KB Output is correct
23 Correct 788 ms 6224 KB Output is correct
24 Correct 826 ms 6168 KB Output is correct
25 Runtime error 81 ms 28676 KB Execution killed with signal 11
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 3 ms 5840 KB Output is correct
4 Correct 3 ms 5840 KB Output is correct
5 Correct 4 ms 5840 KB Output is correct
6 Correct 3 ms 5840 KB Output is correct
7 Correct 4 ms 5832 KB Output is correct
8 Correct 3 ms 5840 KB Output is correct
9 Correct 3 ms 5712 KB Output is correct
10 Correct 3 ms 5712 KB Output is correct
11 Correct 4 ms 5840 KB Output is correct
12 Correct 3 ms 5840 KB Output is correct
13 Correct 5 ms 5840 KB Output is correct
14 Correct 3 ms 5840 KB Output is correct
15 Correct 4 ms 5780 KB Output is correct
16 Correct 4 ms 5840 KB Output is correct
17 Correct 4 ms 5840 KB Output is correct
18 Correct 4 ms 5880 KB Output is correct
19 Correct 3 ms 5840 KB Output is correct
20 Correct 4 ms 5840 KB Output is correct
21 Correct 4 ms 5784 KB Output is correct
22 Correct 4 ms 5840 KB Output is correct
23 Correct 3 ms 5840 KB Output is correct
24 Correct 4 ms 5844 KB Output is correct
25 Correct 4 ms 5840 KB Output is correct
26 Correct 4 ms 5892 KB Output is correct
27 Correct 4 ms 5872 KB Output is correct
28 Correct 5 ms 5840 KB Output is correct
29 Correct 4 ms 5852 KB Output is correct
30 Correct 4 ms 5840 KB Output is correct
31 Correct 4 ms 5840 KB Output is correct
32 Correct 5 ms 5860 KB Output is correct
33 Correct 4 ms 5840 KB Output is correct
34 Correct 3 ms 5840 KB Output is correct
35 Correct 3 ms 5840 KB Output is correct
36 Correct 4 ms 5840 KB Output is correct
37 Correct 3 ms 5968 KB Output is correct
38 Correct 4 ms 5968 KB Output is correct
39 Correct 3 ms 5844 KB Output is correct
40 Correct 3 ms 5848 KB Output is correct
41 Correct 3 ms 5848 KB Output is correct
42 Correct 3 ms 5848 KB Output is correct
43 Correct 656 ms 6096 KB Output is correct
44 Correct 867 ms 6096 KB Output is correct
45 Correct 784 ms 6096 KB Output is correct
46 Correct 855 ms 6224 KB Output is correct
47 Correct 877 ms 6224 KB Output is correct
48 Correct 946 ms 6224 KB Output is correct
49 Correct 891 ms 6300 KB Output is correct
50 Correct 793 ms 6224 KB Output is correct
51 Correct 824 ms 6096 KB Output is correct
52 Correct 970 ms 6012 KB Output is correct
53 Correct 868 ms 6352 KB Output is correct
54 Correct 910 ms 6232 KB Output is correct
55 Correct 888 ms 6108 KB Output is correct
56 Correct 780 ms 6096 KB Output is correct
57 Correct 978 ms 5968 KB Output is correct
58 Correct 898 ms 6608 KB Output is correct
59 Correct 709 ms 6680 KB Output is correct
60 Correct 827 ms 6660 KB Output is correct
61 Correct 643 ms 6180 KB Output is correct
62 Correct 786 ms 6100 KB Output is correct
63 Correct 889 ms 6024 KB Output is correct
64 Correct 858 ms 6004 KB Output is correct
65 Correct 295 ms 5968 KB Output is correct
66 Correct 970 ms 6224 KB Output is correct
67 Correct 901 ms 6224 KB Output is correct
68 Correct 759 ms 6224 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5712 KB Output is correct
2 Correct 3 ms 5712 KB Output is correct
3 Correct 3 ms 5840 KB Output is correct
4 Correct 3 ms 5840 KB Output is correct
5 Correct 4 ms 5840 KB Output is correct
6 Correct 3 ms 5840 KB Output is correct
7 Correct 4 ms 5832 KB Output is correct
8 Correct 3 ms 5840 KB Output is correct
9 Correct 3 ms 5712 KB Output is correct
10 Correct 3 ms 5712 KB Output is correct
11 Correct 4 ms 5840 KB Output is correct
12 Correct 3 ms 5840 KB Output is correct
13 Correct 5 ms 5840 KB Output is correct
14 Correct 3 ms 5840 KB Output is correct
15 Correct 4 ms 5780 KB Output is correct
16 Correct 4 ms 5840 KB Output is correct
17 Correct 4 ms 5840 KB Output is correct
18 Correct 4 ms 5880 KB Output is correct
19 Correct 3 ms 5840 KB Output is correct
20 Correct 4 ms 5840 KB Output is correct
21 Correct 4 ms 5784 KB Output is correct
22 Correct 4 ms 5840 KB Output is correct
23 Correct 3 ms 5840 KB Output is correct
24 Correct 4 ms 5844 KB Output is correct
25 Correct 4 ms 5840 KB Output is correct
26 Correct 4 ms 5892 KB Output is correct
27 Correct 4 ms 5872 KB Output is correct
28 Correct 5 ms 5840 KB Output is correct
29 Correct 4 ms 5852 KB Output is correct
30 Correct 4 ms 5840 KB Output is correct
31 Correct 4 ms 5840 KB Output is correct
32 Correct 5 ms 5860 KB Output is correct
33 Correct 4 ms 5840 KB Output is correct
34 Correct 3 ms 5840 KB Output is correct
35 Correct 3 ms 5840 KB Output is correct
36 Correct 4 ms 5840 KB Output is correct
37 Correct 3 ms 5968 KB Output is correct
38 Correct 4 ms 5968 KB Output is correct
39 Correct 3 ms 5844 KB Output is correct
40 Correct 3 ms 5848 KB Output is correct
41 Correct 3 ms 5848 KB Output is correct
42 Correct 3 ms 5848 KB Output is correct
43 Correct 612 ms 9128 KB Output is correct
44 Correct 914 ms 12504 KB Output is correct
45 Correct 1034 ms 12568 KB Output is correct
46 Correct 724 ms 12356 KB Output is correct
47 Correct 698 ms 9160 KB Output is correct
48 Correct 888 ms 12508 KB Output is correct
49 Correct 1127 ms 12596 KB Output is correct
50 Correct 974 ms 12556 KB Output is correct
51 Correct 503 ms 5968 KB Output is correct
52 Correct 751 ms 6224 KB Output is correct
53 Correct 788 ms 6224 KB Output is correct
54 Correct 826 ms 6168 KB Output is correct
55 Runtime error 81 ms 28676 KB Execution killed with signal 11
56 Halted 0 ms 0 KB -