QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#361110 | #6788. Heap Partition | Xiangmy | AC ✓ | 555ms | 8752kb | C++20 | 1.5kb | 2024-03-22 19:53:52 | 2024-03-22 19:53:53 |
Judging History
answer
/*
* Author: Xiangmy
* Created: 2024-03-22 16:47
* Problem:
* Description: stl 二分
* 题目告诉我们是一颗二叉树
*/
// #pragma GCC optimize(2)
// #pragma GCC optimize(3, "Ofast", "inline")
#include<bits/stdc++.h>
using namespace std;
#define debug(x) cerr << #x << ": " << (x) << ' '
// #define x first
// #define y second
typedef long long LL;
const int INF = 0x3f3f3f3f;
typedef pair<int, int> PII;
void solve() {
int n; cin >> n;
vector<vector<int>> ans;
multiset<PII> a; // 值,树的编号
for (int i = 1; i <= n; ++ i) {
int v; cin >> v;
auto x = a.lower_bound({v + 1, 0});
int id = 0;
if (x == a.begin()) {
id = ans.size();
ans.push_back({i});
} else {
x --;
id = x->second;
ans[id].push_back(i);
a.erase(x); // 减少一个子节点位置
}
a.insert({v, id}); // 两个子节点位置
a.insert({v, id});
}
cout << ans.size() << "\n";
for (auto i : ans) {
cout << i.size();
for (auto j : i) {
cout << ' ' << j;
}
cout << "\n";
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0); // 交互题不用
cout.tie(0);
// cout << fixed << setprecision(6);
// cout << setw(4) << setfill('0');
// init();
int T = 1;
cin >> T;
while (T -- ) {
// cin.ignore(numeric_limits<std::streamsize>::max(), '\n');
solve();
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3784kb
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: 555ms
memory: 8752kb
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