QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#743812#9733. Heavy-light Decompositionucup-team4975#WA 1ms3508kbC++142.0kb2024-11-13 20:05:362024-11-13 20:05:37

Judging History

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

  • [2024-11-13 20:05:37]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3508kb
  • [2024-11-13 20:05:36]
  • 提交

answer

#define LOCAL
#include <bits/stdc++.h>
#define fir first
#define sec second
#define el '\n'

#ifdef LOCAL
#define FINISH cerr << "FINISH" << endl;
#else
#define FINISH ;
#endif

#ifdef LOCAL
#define debug(x) cerr << setw(4) << #x << " == " << x << endl
#else
#define debug(x)
#endif

#ifdef LOCAL
#define debugv(x)                   \
	cerr << setw(4) << #x << ":: "; \
	for (auto i : x)                \
		cerr << i << " ";           \
	cerr << endl
#else
#define debugv(x)
#endif

using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
ostream& operator<<(ostream& out, PII& x)
{
	out << x.fir << " " << x.sec << endl;
	return out;
}

const int mod = 998244353;
const int inf = 0x3f3f3f3f;
const int N = 200020;
void solve()
{
	int n, m;
	cin >> n >> m;
	vector<PII> a(m + 1);
	for (int i = 1; i <= m; i++) {
		cin >> a[i].fir >> a[i].sec;
	}

	if (m == 1) {
		for (int i = 0; i < n; i++) {
			cout << i << " ";
		}
		cout << el;
		return;
	}

	sort(next(a.begin()), a.end(),
		 [&](PII x, PII y) { return x.sec - x.fir > y.sec - y.fir; });
	int mx = a[1].sec - a[1].fir + 1;

	if (a[2].sec - a[2].fir + 1 != mx) {
		int tmp = 1;
		int rt = 0;
		for (int i = 1; i <= m; i++) {
			int now = rt;
			for (int j = a[i].fir; j <= a[i].sec; j++) {
				cout << now << " ";
				now = tmp;
				tmp++;
			}
			rt = 1;
		}
		cout << el;
		return;
	}

	int flag = 0;
	for (int i = 2; i <= m; i++) {
		if (a[i].sec - a[i].fir + 1 <= mx - 2) {
			flag = i;
			break;
		}
	}
	if (!flag) {
		cout << "IMPOSSIBLE" << el;
		return;
	}


	int tmp = 1;
	int rt = 0;
	for (int i = 1; i <= m; i++) {
		int now = rt;
		if (i == flag)
			now = 2;
		for (int j = a[i].fir; j <= a[i].sec; j++) {
			cout << now << " ";
			now = tmp;
			tmp++;
		}
		rt = 1;
	}
	cout << el;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	cin >> T;
	while (T--) {
		solve();
	}
	return 0;
}

詳細信息

Test #1:

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

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 6 7 1 9 1 1 
0 1 1 1 
IMPOSSIBLE

result:

wrong answer 11's parent should be 10, but 1 found (test case 1)