Submission #1025267

# Submission time Handle Problem Language Result Execution time Memory
1025267 2024-07-16T18:48:24 Z vjudge1 Digital Circuit (IOI22_circuit) C++17
0 / 100
428 ms 17248 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
pair<int, int> pii;

const int MOD = 1000002022;
const int maxn = 2e5 + 100;

int n, k;
int p[maxn];
vector<int> g[maxn];
int a[maxn];
int t[maxn * 4];
ll sum[maxn];
ll d[2][maxn * 4];
ll dp[maxn];
int sz[maxn];

void pre(int v){
	swap(d[0][v], d[1][v]);
	t[v] ^= 1;
}

void push(int v, int tl, int tr){
	if(tl == tr || !t[v]) return;
	t[v] = 0; pre(v<<1); pre(v<<1|1);
}

void build(int v = 1, int tl = k + 1, int tr = n){
	if(tl == tr){
		d[a[tl]][v] = dp[tl];
	} else{
		int mid = (tl + tr) >> 1;
		build(v<<1, tl, mid);
		build(v<<1|1, mid+1, tr);
		d[0][v] = d[0][v<<1] + d[0][v<<1|1] % MOD;
		d[1][v] = d[1][v<<1] + d[1][v<<1|1] % MOD;
	}
}

void upd(int l, int r, int v = 1, int tl = k + 1, int tr = n){
	push(v, tl, tr);
	if(tl > r || tr < l) return;
	if(tl <= tl && tr <= r) pre(v);
	else{
		int mid = (tl + tr) >> 1;
		upd(l, r, v<<1, tl, mid);
		upd(l, r, v<<1|1, mid+1, tr);
		d[0][v] = d[0][v<<1] + d[0][v<<1|1] % MOD;
		d[1][v] = d[1][v<<1] + d[1][v<<1|1] % MOD;
	}
}

void init(int N, int M, std::vector<int> P, std::vector<int> A){
	n = N + M; k = N;
	for(int i = 1; i <= n; i++){
		p[i] = P[i-1]; p[i]++;
		g[p[i]].push_back(i);
		dp[i] = 1;
	}
	for(int v = n; v > 0; v--){
		sum[v] = 1;
		for(int to: g[v]){
			sum[v] = sum[v] * sum[to] % MOD;
		}
		if(v <= k) sum[v] = sum[v] * g[v].size() % MOD;
	}
	for(int i = k + 1; i <= n; i++){
		a[i] = A[i - k - 1];
	}
	for(int v = 1; v <= k; v++){
		ll d = 1;
		for(int to: g[v]){
			dp[to] = dp[v];
			dp[to] = dp[to] * d % MOD;
			d = d * sum[to] % MOD;
		}
		d = 1;
		reverse(g[v].begin(), g[v].end());
		for(int to: g[v]){
			dp[to] = dp[to] * d % MOD;
			d = d * sum[to] % MOD;
		}
	}
	build();
}

int count_ways(int L, int R){
	upd(L + 1, R + 1);
	return d[1][1];
}

Compilation message

circuit.cpp: In function 'void upd(int, int, int, int, int)':
circuit.cpp:44:8: warning: self-comparison always evaluates to true [-Wtautological-compare]
   44 |  if(tl <= tl && tr <= r) pre(v);
      |     ~~ ^~ ~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 13140 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 12888 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 13140 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 428 ms 17248 KB 1st lines differ - on the 1st token, expected: '431985922', found: '1099628832'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 428 ms 17248 KB 1st lines differ - on the 1st token, expected: '431985922', found: '1099628832'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 12888 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 13140 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 13140 KB 2nd lines differ - on the 1st token, expected: '2', found: '1'
2 Halted 0 ms 0 KB -