제출 #719079

#제출 시각아이디문제언어결과실행 시간메모리
719079baojiaopisu디지털 회로 (IOI22_circuit)C++17
100 / 100
1141 ms44196 KiB
#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 f[N], val[N];
vector<ll> v;

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

		Node(ll _one = 0, ll _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);
		if(n > 0) build(0, n - 1, 1);
	}
private:
	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;
		}
	}

	void build(int l, int r, int id) {
		if(l == r) {
			node[id].zero = v[l];
			return;
		}
		int mid = (l + r) >> 1;
		build(l, mid, id << 1);
		build(mid + 1, r, id << 1 | 1);
		node[id] = merge(node[id << 1], node[id << 1 | 1]);
	}

	Node merge(const Node &a, const Node &b) {
		Node ans = Node();
		ans.one = (a.one + b.one) % MOD;
		ans.zero = (a.zero + b.zero) % MOD;
		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);
	}
};
vector<int> state;
SegTree IT = SegTree(0);

int n, m;
ll coef = 0;

void dfs(int u) {
	f[u] = 1;
	if(u >= n) return;
	for(auto v : g[u]) {
		dfs(v);
		f[u] = (f[u] * f[v]) % MOD;
	}

	f[u] = f[u] * g[u].size() % MOD;
	// IT = SegTree(m);
}

void dfs2(int u) {
	if(u >= n) return;
	int sz = g[u].size();
	vector<ll> pref(sz), suff(sz);
	pref[0] = f[g[u][0]];
	suff[sz - 1] = f[g[u][sz - 1]];

	for(int i = 1; i < sz; i++) {
		pref[i] = pref[i - 1] * f[g[u][i]] % MOD;
	}

	for(int i = sz - 2; i >= 0; i--) {
		suff[i] = suff[i + 1] * f[g[u][i]] % MOD;
	}

	for(int i = 0; i < g[u].size(); i++) {
		int v = g[u][i];
		val[v] = val[u];
		if(i > 0) val[v] = (val[v] * pref[i - 1]) % MOD;
		if(i + 1 < g[u].size()) val[v] = (val[v] * suff[i + 1]) % MOD;
		dfs2(v);
	}
}


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;
	dfs(0);
	val[0] = 1;
	dfs2(0);
	v.resize(m);
	for(int i = 0; i < m; i++) v[i] = val[i + n];
	IT = SegTree(m);
	for(int i = 0; i < m; i++) {
		if(state[i]) IT.update(i, i);
	}
}

ll count_ways(int l, int r) {
	l -= n;
	r -= n;

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

컴파일 시 표준 에러 (stderr) 메시지

circuit.cpp: In function 'void dfs2(int)':
circuit.cpp:176:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  176 |  for(int i = 0; i < g[u].size(); i++) {
      |                 ~~^~~~~~~~~~~~~
circuit.cpp:180:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  180 |   if(i + 1 < g[u].size()) val[v] = (val[v] * suff[i + 1]) % MOD;
      |      ~~~~~~^~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...