QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#626876#5148. Tree DistancedanielzCompile Error//C++201.5kb2024-10-10 13:39:352024-10-10 13:39:36

Judging History

你现在查看的是最新测评结果

  • [2024-10-10 13:39:36]
  • 评测
  • [2024-10-10 13:39:35]
  • 提交

answer

#define LCA
#define CENTROID
#include "centroid.h"
#include "sgt.h"
using namespace std;

const int N = 2e5 + 1;

struct P { int i; ll d; 
  bool operator<(const P &o) const { return i < o.i; }
};
struct E { int u, v; ll w;
  bool operator<(const E &o) const {
    return v == o.v ? w > o.w : v < o.v;
  }
};
vector<P> v[N];
SGT<2 * N, ll> sgt;
ll r[N];

int main() {
  int n; cin >> n;
  Tree<N, W, set<W, less<>>> t(n);
  t.input().root(1).dfs().decompose();
  for (int i = 1; i <= n; i++) {
    int j = i;
    while (j) {
      v[j].push_back({i, t.D(i, j)});
      j = t.cp[j];
    }
  }
  vector<E> e;
  for (int i = 1; i <= n; i++) {
    sort(v[i].begin(), v[i].end());
    vector<P> st;
    for (auto [j, d] : v[i]) {
      while (st.size() && st.back().d >= d) {
        e.push_back({st.back().i, j, t.D(st.back().i, j)});
        st.pop_back();
      }
      if (st.size()) e.push_back({st.back().i, j, t.D(st.back().i, j)});
      st.push_back({j, d});
    }
  }
  /* for (auto [u, v, w] : e) cout << u << " " << v << " " << w << endl; */
  sgt.fn([](ll x, ll y) { return min(x, y); }, inf).fill(inf);
  int q; cin >> q;
  for (int i = 0; i < q; i++) {
    int u, v; cin >> u >> v;
    e.push_back({u, v, -i});
  }
  sort(e.begin(), e.end());
  for (auto [u, v, w] : e) {
    if (w < 1) r[-w] = sgt.query(u, n + 1);
    else sgt.upd(u, w);
  }
  for (int i = 0; i < q; i++) {
    cout << (r[i] < inf ? r[i] : -1) << endl;
  }
}

详细

answer.code:3:10: fatal error: centroid.h: No such file or directory
    3 | #include "centroid.h"
      |          ^~~~~~~~~~~~
compilation terminated.