QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#502813#7245. Frank SinatraRainPPRCompile Error//C++234.5kb2024-08-03 14:40:232024-08-03 14:40:24

Judging History

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

  • [2024-08-03 14:40:24]
  • 评测
  • [2024-08-03 14:40:23]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

#define int ll

constexpr int N = 5e5 + 10;

// -----------------------------------------------------------------------------

int n, m;

vector<int> s;

#define get_id(x) ({ lower_bound(s.begin(), s.end(), (x)) - s.begin() + 1; })

struct edge {
    int v, w;
    edge() = default;
    edge(int v, int w): v(v), w(w) {}
};

vector<edge> g[N];

int col[N];

// -----------------------------------------------------------------------------

int dfs[2 * N], tot;
int st[N], ed[N];

namespace hld {
    int fa[N], son[N];
    int dep[N], siz[N];
    int top[N];

    void dfs1(int u, int ff) {
        dfs[++tot] = u, st[u] = tot;
        siz[u] = 1, son[u] = -1;
        int mx = -1;
        for (auto t : g[u]) {
            int v = t.v;
            if (v == ff) continue;
            col[v] = get_id(t.w);
            fa[v] = u, dep[v] = dep[u] + 1;
            dfs1(v, u), siz[u] += siz[v];
            if (siz[v] > mx) mx = siz[v], son[u] = v;
        }
        dfs[++tot] = u, ed[u] = tot;
    }

    void dfs2(int u, int tp) {
        top[u] = tp;
        if (son[u] == -1) return;
        dfs2(son[u], tp);
        for (auto t : g[u]) {
            if (t.v == fa[u]) continue;
            if (t.v == son[u]) continue;
            dfs2(t.v, t.v);
        }
    }
}

int lca(int u, int v) {
    while (hld::top[u] != hld::top[v]) {
        if (hld::dep[hld::top[u]] > hld::dep[hld::top[v]])
            u = hld::fa[hld::top[u]];
        else v = hld::fa[hld::top[v]];
    }
    return hld::dep[u] < hld::dep[v] ? u : v;
}

// -----------------------------------------------------------------------------

int block1, belong1[2 * N];

struct query {
    int id, l, r, lca;
    friend bool operator <(const query &a, const query &b) {
        if (belong1[a.l] != belong1[b.l]) return a.l < b.l;
        return belong1[a.l] & 1 ? a.r < b.r : a.r > b.r;
    }
} q[N];

// -----------------------------------------------------------------------------

bool vis[2 * N];

int block, cnt;
int belong[N], L[N], R[N];
int bucket[N], appr[N];

void add(int x) {
    assert(x >= 1);
    assert(x < n);
    if (!bucket[x]) ++appr[belong[x]];
    ++bucket[x];
    assert(bucket[x] <= n);
}

void del(int x) {
    assert(x >= 1);
    assert(x < n);
    --bucket[x];
    assert(bucket[x] >= 0);
    if (!bucket[x]) --appr[belong[x]];
}

int get_ans() {
    int inner = 1;
    while (inner <= cnt && appr[inner] == R[inner] - L[inner] + 1) ++inner;
    for (int i = max(L[inner] - 100, 1); i <= min(R[inner] + 100, n); ++i) if (!bucket[i]) return i;
    assert(false);
    return s.size();
}

void calc(int x) {
    assert(x <= n);
    if (vis[x]) del(col[x]);
    else add(col[x]);
    vis[x] ^= 1;
}

// -----------------------------------------------------------------------------

int ans[N];

