QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#740729#9733. Heavy-light DecompositionHaz_BegoniaWA 0ms3624kbC++201.8kb2024-11-13 11:18:062024-11-13 11:18:08

Judging History

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

  • [2024-11-13 11:18:08]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3624kb
  • [2024-11-13 11:18:06]
  • 提交

answer

//
// Created by 85228 on 2024/11/2.
//

#include <bits/stdc++.h>

using namespace std;
#define int long long
#define fi first
#define se second

using PII = pair<int, int>;

const int N = 1E6 + 10, Mod = 998244353, INF = 1E18;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> fa(n + 1);
    vector<int> l(m), r(m), p(m);
    iota(p.begin(), p.end(), 0ll);
    for(int i = 0; i < m; i++) {
        cin >> l[i] >> r[i];
        for(int j = l[i] + 1; j <= r[i]; j++) {
            fa[j] = j - 1;
        }
    }

    sort(p.begin(), p.end(), [&] (int x, int y) {
        return r[x] - l[x] > r[y] - l[y];
    });

    if(m == 1) {
        for(int i = 1; i <= n; i++) {
            cout << fa[i] << " \n"[i == n];
        }
        return;
    }

    int mx_len = r[p[0]] - l[p[0]] + 1;
    if(mx_len - (r[p[m - 1]] - l[p[m - 1]] + 1) <= 1) {
        cout << "IMPOSSIBLE\n";
        return;
    }

    if(mx_len == r[p[1]] - l[p[1]] + 1) {
        for(int i = 1; i < m; i++) {
            int len = r[p[i]] - l[p[i]] + 1;
            if(mx_len - len <= 1) {
                fa[l[p[i]]] = l[p[0]];
            } else {
                fa[l[p[i]]] = l[p[0]] + 1;
            }
        }
        for(int i = 1; i <= n; i++) {
            cout << fa[i] << " \n"[i == n];
        }
        return;
    }

    for(int i = 1; i < m; i++) {
        fa[l[p[i]]] = l[p[0]];
    }
    for(int i = 1; i <= n; i++) {
        cout << fa[i] << " \n"[i == n];
    }
}

signed main() {
#ifndef ONLINE_JUDGE
    freopen("E:\\C++clion\\in.txt", "r", stdin);
//    freopen("E:\\C++clion\\out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(0), cin.tie(0);
    cout.tie(0);
    int T = 1;
    cin >> T;
    while(T--) {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3624kb

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 1 1 7 1 9 10 1
IMPOSSIBLE
IMPOSSIBLE

result:

wrong answer Case 2, jury find a solution while participant not. (test case 2)