답안 #719060

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
719060 2023-04-05T09:33:32 Z baojiaopisu 디지털 회로 (IOI22_circuit) C++17
2 / 100
22 ms 2124 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 = 1000 + 10;

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

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++) {
      |                 ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 19 ms 412 KB Output is correct
4 Correct 22 ms 436 KB Output is correct
5 Correct 20 ms 336 KB Output is correct
6 Correct 20 ms 432 KB Output is correct
7 Correct 20 ms 336 KB Output is correct
8 Correct 20 ms 428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 1360 KB Output is correct
3 Runtime error 1 ms 592 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 19 ms 412 KB Output is correct
4 Correct 22 ms 436 KB Output is correct
5 Correct 20 ms 336 KB Output is correct
6 Correct 20 ms 432 KB Output is correct
7 Correct 20 ms 336 KB Output is correct
8 Correct 20 ms 428 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 1 ms 1360 KB Output is correct
11 Runtime error 1 ms 592 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 2124 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 10 ms 2124 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 336 KB Output is correct
2 Correct 1 ms 1360 KB Output is correct
3 Runtime error 1 ms 592 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 19 ms 412 KB Output is correct
4 Correct 22 ms 436 KB Output is correct
5 Correct 20 ms 336 KB Output is correct
6 Correct 20 ms 432 KB Output is correct
7 Correct 20 ms 336 KB Output is correct
8 Correct 20 ms 428 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 1 ms 1360 KB Output is correct
11 Runtime error 1 ms 592 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 208 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 19 ms 412 KB Output is correct
4 Correct 22 ms 436 KB Output is correct
5 Correct 20 ms 336 KB Output is correct
6 Correct 20 ms 432 KB Output is correct
7 Correct 20 ms 336 KB Output is correct
8 Correct 20 ms 428 KB Output is correct
9 Correct 0 ms 336 KB Output is correct
10 Correct 1 ms 1360 KB Output is correct
11 Runtime error 1 ms 592 KB Execution killed with signal 11
12 Halted 0 ms 0 KB -