Submission #719062

# Submission time Handle Problem Language Result Execution time Memory
719062 2023-04-05T09:34:18 Z baojiaopisu Digital Circuit (IOI22_circuit) C++17
34 / 100
992 ms 15356 KB
#include<bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;

#define fi first
#define se second
#define left BAO
#define right ANH
#define pb push_back
#define pf push_front
#define mp make_pair
#define ins insert
#define btpc __builtin_popcount
#define btclz __builtin_clz

#define sz(x) (int)(x.size());
#define all(x) x.begin(), x.end()
#define debug(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int d4x[4] = {1, 0, -1, 0}; int d4y[4] = {0, 1, 0, -1};
int d8x[8] = {0, 1, 1, 1, 0, -1, -1, -1};
int d8y[8] = {1, 1, 0, -1, -1, -1, 0, 1};

template<class X, class Y>
    bool minimize(X &x, const Y &y) {
        if (x > y)
        {
            x = y;
            return true;
        }
        return false;
    }
template<class X, class Y>
    bool maximize(X &x, const Y &y) {
        if (x < y)
        {
            x = y;
            return true;
        }
        return false;
    }

const int MOD = 1000002022; //998244353

template<class X, class Y>
	void add(X &x, const Y &y) {
		x = (x + y);
		if(x >= MOD) x -= MOD;
	}

template<class X, class Y> 
	void sub(X &x, const Y &y) {
		x = (x - y);
		if(x < 0) x += MOD;
	}

/* Author : Le Ngoc Bao Anh, 12A5, LQD High School for Gifted Student*/

const ll INF = 1e9;
const int N = 2e5 + 10;

vector<int> g[N];
ll dp[2005][2], f[2005][2005];

struct SegTree {
	int n;
	struct Node {
		int one, zero;
		int lazy;

		Node(int _one = 0, int _zero = 0, int _lazy = 0) {
			one = _one;
			zero = _zero;
			lazy = _lazy;
		}
	};
	vector<Node> node;

	SegTree(int _n = 0) {
		n = _n;
		node.resize(4 * n + 7);
		build(0, n - 1, 1);
	}
private:
	void build(int l, int r, int id) {
		node[id].zero = r - l + 1;
		if(l == r) return;
		int mid = (l + r) >> 1;
		build(l, mid, id << 1);
		build(mid + 1, r, id << 1 | 1);
	}

	void Down(int id) {
		if(!node[id].lazy) return;
		node[id].lazy = 0;

		for(int i = (id << 1); i <= (id << 1 | 1); i++) {
			swap(node[i].one, node[i].zero);
			node[i].lazy ^= 1;
		}
	}

	Node merge(const Node &a, const Node &b) {
		Node ans = Node();
		ans.one = a.one + b.one;
		ans.zero = a.zero + b.zero;
		return ans;
	}

	void Update(int l, int r, int lo, int hi, int id) {
		if(l > hi || r < lo) return;
		if(lo <= l && r <= hi) {
			swap(node[id].one, node[id].zero);
			node[id].lazy ^= 1;
			return;
		}

		int mid = (l + r) >> 1;
		Down(id);
		Update(l, mid, lo, hi, id << 1);
		Update(mid + 1, r, lo, hi, id << 1 | 1);
		node[id] = merge(node[id << 1], node[id << 1 | 1]);
	}
public:
	void update(int l, int r) {
		Update(0, n - 1, l, r, 1);
	}
};
SegTree IT = SegTree(1);

int n, m;
ll coef = 0;
vector<int> state;
void init(int N, int M, vector<int> p, vector<int> A) {
	for(int i = 1; i < N + M; i++) {
		g[p[i]].pb(i);
	}
	n = N; m = M;
	state = A;
	coef = 1;
	IT = SegTree(m);
	for(int i = 0; i < m; i++) {
		if(state[i]) IT.update(i, i);
	}
	int d = m, f = 0;
	while(d > 1) {
		d /= 2;
		f++;
	}
	for(int i = 0; i < n - f; i++) {
		coef = (coef * 2) % MOD;
	}
}

