QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#603175 | #8720. BFS 序 0 | UESTC_DebugSimulator# | WA | 259ms | 27956kb | C++17 | 2.9kb | 2024-10-01 15:03:28 | 2024-10-01 15:05:19 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define lowbit(i) (i&-i)
#define rand() (myrand())
using namespace std;
mt19937 myrand(time(0));
const int maxn = 5e5 + 5;
int n, _, q, m, dfn[maxn], cnt, now[maxn], head[maxn], tot, dep[maxn], tr[maxn], fa[maxn];
struct EDGE{
int next, to;
}edge[maxn<<1];
void addedge(int from, int to) {
edge[++cnt].next = head[from];
edge[cnt].to = to;
head[from] = cnt;
}
void change(int x, int y) {
while(x <= m) {
tr[x] += y;
x += lowbit(x);
}
}
int get(int x) {
int res = 0;
while(x) {
res += tr[x];
x -= lowbit(x);
}
return res;
}
namespace Segtr{
int v[maxn<<2], done[maxn<<2];
void plus(int x, int p) {
v[x] = p;
done[x] = p;
}
void push(int x) {
if (done[x]) {
plus(x<<1, done[x]);
plus(x<<1|1, done[x]);
done[x] = 0;
}
}
int search(int x, int l, int r, int ql) {
if (l == r) return v[x];
int mid = (l + r)>>1;
push(x);
if (ql <= mid) return search(x<<1, l, mid, ql);
return search(x<<1|1, mid + 1, r, ql);
}
void modify(int x, int l, int r, int ql, int qr, int t) {
if (ql <= l && qr >= r) {
plus(x, t);
return;
}
int mid = (l + r)>>1;
push(x);
if (ql <= mid && qr > mid) {
modify(x<<1, l, mid, ql, qr, t);
modify(x<<1|1, mid + 1, r, ql, qr, t);
}
else if (ql > mid) modify(x<<1|1, mid + 1, r, ql, qr, t);
else modify(x<<1, l, mid, ql, qr, t);
v[x] = min(v[x<<1], v[x<<1|1]);
}
}
void dfs(int u, int p) {
dfn[u] = ++tot;
dep[u] = dep[p] + 1;
fa[u] = p;
for (int i = head[u] ; i ; i = edge[i].next) {
int v = edge[i].to;
if (v == p) continue;
dfs(v, u);
}
now[u] = tot;
}
void solve() {
cin >> n;
for (int i = 2 ; i <= n ; ++i) {
int p;
cin >> p;
addedge(i, p);
addedge(p, i);
}
dfs(1, 0);
cin >> q;
for (int i = 1 ; i <= q ; ++i) {
cin >> m;
vector<int>pt(m + 1);
int jud = 0;
for (int j = 1 ; j <= m ; ++j) {
cin >> pt[j];
if (j > 1 && dep[pt[j]] < dep[pt[j - 1]]) jud = 1;
}
if (jud == 1) {
cout << "No" << '\n';
continue;
}
int p = 1;
while(p <= m) {
int l = p, r = p;
while(r + 1 <= m && dep[pt[r]] == dep[pt[r + 1]]) r++;
for (int j = l ; j <= r ; ++j) {
int val = Segtr::search(1, 1, n, pt[j]);
if (!val) continue;
if (get(val) != j - l) jud = 1;
change(val, 1);
}
for (int j = l ; j <= r ; ++j) {
int val = Segtr::search(1, 1, n, pt[j]);
if (!val) continue;
change(val, -1);
}
for (int j = l ; j <= r ; ++j) {
if (pt[j] != 1) Segtr::modify(1, 1, n, dfn[fa[pt[j]]], now[fa[pt[j]]], j);
else Segtr::modify(1, 1, n, dfn[1], now[1], j);
}
p = r + 1;
}
Segtr::modify(1, 1, n, 1, n, 0);
cout << (jud == 1 ? "No" : "Yes") << '\n';
}
}
signed main(void) {
ios::sync_with_stdio(false);
cin.tie(0);
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 9844kb
input:
6 1 1 3 2 4 10 4 3 6 2 5 1 4 3 2 4 5 5 2 5 4 6 3 3 1 4 2 3 5 6 3 5 4 5 2 6 1 4 4 3 2 5 4 4 6 2 3 3 3 2 6
output:
No Yes Yes No No No No No No Yes
result:
ok 10 token(s): yes count is 3, no count is 7
Test #2:
score: -100
Wrong Answer
time: 259ms
memory: 27956kb
input:
300000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
Yes No No No No No No No No No No No No No No Yes Yes Yes Yes No No No No No No Yes No Yes No No No Yes No No No Yes No No No No No No No No No Yes Yes Yes No No No Yes No Yes Yes Yes Yes Yes Yes Yes No Yes No Yes No Yes Yes No No Yes No No No Yes No No No Yes No Yes No No No No No Yes No No No Yes ...
result:
wrong answer expected NO, found YES [1st token]