QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#789709 | #9733. Heavy-light Decomposition | qfl_zzz# | WA | 0ms | 3684kb | C++23 | 1.5kb | 2024-11-27 21:32:24 | 2024-11-27 21:32:29 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define vv vector
#define ll long long
const int N = 200000 + 5;
const int P = 1e9 + 7;
const ll inf = 1e18;
mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
uniform_int_distribution<ll> rd(0, 1e9);
inline ll rnd() { return rd(gen); }
void qfl_zzz()
{
ll n, k;
cin >> n >> k;
vv<ll> fa(n + 1), sz(n + 1);
vv<vv<ll>> a(k + 1);
for (ll i = 1; i <= k; ++i)
{
ll l, r;
cin >> l >> r;
for (ll j = l; j <= r; ++j)
{
a[i].push_back(j);
if (j > l)
fa[j] = j - 1;
}
}
sort(a.begin() + 1, a.end(), [&](auto x, auto y)
{ return x.size() > y.size(); });
ll i = a[1].back(), j = k;
for (; i > 0 && j >= 2; i = fa[i])
{
while (j >= 2 && sz[i] >= a[j].size())
{
fa[*a[j].begin()] = i;
sz[i] += a[j].size();
--j;
}
++sz[i], sz[fa[i]] += sz[i];
}
if (j >= 2)
{
cout << "IMPOSSIBLE\n";
return;
}
for (ll i = 1; i <= n; ++i)
cout << fa[i] << " \n"[i == n];
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
srand(unsigned(time(0)));
cout << setiosflags(ios::fixed) << setprecision(12);
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("std.txt", "w", stdout);
#endif
int T = 1;
cin >> T;
while (T--)
qfl_zzz();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3684kb
input:
3 12 5 1 5 9 11 7 8 6 6 12 12 4 3 1 1 4 4 2 3 2 2 1 1 2 2
output:
0 1 2 3 4 4 4 7 4 9 10 4 2 0 2 2 IMPOSSIBLE
result:
wrong answer 5 should be a heavy child, but the maximum one with size 3 and 1 found. (test case 1)