QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#361110#6788. Heap PartitionXiangmyAC ✓555ms8752kbC++201.5kb2024-03-22 19:53:522024-03-22 19:53:53

Judging History

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

  • [2024-03-22 19:53:53]
  • 评测
  • 测评结果:AC
  • 用时:555ms
  • 内存:8752kb
  • [2024-03-22 19:53:52]
  • 提交

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,我给组数据试试?

详细

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