QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#853307 | #9733. Heavy-light Decomposition | ucup-team4435# | WA | 0ms | 3856kb | C++20 | 1.2kb | 2025-01-11 16:32:33 | 2025-01-11 16:32:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int n, k;
cin >> n >> k;
vector<pair<int, int>> s(k);
for (auto &[l, r] : s) {
cin >> l >> r;
--l, --r;
}
sort(s.begin(), s.end(), [&](auto x, auto y) { return x.second - x.first > y.second - y.first; });
vector<int> p(n, -1);
bool yay = true;
int root = 0;
if (n > 1) {
if (s.size() > 1 && s[0].second - s[0].first - 1 <= s.back().second - s.back().first) {
yay = false;
} else {
root = s[0].first;
for (auto [l, r] : s) {
if (l != root) {
p[l] = root + max(0, s[0].second - s[0].first - (r - l) - 1);
}
for (int i = l + 1; i <= r; ++i) {
p[i] = i - 1;
}
}
}
}
if (!yay) {
cout << "IMPOSSIBLE\n";
} else {
for (int x : p) {
cout << x + 1 << " ";
}
}
cout << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int test = 1;
cin >> test;
while (test--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3856kb
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 3 7 2 9 10 4 IMPOSSIBLE IMPOSSIBLE
result:
wrong answer Case 2, jury find a solution while participant not. (test case 2)