QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#518249#4564. Digital CircuitDan4Life#0 23ms10836kbC++231.8kb2024-08-13 18:50:092024-08-13 18:50:09

Judging History

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

  • [2024-08-13 18:50:09]
  • 评测
  • 测评结果:0
  • 用时:23ms
  • 内存:10836kb
  • [2024-08-13 18:50:09]
  • 提交

answer

#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a), end(a)
using vi = vector<int>;
using ll = long long;
using ar2 = array<ll,2>;
const int mxN = (int)1e5+10;
const int MOD = 1000002022;
int n, m;
vi a, p;
vi adj[mxN*2];
vector<ll> dp[mxN][2];
int st[mxN], en[mxN];
int dfs_tim = 0;

bool upper(int a, int b){
	return st[a]<=st[b] and en[a]>=en[b];
}

ar2 dfs(int s, int p, int l, int r){
	if(l==0 and r==n+m-1) st[s]=dfs_tim++;
	if(sz(adj[s])==0){
		if(a[s-n]==1) return {0,1};
		return {1,0};
	}
	vector<ar2> v; v.clear();
	for(auto u : adj[s]){
		if(u==p) continue;
		if(!upper(u,l) and !upper(u,r)) continue;
		v.pb(dfs(u,s,l,r));
	}
	if(l==0 and r==n+m-1) en[s]=dfs_tim;
	int k = sz(v);
	dp[s][0].clear(), dp[s][1].clear();
	dp[s][0].resize(k+1,0);
	dp[s][1].resize(k+1,0);
	vector<vector<ll>> num(k+1,vector<ll>(k+1,0));
	num[0][0] = 1;
	for(int i = 1; i <= k; i++){
		for(int j = 0; j <= k; j++){
			num[i][j]+=(num[i-1][j]*v[i-1][0])%MOD, num[i][j]%=MOD;
			if(j) num[i][j]+=(num[i-1][j-1]*v[i-1][1])%MOD, num[i][j]%=MOD;
		}
	}
	
	for(int i = 1; i <= k; i++) 
		num[k][i]+=num[k][i-1];
	for(int i = 1; i <= k; i++){
		dp[s][0][i]+=num[k][i-1];
		dp[s][1][i]+=num[k][k]-num[k][i-1];
		for(int j:{0,1}) dp[s][j][i]%=MOD;
	}
	int num0 = 0, num1 = 0;
	for(int i = 1; i <= k; i++){
		num0+=dp[s][0][i], num1+=dp[s][1][i];
		num0%=MOD, num1%=MOD;
	}
	return {num0, num1};
}

void init(int N, int M, vi P, vi A) {
	n = N, m = M;
	for(auto u : P) p.pb(u);
	for(auto u : A) a.pb(u);
	for(int i = 1; i < n+m; i++) 
		adj[p[i]].pb(i);
	dfs(0,-1,0,n+m-1);
}

int count_ways(int L, int R) {
	for(int i = L; i <= R; i++) a[i-n]^=1;
	return dfs(0,-1, L, R)[1];
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 2
Accepted
time: 0ms
memory: 3844kb

input:

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

output:

1
2
0
1
1

result:

ok 7 lines

Test #2:

score: 2
Accepted
time: 0ms
memory: 3844kb

input:

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

output:

1
0
1
0

result:

ok 6 lines

Test #3:

score: 0
Wrong Answer
time: 23ms
memory: 10836kb

input:

1 972
-1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...

output:

159
430
324
414
404

result:

wrong answer 3rd lines differ - expected: '509', found: '159'

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 7
Accepted
time: 1ms
memory: 3848kb

input:

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

output:

1
2
0
1
1

result:

ok 7 lines

Test #10:

score: 0
Wrong Answer
time: 1ms
memory: 3892kb

input:

255 256
-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 51 ...

output:

26065470
8192
688590930

result:

wrong answer 3rd lines differ - expected: '52130940', found: '26065470'

Subtask #3:

score: 0
Skipped

Dependency #1:

0%

Subtask #4:

score: 0
Time Limit Exceeded

Test #43:

score: 0
Time Limit Exceeded

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:

517012836
475918536
92382482
557506280
82580362
653827890
222787672
908741012
241593102
574126924
290725634
954775488
211402716
101058084
743794624
467767786
76344612
50561812
706015460
204943206
995078270
351956112
279163580
913950482
998415450
823932862
590923418
444393156
430058352
896955328
5750...

result:


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%