void dfs(int u) {
	if(u >= n) return;
	for(int i = 0; i <= g[u].size(); i++) f[u][i] = 0;
	f[u][0] = 1;
	for(auto v : g[u]) {
		dfs(v);
		for(int i = g[u].size(); i >= 0; i--) {
			f[u][i] = f[u][i] * dp[v][0] % MOD;
			if(i > 0) f[u][i] += f[u][i - 1] * dp[v][1] % MOD;
			f[u][i] %= MOD;
		}
	}

	dp[u][0] = dp[u][1] = 0;
	for(int i = 0; i <= g[u].size(); i++) {
		dp[u][1] += f[u][i] * i % MOD;
		dp[u][0] += f[u][i] * (g[u].size() - i) % MOD;
		dp[u][0] %= MOD;
		dp[u][1] %= MOD;
	}
	// IT = SegTree(m);
}

ll count_ways(int l, int r) {
	l -= n;
	r -= n;
	if(n <= 1000 && m <= 1000) {
		for(int i = l; i <= r; i++) state[i] ^= 1;

		for(int i = n; i < n + m; i++) {
			dp[i][1] = state[i - n];
			dp[i][0] = state[i - n] ^ 1;
		}

		dfs(0);
		return dp[0][1];
	}

	IT.update(l, r);
	return (coef * IT.node[1].one) % MOD;
}

Compilation message

circuit.cpp: In function 'void dfs(int)':
circuit.cpp:167:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  167 |  for(int i = 0; i <= g[u].size(); i++) f[u][i] = 0;
      |                 ~~^~~~~~~~~~~~~~
