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:4: /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("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
// #include "debug.h"
void solve() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; ++i) {
int u, v;
cin >> u >> v;
--u, --v;
g[u].push_back(v), g[v].push_back(u);
}
vector<vector<int>> sub(n);
vector<int> sz(n, 1);
auto merge = [&](vector<int> &u, vector<int> &v) {
if (v.size() > u.size()) {
u.swap(v);
}
for (int i : v) {
u.push_back(i);
}
};
vector<int> ans(n);
auto go = [&](auto &&go, int u, int v) -> void {
sub[u].push_back(a[u]);
for (int c : g[u]) {
if (c == v) {
continue;
}
go(go, c, u);
sz[u] += sz[c];
merge(sub[u], sub[c]);
}
sort(sub[u].begin(), sub[u].end());
int cnt = 0;
vector<int> nsub;
for (int i : sub[u]) {
if (nsub.empty() || nsub.back() != i) {
cnt += (i <= sz[u]);
nsub.push_back(i);
}
}
sub[u].swap(nsub);
ans[u] = sz[u] - cnt;
};
go(go, 0, 0);
int q;
cin >> q;
for (int i = 0; i < q; ++i) {
int x;
cin >> x;
cout << ans[x - 1] << '\n';
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int tc = 1;
cin >> tc;
while (tc--) {
solve();
}
}
Information
- Submit By
- Type
- Submission
- Problem
- P1157 Roy and Tree Permutation
- Contest
- Happy New Year 2025
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2025-01-02 16:05:07
- Judged At
- 2025-01-02 16:05:07
- Judged By
- Score
- 0
- Total Time
- 0ms
- Peak Memory
- 0 Bytes