QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#321432#6788. Heap PartitionieeAC ✓655ms8744kbC++17688b2024-02-04 18:11:162024-02-04 18:11:17

Judging History

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

  • [2024-02-04 18:11:17]
  • 评测
  • 测评结果:AC
  • 用时:655ms
  • 内存:8744kb
  • [2024-02-04 18:11:16]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int main() {
	cin.tie(0)->sync_with_stdio(0);
	int t;
	cin >> t;
	while (t--) {
		int n;
		cin >> n;
		vector<vector<int>> r;
		multiset<pair<int, int>> s;
		for (int i = 0, x; i < n; i++) {
			cin >> x;
			auto it = s.lower_bound({x + 1, -1});
			int id;
			if (it == s.begin()) {
				id = r.size(), r.push_back({i});
			} else {
				it--, id = it->second;
				r[id].push_back(i);
				s.erase(it);
			}
			s.insert({x, id}), s.insert({x, id});
		}
		cout << r.size() << "\n";
		for (auto v : r) {
			cout << v.size();
			for (int &i : v) {
				cout << " " << i + 1;
			}
			cout << "\n";
		}
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3640kb

input:

4
4
1 2 3 4
4
2 4 3 1
4
1 1 1 1
5
3 2 1 4 1

output:

1
4 1 2 3 4
2
3 1 2 3
1 4
1
4 1 2 3 4
3
2 1 4
1 2
2 3 5

result:

ok ok

Test #2:

score: 0
Accepted
time: 655ms
memory: 8744kb

input:

72284
1
1
2
1 1
2
2 1
2
1 2
2
2 2
3
1 1 1
3
2 1 1
3
3 1 1
3
1 2 1
3
2 2 1
3
3 2 1
3
1 3 1
3
2 3 1
3
3 3 1
3
1 1 2
3
2 1 2
3
3 1 2
3
1 2 2
3
2 2 2
3
3 2 2
3
1 3 2
3
2 3 2
3
3 3 2
3
1 1 3
3
2 1 3
3
3 1 3
3
1 2 3
3
2 2 3
3
3 2 3
3
1 3 3
3
2 3 3
3
3 3 3
4
1 1 1 1
4
2 1 1 1
4
3 1 1 1
4
4 1 1 1
4
1 2 1 1
...

output:

1
1 1
1
2 1 2
2
1 1
1 2
1
2 1 2
1
2 1 2
1
3 1 2 3
2
1 1
2 2 3
2
1 1
2 2 3
1
3 1 2 3
2
2 1 2
1 3
3
1 1
1 2
1 3
1
3 1 2 3
2
2 1 2
1 3
2
2 1 2
1 3
1
3 1 2 3
2
2 1 3
1 2
2
1 1
2 2 3
1
3 1 2 3
1
3 1 2 3
2
1 1
2 2 3
1
3 1 2 3
1
3 1 2 3
2
2 1 2
1 3
1
3 1 2 3
2
2 1 3
1 2
2
2 1 3
1 2
1
3 1 2 3
1
3 1 2 3
2
2 ...

result:

ok ok