QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#751333 | #9733. Heavy-light Decomposition | hhdhh# | WA | 0ms | 3572kb | C++23 | 1.4kb | 2024-11-15 18:10:39 | 2024-11-15 18:10:40 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
typedef long long ll;
#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
#define sz(a) a.size()
#define all(a) a.begin(),a.end()
typedef pair<ll, ll> pll;
const ll N = 3e5 + 10;
void solve()
{
ll n, m;
cin >> n >> m;
ll fa[n + 5];
vector<pll>ve;
rep(i, 1, n) {
fa[i] = 0;
}
rep(i, 1, m) {
ll l, r;
cin >> l >> r;
ve.push_back({-1 * (r - l + 1), l});
per(j, r, l + 1) {
fa[j] = j - 1;
}
}
if(m == 1) {
rep(i, 1, n) {
cout << fa[i] << " \n"[i == n];
}
}
else {
sort(all(ve));
rep(i, 1, sz(ve) - 1) {
fa[ve[i].second] = ve[0].second;
}
if(ve[0].first == -1 || ve.back().first < 2 + ve[0].first) {
cout << "IMPOSSIBLE" << endl;
return;
}
if(ve[0].first == ve[1].first) fa[ve.back().second] = ve[0].second + 1;
rep(i, 1, n) {
cout << fa[i] << " \n"[i == n];
}
}
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
int T=1;
cin>>T;
while(T--)
{
solve();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3572kb
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)