signed main() {
    cin >> n >> m;
    // 预处理值域分块
    block = sqrt(n), cnt = (n - 1) / block + 1;
    for (int i = 1; i <= n; ++i) belong[i] = (i - 1) / block + 1;
    for (int i = 1; i <= cnt; ++i) R[i] = i * block, L[i] = R[i] - block + 1;
    R[cnt] = n;
    // 操作离线
    for (int i = 2; i <= n; ++i) {
        int u, v, w;
        cin >> u >> v >> w;
        g[u].emplace_back(v, w);
        g[v].emplace_back(u, w);
        s.push_back(w);
    }
    sort(s.begin(), s.end());
    s.erase(unique(s.begin(), s.end()), s.end());
    s.push_back(s.back() + 1);
    // 轻重链剖分
    hld::dfs1(1, -1);
    hld::dfs2(1, 1);
    col[1] = 1;
    for (int i = 1; i <= m; ++i) {
        int u, v;
        cin >> u >> v;
        if (st[u] > st[v]) swap(u, v);
        int l = lca(u, v);
        assert(l != 0);
        if (l == u) q[i] = query{i, st[u], st[v], l};
        else q[i] = query{i, ed[u], st[v], -1};
    }
    block1 = max(1, int(tot / sqrt(m * 2 / 3.0)));
    for (int i = 1; i <= tot; ++i) belong1[i] = (i - 1) / block1 + 1;
    sort(q + 1, q + m + 1);
    // 莫队算法
    int l = 1, r = 0;
    for (int i = 1; i <= m; ++i) {
        int x = q[i].l, y = q[i].r;
        while (x < l) calc(dfs[--l]);
        while (y > r) calc(dfs[++r]);
        while (x > l) calc(dfs[l++]);
        while (y < r) calc(dfs[r--]);
        assert(x == l && y == r);
        if (q[i].lca != -1) calc(q[i].lca);
        ans[q[i].id] = get_ans();
        if (q[i].lca != -1) calc(q[i].lca);
    }
    for (int i = 1; i <= m; ++i)
        cout << s[ans[i] - 1] << endl;
    return 0;
}

詳細信息

answer.code: In function ‘ll get_ans()’:
answer.code:114:21: error: no matching function for call to ‘max(ll, int)’
  114 |     for (int i = max(L[inner] - 100, 1); i <= min(R[inner] + 100, n); ++i) if (!bucket[i]) return i;
      |                  ~~~^~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51,
                 from answer.code:1:
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
answer.code:114:21: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’)
  114 |     for (int i = max(L[inner] - 100, 1); i <= min(R[inner] + 100, n); ++i) if (!bucket[i]) return i;
      |                  ~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
answer.code:114:21: note:   deduced conflicting types for parameter ‘const _Tp’ (‘long long int’ and ‘int’)
  114 |     for (int i = max(L[inner] - 100, 1); i <= min(R[inner] + 100, n); ++i) if (!bucket[i]) return i;
      |                  ~~~^~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/13/algorithm:61:
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)’
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
answer.code:114:21: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’
  114 |     for (int i = max(L[inner] - 100, 1); i <= min(R[inner] + 100, n); ++i) if (!bucket[i]) return i;
      |                  ~~~^~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)’
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
answer.code:114:21: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘long long int’
  114 |     for (int i = max(L[inner] - 100, 1); i <= min(R[inner] + 100, n); ++i) if (!bucket[i]) return i;
      |                  ~~~^~~~~~~~~~~~~~~~~~~
answer.code: In function ‘int main()’:
answer.code:161:17: error: no matching function for call to ‘max(int, ll)’
  161 |     block1 = max(1, int(tot / sqrt(m * 2 / 3.0)));
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note: candidate: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
answer.code:161:17: note:   deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘ll’ {aka ‘long long int’})
  161 |     block1 = max(1, int(tot / sqrt(m * 2 / 3.0)));
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algobase.h:303:5: note:   template argument deduction/substitution failed:
answer.code:161:17: note:   deduced conflicting types for parameter ‘const _Tp’ (‘int’ and ‘ll’ {aka ‘long long int’})
  161 |     block1 = max(1, int(tot / sqrt(m * 2 / 3.0)));
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note: candidate: ‘template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)’
 5795 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5795:5: note:   template argument deduction/substitution failed:
answer.code:161:17: note:   mismatched types ‘std::initializer_list<_Tp>’ and ‘int’
  161 |     block1 = max(1, int(tot / sqrt(m * 2 / 3.0)));
      |              ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note: candidate: ‘template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)’
 5805 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/13/bits/stl_algo.h:5805:5: note:   template argument deduction/substitution failed:
answe...