답안 #779705

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
779705 2023-07-11T17:10:51 Z IBory 디지털 회로 (IOI22_circuit) C++17
2 / 100
591 ms 8252 KB
#include "circuit.h"
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const ll SZ = 1 << 17, MOD = 1'000'002'022;
vector<int> G[SZ];
ll N, M, S[SZ], A[SZ], ans;

ll DFS(int cur) {
	ll& ret = S[cur] = G[cur].size();
	if (G[cur].empty()) ret = 1;
	for (int next : G[cur]) {
		ll c = DFS(next);
		ret = ret * c % MOD;
	}
	return ret;
}

void DFS2(int cur, ll n) {
	if (G[cur].empty()) {
		A[cur] = n;
		return;
	}
	vector<ll> D;
	for (int next : G[cur]) D.push_back(S[next]);
	for (int i = (int)D.size() - 2; i >= 0; --i) D[i] = D[i] * D[i + 1] % MOD;
	ll pref = 1;
	for (int i = 0; i < G[cur].size(); ++i) {
		ll t = n * pref % MOD;
		if (i != (int)G[cur].size() - 1) t = t * D[i + 1] % MOD;
		DFS2(G[cur][i], t);
		pref = pref * D[i] % MOD;
	}
}

struct Seg {
	ll T[SZ << 1], P[SZ << 1], Z[SZ << 1];
	void Build(int N, int M) {
		for (int i = SZ; i < SZ + M; ++i) P[i] = A[i - SZ + N];
		for (int i = SZ - 1; i >= 0; --i) P[i] = P[i * 2] + P[i * 2 + 1];
	}
	void Push(int n) {
		if (n < SZ) {
			Z[n * 2] += Z[n];
			Z[n * 2 + 1] += Z[n];
		}
		if (Z[n] & 1) T[n] = P[n] - T[n];
		Z[n] = 0;
	}
	void Update(int L, int R, int sL = 1, int sR = SZ, int n = 1) {
		Push(n);
		if (R < sL || sR < L) return;
		if (L <= sL && sR <= R) {
			ans += P[n] - 2LL * T[n];
			Z[n]++;
			Push(n);
			return;
		}
		int mid = (sL + sR) >> 1;
		Update(L, R, sL, mid, n * 2);
		Update(L, R, mid + 1, sR, n * 2 + 1);
		T[n] = T[n * 2] + T[n * 2 + 1];
	}
} T;

void init(int _N, int _M, vector<int> P, vector<int> Q) {
	N = _N, M = _M;
	for (int i = 1; i < N + M; ++i) G[P[i]].push_back(i);
	DFS(0);
	DFS2(0, 1);
	T.Build(N, M);
	for (int i = 0; i < M; ++i) if (Q[i]) T.Update(i + 1, i + 1);
}

int count_ways(int L, int R) {
	T.Update(L - N + 1, R - N + 1);
	ll ret = ans % MOD;
	return ans;
}

Compilation message

circuit.cpp: In function 'void DFS2(int, ll)':
circuit.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |  for (int i = 0; i < G[cur].size(); ++i) {
      |                  ~~^~~~~~~~~~~~~~~
circuit.cpp: In function 'int count_ways(int, int)':
circuit.cpp:78:5: warning: unused variable 'ret' [-Wunused-variable]
   78 |  ll ret = ans % MOD;
      |     ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 2 ms 4560 KB Output is correct
4 Correct 4 ms 4564 KB Output is correct
5 Correct 2 ms 4560 KB Output is correct
6 Correct 2 ms 4560 KB Output is correct
7 Correct 2 ms 4560 KB Output is correct
8 Correct 2 ms 4560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Incorrect 2 ms 4432 KB 1st lines differ - on the 1st token, expected: '52130940', found: '1840610774'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 2 ms 4560 KB Output is correct
4 Correct 4 ms 4564 KB Output is correct
5 Correct 2 ms 4560 KB Output is correct
6 Correct 2 ms 4560 KB Output is correct
7 Correct 2 ms 4560 KB Output is correct
8 Correct 2 ms 4560 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Incorrect 2 ms 4432 KB 1st lines differ - on the 1st token, expected: '52130940', found: '1840610774'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 591 ms 8252 KB 1st lines differ - on the 1st token, expected: '431985922', found: '-704044656'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 591 ms 8252 KB 1st lines differ - on the 1st token, expected: '431985922', found: '-704044656'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 4432 KB Output is correct
2 Incorrect 2 ms 4432 KB 1st lines differ - on the 1st token, expected: '52130940', found: '1840610774'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 2 ms 4560 KB Output is correct
4 Correct 4 ms 4564 KB Output is correct
5 Correct 2 ms 4560 KB Output is correct
6 Correct 2 ms 4560 KB Output is correct
7 Correct 2 ms 4560 KB Output is correct
8 Correct 2 ms 4560 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Incorrect 2 ms 4432 KB 1st lines differ - on the 1st token, expected: '52130940', found: '1840610774'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4432 KB Output is correct
2 Correct 2 ms 4432 KB Output is correct
3 Correct 2 ms 4560 KB Output is correct
4 Correct 4 ms 4564 KB Output is correct
5 Correct 2 ms 4560 KB Output is correct
6 Correct 2 ms 4560 KB Output is correct
7 Correct 2 ms 4560 KB Output is correct
8 Correct 2 ms 4560 KB Output is correct
9 Correct 2 ms 4432 KB Output is correct
10 Incorrect 2 ms 4432 KB 1st lines differ - on the 1st token, expected: '52130940', found: '1840610774'
11 Halted 0 ms 0 KB -