답안 #1030703

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1030703 2024-07-22T08:51:08 Z 42kangaroo 디지털 회로 (IOI22_circuit) C++17
2 / 100
393 ms 7000 KB
#include "circuit.h"

#include <vector>

using namespace std;

vector<int> a;
using g_t = vector<vector<int>>;
g_t g;

using ll = long long;

constexpr ll mod = 1000002022;

struct SVal {
	ll pos, fpos;
};

SVal comb(SVal l, SVal r) {
	return SVal{l.pos + r.pos, l.fpos + r.fpos};
}

struct SegTe {
	vector<SVal> a;
	vector<bool> lazy;

	void push(int i) {
		if (lazy[i]) {
			swap(a[i].pos, a[i].fpos);
			if (2 * i + 2 < a.size()) {
				lazy[2 * i + 1] = !lazy[2 * i + 1];
				lazy[2 * i + 2] = !lazy[2 * i + 2];
			}
			lazy[i] = false;
		}
	}

	SVal toggle(int l, int r, int i, int lq, int rq) {
		push(i);
		if (rq <= l || r <= lq) return a[i];
		if (lq <= l && r <= rq) {
			lazy[i] = true;
			push(i);
			return a[i];
		}
		int m = (l + r) / 2;
		return a[i] = comb(toggle(l, m, 2 * i + 1, lq, rq), toggle(m, r, 2 * i + 2, lq, rq));
	}

	SVal set(int l, int r, int i, int k, int pos, int fpos) {
		if (k < l || k >= r) return a[i];
		if (l + 1 == r) {
			return a[i] = {pos, fpos};
		}
		int m = (l + r)/2;
		return a[i] = comb(set(l, m, 2*i + 1, k, pos, fpos), set(m, r, 2*i + 2, k, pos, fpos));
	}
};

SegTe se;
int n, m;

ll dfs(int t, vector<vector<ll>>& re) {
	if (t >= n) return 1;
	re[t].resize(g[t].size());
	ll tot = 1;
	for (int i = 0; i < g[t].size(); ++i) {
		re[t][i] = dfs(g[t][i], re);
		tot = (tot*re[t][i])%mod;
	}
	return tot;
}

void dfs2(int t, ll to, vector<vector<ll>>& re, vector<ll>& st) {
	if (t >= n) {
		st[t - n] = to;
		return;
	}
	vector<ll> suffMu(re[t].size() + 1, 1);
	for (int i = re[t].size() - 1; i >= 0; --i) {
		suffMu[i] = (suffMu[i + 1]*re[t][i])%mod;
	}
	ll mu = 1;
	for (int i = 0; i < re[t].size(); ++i) {
		dfs2(g[t][i], (((to*mu)%mod)*suffMu[i + 1])%mod, re, st);
		mu = (mu*re[t][i])%mod;
	}
}

void init(int N, int M, std::vector<int> P, std::vector<int> A) {
	n = N; m = M;
	g = g_t(N);
	for (int i = 1; i < N + M; ++i) {
		g[P[i]].push_back(i);
	}
	vector<vector<ll>> re(N);
	dfs(0, re);
	vector<ll> res(M);
	dfs2(0, 1, re, res);
	se = SegTe{vector<SVal>(4*M), vector<bool>(4*M, false)};
	for (int i = 0; i < M; ++i) {
		if (A[i] == 1) {
			se.set(0, M, 0, i, res[i], 0);
		} else {
			se.set(0, M, 0, i, 0, res[i]);
		}
	}
}

int count_ways(int L, int R) {
	L -= n;
	R -= n;
	return se.toggle(0, m, 0, L, R + 1).pos;
}

Compilation message

circuit.cpp: In member function 'void SegTe::push(int)':
circuit.cpp:30:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<SVal>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   30 |    if (2 * i + 2 < a.size()) {
      |        ~~~~~~~~~~^~~~~~~~~~
circuit.cpp: In function 'll dfs(int, std::vector<std::vector<long long int> >&)':
circuit.cpp:67:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for (int i = 0; i < g[t].size(); ++i) {
      |                  ~~^~~~~~~~~~~~~
circuit.cpp: In function 'void dfs2(int, ll, std::vector<std::vector<long long int> >&, std::vector<long long int>&)':
circuit.cpp:84:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |  for (int i = 0; i < re[t].size(); ++i) {
      |                  ~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 596 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 393 ms 7000 KB 1st lines differ - on the 1st token, expected: '431985922', found: '16402'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 393 ms 7000 KB 1st lines differ - on the 1st token, expected: '431985922', found: '16402'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 596 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 344 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 1 ms 344 KB Output is correct
8 Correct 0 ms 596 KB Output is correct
9 Correct 0 ms 344 KB Output is correct
10 Incorrect 1 ms 344 KB 1st lines differ - on the 1st token, expected: '52130940', found: '128'
11 Halted 0 ms 0 KB -