QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#644336 | #6335. Belt Conveyor | L_Hospital_ | 1 | 58ms | 56600kb | C++17 | 2.5kb | 2024-10-16 13:20:47 | 2024-10-16 13:20:48 |
Judging History
answer
#include "conveyor.h"
#include <vector>
#include<bits/stdc++.h>
# define rep(i, j, k) for (int i = j; i <= k; ++i)
using namespace std;
int n, hd[100005], to[200005], nxt[200005], id[200005], etimer;
int sz[100005], d[100005], p[100005], nt[100005], ppp[100005], son[100005], ly[100005], lbian[100005], maxx;
int ans[100005];
int stk[100005], r;
vector < int > qu[33], ute[33];
void addedge(int u, int v, int ix){to[++etimer] = v, nxt[etimer] = hd[u], hd[u] = etimer; id[etimer] = ix;}
void dfs(int u, int fa)
{
p[u] = fa, d[u] = d[fa] + 1; sz[u] = 1; son[u] = 0;
for (int i = hd[u]; i; i = nxt[i]) if (to[i] != fa) {nt[to[i]] = abs(id[i]), ppp[to[i]] = (id[i] < 0); dfs(to[i], u); sz[u] += sz[to[i]]; if (sz[to[i]] > sz[son[u]]) son[u] = to[i];}
}
void dfs_solve(int u, int lye)
{
ly[u] = lye; maxx = max(maxx, lye);
if (son[u]) dfs_solve(son[u], lye); else stk[++r] = u;
for (int i = hd[u]; i; i = nxt[i]) if (to[i] != p[u] && to[i] != son[u]) dfs_solve(to[i], lye + 1);
}
void Solve(int N, std::vector<int> A, std::vector<int> B)
{
std::vector<int> x(N - 1, 0), y(N, 0), za, zb, a(N - 1, 0);
rep(i, 1, 30) qu[i] = x, ute[i] = y;
n = N;
rep(i, 0, n - 2) addedge(A[i] + 1, B[i] + 1, i + 1), addedge(B[i] + 1, A[i] + 1, -i - 1);
dfs(1, 0);
int rt = 1;
rep(i, 2, n) if (sz[i] >= (n + 1) / 2 && sz[i] < sz[rt]) rt = i;// cerr << rt << endl;
nt[rt] = 0; dfs(rt, 0);
dfs_solve(rt, 1);
// rep(i, 1, n) cerr << i << ' ' << son[i] << '\n';
for (int i = maxx; i; --i)
{
rep(j, 1, r) if (ly[stk[j]] == i)
{
int u = stk[j];
do
{//cerr << u << endl;
if (u != rt) qu[2 * i][nt[u] - 1] = 1;
u = p[u];
} while (ly[u] == ly[stk[j]]);
}
else if (ly[stk[j]] > i)
{
int u = stk[j];
do
{
if (u != rt) qu[2 * i - 1][nt[u] - 1] = qu[2 * i][nt[u] - 1] = (ans[nt[u]] ^ ppp[u] ^ 1);
u = p[u];
} while (ly[u] == ly[stk[j]]);
}
rep(j, 0, n - 1) ute[2 * i - 1][j] = ute[2 * i][j] = 1;
// rep(j, 0, n - 2) cerr << qu[2 * i - 1][j] << ' '; cerr << '\n';
// rep(j, 0, n - 2) cerr << qu[2 * i][j] << ' '; cerr << '\n';
za = Query(qu[2 * i - 1], ute[2 * i - 1]), zb = Query(qu[2 * i], ute[2 * i]);
rep(j, 1, r) if (ly[stk[j]] == i)
{
int pos = (za[stk[j] - 1] == 1), u = stk[j];
do
{
if (u != rt) ans[nt[u]] = (pos ^ ppp[u] ^ 1);
u = p[u];
if (u > 0) if (za[u - 1] || zb[u - 1]) pos = !pos;
} while (ly[u] == ly[stk[j]]);
}
}
rep(i, 0, n - 2) a[i] = ans[i + 1];//, cerr << a[i] << '\n';
Answer(a);
}
详细
Subtask #1:
score: 1
Accepted
Test #1:
score: 1
Accepted
time: 1ms
memory: 5976kb
input:
random1 2 0 1 1 0xC321A02965AC2640
output:
Accepted: 2
result:
ok correct
Test #2:
score: 1
Accepted
time: 1ms
memory: 7936kb
input:
random1 2 1 0 0 0x8A99AD9552B2C218
output:
Accepted: 2
result:
ok correct
Test #3:
score: 1
Accepted
time: 1ms
memory: 6192kb
input:
random1 2 1 0 1 0x024D21FA307D148D
output:
Accepted: 2
result:
ok correct
Test #4:
score: 1
Accepted
time: 0ms
memory: 8244kb
input:
random1 2 0 1 0 0x3C96AB23CEB63F75
output:
Accepted: 2
result:
ok correct
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #5:
score: 0
Wrong Answer
time: 1ms
memory: 6208kb
input:
priority 30 10 29 10 13 17 11 2 15 15 27 9 26 18 0 14 1 22 24 29 28 6 22 4 20 15 5 28 4 21 24 3 13 1 8 13 12 8 19 16 3 1 10 24 29 12 8 4 7 2 7 28 25 12 7 2 23 27 22 89058848 6377689 24189123 31671827 205117644 254374430 56016068 6819602 212866321 246625321 274047319 230485311 202854776 280075001 203...
output:
Wrong Answer [8]
result:
wrong answer Token "Wrong" doesn't correspond to pattern "Accepted:"
Subtask #3:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 58ms
memory: 56600kb
input:
random1 100000 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 9...
output:
Wrong Answer [8]
result:
wrong answer Token "Wrong" doesn't correspond to pattern "Accepted:"
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%