QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#141726 | #4564. Digital Circuit | valerikk# | 2 | 3ms | 12444kb | C++17 | 1.6kb | 2023-08-17 22:33:44 | 2024-07-04 02:39:20 |
Judging History
answer
#include "circuit.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
namespace {
const int N = 2e5 + 7;
const int md = 1e9 + 2022;
int add(int a, int b) {
return a + b < md ? a + b : a + b - md;
}
int mul(int a, int b) {
return a * 1ll * b % md;
}
int pw(int a, int n) {
int ret = 1;
while (n > 0) {
if (n & 1) {
ret = mul(ret, a);
}
a = mul(a, a);
n >>= 1;
}
return ret;
}
int n, m;
int p[N], a[N];
int h[N];
int dp[N];
int sz[N];
vector<int> g[N];
int kek[N];
void dfsdp(int v) {
dp[v] = v >= n ? 1 : sz[v];
for (int u : g[v]) {
dfsdp(u);
dp[v] = mul(dp[v], dp[u]);
}
}
void dfskek(int v) {
if (sz[v] == 0) {
return;
}
{
vector<int> pref(sz[v] + 1, 1), suf(sz[v] + 1, 1);
for (int i = 0; i < sz[v]; ++i) {
pref[i + 1] = mul(pref[i], dp[g[v][i]]);
suf[i + 1] = mul(suf[i], dp[g[v][sz[v] - i - 1]]);
}
for (int i = 0; i < sz[v]; ++i) {
int u = g[v][i];
kek[u] = mul(pref[i], suf[sz[v] - i - 1]);
}
}
for (int u : g[v]) {
dfskek(u);
}
}
}
void init(int grdn, int grdm, vector<int> grdp, vector<int> grda) {
n = grdn;
m = grdm;
for (int i = 0; i < n + m; ++i) {
p[i] = grdp[i];
}
for (int i = 0; i < m; ++i) {
a[n + i] = grda[i];
}
h[0] = 0;
for (int i = 1; i < n + m; ++i) {
h[i] = h[p[i]] + 1;
g[p[i]].push_back(i);
}
for (int i = 0; i < n + m; ++i) {
sz[i] = g[i].size();
}
dfsdp(0);
kek[0] = 1;
dfskek(0);
}
int count_ways(int grdl, int grdr) {
int l = grdl;
int r = grdr;
++r;
for (int i = l; i < r; ++i) {
a[i] ^= 1;
}
int ret = 0;
for (int i = n; i < n + m; ++i) {
if (a[i] == 1) {
ret = add(ret, kek[i]);
}
}
return ret;
}
詳細信息
Subtask #1:
score: 2
Accepted
Test #1:
score: 2
Accepted
time: 3ms
memory: 11984kb
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: 0
Accepted
time: 2ms
memory: 10584kb
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
Accepted
time: 0ms
memory: 10860kb
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: 0
Accepted
time: 3ms
memory: 12444kb
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: 0
Accepted
time: 1ms
memory: 11996kb
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: 0
Accepted
time: 2ms
memory: 10868kb
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: 0
Accepted
time: 3ms
memory: 12024kb
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: 0
Accepted
time: 0ms
memory: 12280kb
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: 2ms
memory: 11988kb
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: -7
Wrong Answer
time: 3ms
memory: 12388kb
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:
128 125 134
result:
wrong answer 3rd lines differ - expected: '52130940', found: '128'
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:
16402 16401 16402 16403 16404 16403 16402 16403 16402 16403 16404 16403 16402 16401 16400 16399 16400 16401 16402 16401 16400 16401 16402 16403 16404 16403 16402 16401 16400 16399 16398 16397 16398 16399 16398 16397 16396 16397 16396 16397 16396 16397 16396 16397 16398 16397 16398 16397 16398 16399 ...
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%