QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#142905#4564. Digital CircuitAPROHACK#0 43ms24164kbC++202.8kb2023-08-20 02:21:592024-07-04 02:40:46

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 02:40:46]
  • 评测
  • 测评结果:0
  • 用时:43ms
  • 内存:24164kb
  • [2023-08-20 02:21:59]
  • 提交

answer

#include "circuit.h"
#include <cstring>
#include <vector>
#include <cassert>
#define ll long long
#define ff first
#define ss second
#define pb push_back
using namespace std;
int n, m;
vector<int>child[100001];
bool state[100001];
ll encen[100001][2]; // encendido y apagado
const int MOD = 1000002022;
int past[2002][2002];
void generate(int node);
int parent[100001];
bool casito = true;
void init(int N, int M, std::vector<int> P, std::vector<int> A) {
	n = N;
	m = M;
	if( m != n+1 )casito = false;
	for(int i = 0 ; i < n+m ; i ++){
		if(P[i] != -1){
			child[P[i]].pb(i);
			if(P[i] != (i-1)/2)casito = false;
		}
		parent[i] = P[i];
	}
	int temp = m;
	while(temp != 1){
		if(temp % 2 == 1)casito = false;
		temp /= 2;
	}
	if(!casito) assert(casito);
	for(int i = N ; i <= N+M ; i ++)state[i] = A[i-N];
	memset(past, -1, sizeof past);
	generate(0);
}

ll mem[2002][2002];
int currentIt = -1;

void newDp(){
	currentIt++;
}
ll dp(int parent, int i, int k){
	if(k < 0)return 0;
	if(i == child[parent].size() and k > 0)return 0;
	else if(i == child[parent].size()) return 1;
	if(past[i][k] == currentIt)return mem[i][k];
	past[i][k] = currentIt;
	return mem[i][k] = (dp(parent, i+1, k-1) * encen[child[parent][i]][0] + dp(parent, i+1, k) * encen[child[parent][i]][1])%MOD;
}

void generate(int node){
	if(node >= n){
		if(state[node]){
			encen[node][0] = 1;
			encen[node][1] = 0;
		}else{
			encen[node][0] = 0;
			encen[node][1] = 1;
		}
		return ;
	}
	for(int i = 0 ; i < child[node].size() ; i ++){
		generate(child[node][i]);
	}
	newDp();
	ll enc = 0;
	for(int i = 1 ; i <= child[node].size() ; i ++){
		enc += dp(node, 0, i) * i;
		enc %= MOD;
	}
	ll allWays = 1;
	for(int i = 0 ; i < child[node].size() ; i ++){
		allWays *= (encen[child[node][i]][0] + encen[child[node][i]][1]);
		allWays %= MOD;
	}
	allWays *= child[node].size();
	allWays %= MOD;
	encen[node][0] = enc;
	encen[node][1] = ((allWays - enc) + MOD) % MOD;
	//cout << "for node " << node << " there are " << encen[node][0] << ", " << encen[node][1] << "\n";
}
void recargar(int node){
	if(node >= n){
		if(state[node]){
			encen[node][0] = 1;
			encen[node][1] = 0;
		}else{
			encen[node][0] = 0;
			encen[node][1] = 1;
		}
		return ;
	}
	newDp();
	ll enc = 0;
	for(int i = 1 ; i <= child[node].size() ; i ++){
		enc += dp(node, 0, i) * i;
		enc %= MOD;
	}
	ll allWays = 1;
	for(int i = 0 ; i < child[node].size() ; i ++){
		allWays *= (encen[child[node][i]][0] + encen[child[node][i]][1]);
		allWays %= MOD;
	}
	allWays *= child[node].size();
	allWays %= MOD;
	encen[node][0] = enc;
	encen[node][1] = ((allWays - enc) + MOD) % MOD;
	if(parent[node] != -1)recargar(parent[node]);
}

int count_ways(int L, int R) {
	for(int i = L ; i <= R ; i ++){
		state[i] = !state[i];
	}
	if(L == R and casito)recargar(L);
	else generate(0);
	return encen[0][0];
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 2ms
memory: 20164kb

input:

1 2
-1 0 0
0 0
1 1
2 2
1 2
2 2
1 2
-1 -1
-2 -2

output:

0
0
0
0
1

result:

wrong answer 3rd lines differ - expected: '1', found: '0'

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 0ms
memory: 22220kb

input:

1 2
-1 0 0
0 0
1 1
2 2
1 2
2 2
1 2
-1 -1
-2 -2

output:

0
0
0
0
1

result:

wrong answer 3rd lines differ - expected: '1', found: '0'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Wrong Answer

Test #43:

score: 0
Wrong Answer
time: 43ms
memory: 24164kb

input:

32767 32768
-1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...

output:

394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
394586018
...

result:

wrong answer 3rd lines differ - expected: '431985922', found: '394586018'

Subtask #5:

score: 0
Skipped

Dependency #4:

0%

Subtask #6:

score: 0
Skipped

Dependency #2:

0%

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%