/ WOJ /

记录详情

Wrong Answer


  
# 状态 耗时 内存占用
#1 Wrong Answer 成绩取消 0ms 0 Bytes

代码

#include <bits/extc++.h>
#define endl '\n'
typedef long long ll;
#define int ll
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;

struct ly {
  int to, nxt;
};

void Main() {
  int n;
  cin >> n;
  vector<int> he(n + 1), fa(n + 1), dep(n + 1), l(n + 1), r(n + 1);
  vector<vector<int>> dep_mp(n + 1);
  vector<ly> edge(1);
  auto add = [&](const int &u, const int &v) {
    edge.emplace_back(v, he[u]);
    he[u] = edge.size() - 1;
  };
  fa[1] = 1;
  for (int i = 2; i <= n; ++i) {
    cin >> fa[i];
    add(fa[i], i);
  }
  int t = 0;
  function<void(int)> dfs = [&](const int &u) {
    l[u] = ++t;
    dep_mp[dep[u]].push_back(l[u]);
    for (int i = he[u]; i; i = edge[i].nxt) {
      const int &v = edge[i].to;
      fa[v] = u;
      dep[v] = dep[u] + 1;
      dfs(v);
    }
    r[u] = t;
  };
  dfs(1);
  int q;
  cin >> q;
  while (q--) {
    int d, x;
    cin >> d >> x;
    auto u = ranges::lower_bound(dep_mp[d], l[x]);
    auto v = ranges::upper_bound(dep_mp[d], r[x]);
    cout << v - u << endl;
  }
  cout << "Debug:dep_mp" << endl;
  for (const auto &_: dep_mp) {
    for (int i = 0; i < _.size(); ++i) {
      cout << _[i] << " \n"[i == _.size() - 1];
    }
  }
}

// #define __CP_MULTI_TEST_CASES

signed main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int t = 1;
#ifdef __CP_MULTI_TEST_CASES
  cin >> t;
#endif
  while (t--) {
    Main();
  }
  return cout << flush, fflush(stdout), 0;
}

信息

递交者
类型
递交
题目
P1000 云剪贴板
题目数据
下载
语言
C++
递交时间
2025-07-21 18:49:40
评测时间
2025-07-21 18:49:43
评测机
分数
0
总耗时
0ms
峰值内存
0 Bytes