QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#786251#9733. Heavy-light DecompositionZhZlzcWA 1ms3592kbC++201006b2024-11-26 20:52:502024-11-26 20:52:50

Judging History

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

  • [2024-11-26 20:52:50]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3592kb
  • [2024-11-26 20:52:50]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long
#define x first
#define y second
using namespace std;
using LL = long long;
typedef pair<int, int> PII;
const int N = 1e5 + 10, M = 5010, mod = 1e9 + 7;
const int inf = 1e18;
void solve(){
	int n, k;
	cin >> n >> k;
	vector <PII> a(k + 1);
	vector <int> fa(n + 1);
	for(int i = 1; i <= k; i++){
		cin >> a[i].x >> a[i].y;
		for(int j = a[i].x + 1; j <= a[i].y; j++){
			fa[j] = j - 1;
		}
	}
	sort(a.begin() + 1, a.end(), [&](PII a, PII b){
		return (a.y - a.x) > (b.y - b.x);
	});
	if(k == 1){
		fa[a[1].x] = 0;
		for(int i = 1; i <= n; i++) cout << fa[i] << " \n"[ i == n ];
		return;
	}
	if(a[1].y - a[1].x == a[2].y - a[2].x) cout << "IMPOSSIBLE\n";
	else{
		for(int i = 2; i <= n; i++){
			fa[a[i].x] = a[1].x;
		}
		for(int i = 1; i <= n; i++){
			cout << fa[i] << " \n"[ i == n ];
		}
	}
}
signed main() {
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	int T = 1;
	cin >> T;
	while(T--) {
		solve();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3592kb

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:

1 1 1 3 4 1 1 7 1 9 10 1
2 0 2 2
IMPOSSIBLE

result:

wrong answer self-loops found. (test case 1)