QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#526557 | #4564. Digital Circuit | green_gold_dog# | 2 | 1ms | 4080kb | C++20 | 1.1kb | 2024-08-21 17:36:11 | 2024-08-21 17:36:11 |
answer
#include "circuit.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1'000'002'022;
void dfs(ll v, vector<vector<ll>>& sons, vector<ll>& cf, ll ncf) {
if (v >= sons.size()) {
cf[v - sons.size()] = ncf;
return;
}
vector<ll> pcf(1, 1);
vector<ll> muls;
for (auto i : sons[v]) {
ll nmul = 1;
if (i < sons.size()) {
nmul = sons[i].size();
}
muls.push_back(nmul);
pcf.push_back(pcf.back() * nmul % MOD);
}
ll muln = 1;
reverse(sons[v].begin(), sons[v].end());
for (auto i : sons[v]) {
ll nmul = muls.back();
muls.pop_back();
pcf.pop_back();
dfs(i, sons, cf, ncf * muln % MOD * pcf.back() % MOD);
muln = muln * nmul % MOD;
}
}
vector<int> na;
vector<ll> ncf;
ll nn;
void init(int n, int m, vector<int> p, vector<int> a) {
vector<vector<ll>> sons(n);
for (ll i = 1; i < n + m; i++) {
sons[p[i]].push_back(i);
}
vector<ll> cf(m);
dfs(0, sons, cf, 1);
na = a;
ncf = cf;
nn = n;
}
int count_ways(int l, int r) {
l -= nn;
r -= nn;
for (ll i = l; i <= r; i++) {
na[i] ^= 1;
}
ll ans = 0;
for (ll i = 0; i < na.size(); i++) {
ans += ncf[i] * na[i];
ans %= MOD;
}
return ans;
}
詳細信息
Subtask #1:
score: 2
Accepted
Test #1:
score: 2
Accepted
time: 1ms
memory: 4048kb
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: 1ms
memory: 3792kb
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: 2
Accepted
time: 1ms
memory: 3828kb
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:
509 483 489 500 481
result:
ok 7 lines
Test #4:
score: 2
Accepted
time: 0ms
memory: 3828kb
input:
1 1000 -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 ...
output:
4 40 428 262 237
result:
ok 7 lines
Test #5:
score: 2
Accepted
time: 1ms
memory: 3760kb
input:
1 1000 -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 ...
output:
898 828 828 617 582
result:
ok 7 lines
Test #6:
score: 2
Accepted
time: 0ms
memory: 3924kb
input:
1 1000 -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 ...
output:
535 494 500 498 509
result:
ok 7 lines
Test #7:
score: 2
Accepted
time: 1ms
memory: 3836kb
input:
1 1000 -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 ...
output:
517 486 511 487 512
result:
ok 7 lines
Test #8:
score: 2
Accepted
time: 1ms
memory: 4080kb
input:
1 1000 -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 ...
output:
501 500 499 500 501
result:
ok 7 lines
Subtask #2:
score: 0
Wrong Answer
Test #9:
score: 7
Accepted
time: 1ms
memory: 3792kb
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: 3792kb
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:
16384 16000 17152
result:
wrong answer 3rd lines differ - expected: '52130940', found: '16384'
Subtask #3:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
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:
268730368 268713984 268730368 268746752 268763136 268746752 268730368 268746752 268730368 268746752 268763136 268746752 268730368 268713984 268697600 268681216 268697600 268713984 268730368 268713984 268697600 268713984 268730368 268746752 268763136 268746752 268730368 268713984 268697600 268681216 ...
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:
100%
Accepted
Dependency #2:
0%