QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#853307#9733. Heavy-light Decompositionucup-team4435#WA 0ms3856kbC++201.2kb2025-01-11 16:32:332025-01-11 16:32:35

Judging History

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

  • [2025-01-11 16:32:35]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3856kb
  • [2025-01-11 16:32:33]
  • 提交

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;
}

详细

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)