circuit.cpp:179:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  179 |  for(int i = 0; i <= g[u].size(); i++) {
      |                 ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 20 ms 5072 KB Output is correct
4 Correct 24 ms 5104 KB Output is correct
5 Correct 25 ms 5104 KB Output is correct
6 Correct 22 ms 5072 KB Output is correct
7 Correct 22 ms 5072 KB Output is correct
8 Correct 23 ms 5088 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 5968 KB Output is correct
3 Correct 4 ms 7032 KB Output is correct
4 Correct 4 ms 7120 KB Output is correct
5 Correct 4 ms 7120 KB Output is correct
6 Correct 5 ms 8024 KB Output is correct
7 Correct 5 ms 9168 KB Output is correct
8 Correct 5 ms 9168 KB Output is correct
9 Correct 5 ms 9168 KB Output is correct
10 Correct 5 ms 9168 KB Output is correct
11 Correct 5 ms 9268 KB Output is correct
12 Correct 5 ms 8528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 20 ms 5072 KB Output is correct
4 Correct 24 ms 5104 KB Output is correct
5 Correct 25 ms 5104 KB Output is correct
6 Correct 22 ms 5072 KB Output is correct
7 Correct 22 ms 5072 KB Output is correct
8 Correct 23 ms 5088 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 5968 KB Output is correct
11 Correct 4 ms 7032 KB Output is correct
12 Correct 4 ms 7120 KB Output is correct
13 Correct 4 ms 7120 KB Output is correct
14 Correct 5 ms 8024 KB Output is correct
15 Correct 5 ms 9168 KB Output is correct
16 Correct 5 ms 9168 KB Output is correct
17 Correct 5 ms 9168 KB Output is correct
18 Correct 5 ms 9168 KB Output is correct
19 Correct 5 ms 9268 KB Output is correct
20 Correct 5 ms 8528 KB Output is correct
21 Correct 4 ms 8016 KB Output is correct
22 Correct 4 ms 8272 KB Output is correct
23 Correct 4 ms 7632 KB Output is correct
24 Correct 5 ms 9168 KB Output is correct
25 Correct 6 ms 9168 KB Output is correct
26 Correct 5 ms 9168 KB Output is correct
27 Correct 5 ms 9168 KB Output is correct
28 Correct 5 ms 9168 KB Output is correct
29 Correct 28 ms 5072 KB Output is correct
30 Correct 22 ms 5100 KB Output is correct
31 Correct 5 ms 9168 KB Output is correct
32 Correct 6 ms 9168 KB Output is correct
33 Correct 4 ms 7120 KB Output is correct
34 Correct 4 ms 6096 KB Output is correct
35 Correct 7 ms 5100 KB Output is correct
36 Correct 6 ms 9168 KB Output is correct
37 Correct 24 ms 9168 KB Output is correct
38 Correct 24 ms 9168 KB Output is correct
39 Correct 5 ms 7888 KB Output is correct
40 Correct 4 ms 7120 KB Output is correct
41 Correct 4 ms 6480 KB Output is correct
42 Correct 4 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 580 ms 8500 KB Output is correct
2 Correct 776 ms 11904 KB Output is correct
3 Correct 724 ms 11912 KB Output is correct
4 Correct 714 ms 11848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 580 ms 8500 KB Output is correct
2 Correct 776 ms 11904 KB Output is correct
3 Correct 724 ms 11912 KB Output is correct
4 Correct 714 ms 11848 KB Output is correct
5 Correct 611 ms 8464 KB Output is correct
6 Correct 992 ms 11908 KB Output is correct
7 Correct 933 ms 11908 KB Output is correct
8 Correct 904 ms 11848 KB Output is correct
9 Correct 433 ms 5204 KB Output is correct
10 Correct 877 ms 5328 KB Output is correct
11 Correct 626 ms 5392 KB Output is correct
12 Correct 589 ms 5440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 5968 KB Output is correct
3 Correct 4 ms 7032 KB Output is correct
4 Correct 4 ms 7120 KB Output is correct
5 Correct 4 ms 7120 KB Output is correct
6 Correct 5 ms 8024 KB Output is correct
7 Correct 5 ms 9168 KB Output is correct
8 Correct 5 ms 9168 KB Output is correct
9 Correct 5 ms 9168 KB Output is correct
10 Correct 5 ms 9168 KB Output is correct
11 Correct 5 ms 9268 KB Output is correct
12 Correct 5 ms 8528 KB Output is correct
13 Correct 580 ms 8500 KB Output is correct
14 Correct 776 ms 11904 KB Output is correct
15 Correct 724 ms 11912 KB Output is correct
16 Correct 714 ms 11848 KB Output is correct
17 Correct 611 ms 8464 KB Output is correct
18 Correct 992 ms 11908 KB Output is correct
19 Correct 933 ms 11908 KB Output is correct
20 Correct 904 ms 11848 KB Output is correct
21 Correct 433 ms 5204 KB Output is correct
22 Correct 877 ms 5328 KB Output is correct
23 Correct 626 ms 5392 KB Output is correct
24 Correct 589 ms 5440 KB Output is correct
25 Incorrect 832 ms 15356 KB 1st lines differ - on the 1st token, expected: '732332002', found: '355232644'
26 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 20 ms 5072 KB Output is correct
4 Correct 24 ms 5104 KB Output is correct
5 Correct 25 ms 5104 KB Output is correct
6 Correct 22 ms 5072 KB Output is correct
7 Correct 22 ms 5072 KB Output is correct
8 Correct 23 ms 5088 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 5968 KB Output is correct
11 Correct 4 ms 7032 KB Output is correct
12 Correct 4 ms 7120 KB Output is correct
13 Correct 4 ms 7120 KB Output is correct
14 Correct 5 ms 8024 KB Output is correct
15 Correct 5 ms 9168 KB Output is correct
16 Correct 5 ms 9168 KB Output is correct
17 Correct 5 ms 9168 KB Output is correct
18 Correct 5 ms 9168 KB Output is correct
19 Correct 5 ms 9268 KB Output is correct
20 Correct 5 ms 8528 KB Output is correct
21 Correct 4 ms 8016 KB Output is correct
22 Correct 4 ms 8272 KB Output is correct
23 Correct 4 ms 7632 KB Output is correct
24 Correct 5 ms 9168 KB Output is correct
25 Correct 6 ms 9168 KB Output is correct
26 Correct 5 ms 9168 KB Output is correct
27 Correct 5 ms 9168 KB Output is correct
28 Correct 5 ms 9168 KB Output is correct
29 Correct 28 ms 5072 KB Output is correct
30 Correct 22 ms 5100 KB Output is correct
31 Correct 5 ms 9168 KB Output is correct
32 Correct 6 ms 9168 KB Output is correct
33 Correct 4 ms 7120 KB Output is correct
34 Correct 4 ms 6096 KB Output is correct
35 Correct 7 ms 5100 KB Output is correct
36 Correct 6 ms 9168 KB Output is correct
37 Correct 24 ms 9168 KB Output is correct
38 Correct 24 ms 9168 KB Output is correct
39 Correct 5 ms 7888 KB Output is correct
40 Correct 4 ms 7120 KB Output is correct
41 Correct 4 ms 6480 KB Output is correct
42 Correct 4 ms 5200 KB Output is correct
43 Incorrect 650 ms 5288 KB 1st lines differ - on the 1st token, expected: '196037954', found: '432252474'
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4944 KB Output is correct
2 Correct 3 ms 4944 KB Output is correct
3 Correct 20 ms 5072 KB Output is correct
4 Correct 24 ms 5104 KB Output is correct
5 Correct 25 ms 5104 KB Output is correct
6 Correct 22 ms 5072 KB Output is correct
7 Correct 22 ms 5072 KB Output is correct
8 Correct 23 ms 5088 KB Output is correct
9 Correct 2 ms 4944 KB Output is correct
10 Correct 3 ms 5968 KB Output is correct
11 Correct 4 ms 7032 KB Output is correct
12 Correct 4 ms 7120 KB Output is correct
13 Correct 4 ms 7120 KB Output is correct
14 Correct 5 ms 8024 KB Output is correct
15 Correct 5 ms 9168 KB Output is correct
16 Correct 5 ms 9168 KB Output is correct
17 Correct 5 ms 9168 KB Output is correct
18 Correct 5 ms 9168 KB Output is correct
19 Correct 5 ms 9268 KB Output is correct
20 Correct 5 ms 8528 KB Output is correct
21 Correct 4 ms 8016 KB Output is correct
22 Correct 4 ms 8272 KB Output is correct
23 Correct 4 ms 7632 KB Output is correct
24 Correct 5 ms 9168 KB Output is correct
25 Correct 6 ms 9168 KB Output is correct
26 Correct 5 ms 9168 KB Output is correct
27 Correct 5 ms 9168 KB Output is correct
28 Correct 5 ms 9168 KB Output is correct
29 Correct 28 ms 5072 KB Output is correct
30 Correct 22 ms 5100 KB Output is correct
31 Correct 5 ms 9168 KB Output is correct
32 Correct 6 ms 9168 KB Output is correct
33 Correct 4 ms 7120 KB Output is correct
34 Correct 4 ms 6096 KB Output is correct
35 Correct 7 ms 5100 KB Output is correct
36 Correct 6 ms 9168 KB Output is correct
37 Correct 24 ms 9168 KB Output is correct
38 Correct 24 ms 9168 KB Output is correct
39 Correct 5 ms 7888 KB Output is correct
40 Correct 4 ms 7120 KB Output is correct
41 Correct 4 ms 6480 KB Output is correct
42 Correct 4 ms 5200 KB Output is correct
43 Correct 580 ms 8500 KB Output is correct
44 Correct 776 ms 11904 KB Output is correct
45 Correct 724 ms 11912 KB Output is correct
46 Correct 714 ms 11848 KB Output is correct
47 Correct 611 ms 8464 KB Output is correct
48 Correct 992 ms 11908 KB Output is correct
49 Correct 933 ms 11908 KB Output is correct
50 Correct 904 ms 11848 KB Output is correct
51 Correct 433 ms 5204 KB Output is correct
52 Correct 877 ms 5328 KB Output is correct
53 Correct 626 ms 5392 KB Output is correct
54 Correct 589 ms 5440 KB Output is correct
55 Incorrect 832 ms 15356 KB 1st lines differ - on the 1st token, expected: '732332002', found: '355232644'
56 Halted 0 ms 0 KB -