/ SeriousOJ /

Record Detail

Compile Error

In file included from /usr/include/c++/13/string:43,
                 from /usr/include/c++/13/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:52,
                 from foo.cc:5:
/usr/include/c++/13/bits/allocator.h: In destructor 'std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_impl()':
/usr/include/c++/13/bits/allocator.h:184:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = int]': target specific option mismatch
  184 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/13/vector:66,
                 from /usr/include/c++/13/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:53:
/usr/include/c++/13/bits/stl_vector.h:133:14: note: called from here
  133 |       struct _Vector_impl
      |              ^~~~~~~~~~~~

Code

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")

#ifndef LOCAL
#include <bits/stdc++.h>
#define debug(...)
#endif

using namespace std;
#define cinv(v) for (auto &it:v) cin>>it;
#define coutv(v) for (auto &it:v) cout<< it<<' '; cout<<'\n';

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const int N = 1e5 + 5;
int arr[N], ans[N], sz[N];
vector<int> adj[N];

void shelby() {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> arr[i], adj[i].clear();
    for (int i = 1; i < n; ++i) {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    auto dfs = [&](auto &&self, int u, int par)-> ordered_set<int> {
        ordered_set<int> ret;
        ret.insert(arr[u]);
        sz[u] = 1;
        for (auto &v: adj[u]) {
            if (v == par) continue;
            ordered_set<int> o = self(self, v, u);
            if (o.size() > ret.size()) swap(ret, o);
            for (auto &it: o) ret.insert(it);
            sz[u] += sz[v];
        }
        ans[u] = sz[u] - (ret.order_of_key(sz[u] + 1));
        return ret;
    };
    dfs(dfs, 1, -1);
    int q;
    cin >> q;
    while (q--) {
        int x;
        cin >> x;
        cout << ans[x] << '\n';
    }
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    cin >> t;
    for (int _ = 1; _ <= t; ++_) {
        // cout << "Case " << _ << ": ";
        shelby();
    }
}

Information

Submit By
Type
Submission
Problem
P1157 Roy and Tree Permutation
Language
C++17 (G++ 13.2.0)
Submit At
2025-01-12 20:34:50
Judged At
2025-01-12 20:34:50
Judged By
Score
0
Total Time
0ms
Peak Memory
0 Bytes