QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#184123#6788. Heap Partitionucup-team004#AC ✓560ms8920kbC++201021b2023-09-20 13:18:592023-09-20 13:18:59

Judging History

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

  • [2023-09-20 13:18:59]
  • 评测
  • 测评结果:AC
  • 用时:560ms
  • 内存:8920kb
  • [2023-09-20 13:18:59]
  • 提交

answer

#include <bits/stdc++.h>

using i64 = long long;

void solve() {
    int n;
    std::cin >> n;
    
    std::vector<std::vector<int>> ans;
    std::multiset<std::pair<int, int>> a;
    for (int i = 1; i <= n; i++) {
        int s;
        std::cin >> s;
        auto it = a.lower_bound({s + 1, 0});
        int x;
        if (it == a.begin()) {
            x = ans.size();
            ans.push_back({i});
        } else {
            it--;
            x = it->second;
            ans[x].push_back(i);
            a.erase(it);
        }
        a.emplace(s, x);
        a.emplace(s, x);
    }
    std::cout << ans.size() << "\n";
    for (auto v : ans) {
        std::cout << v.size();
        for (auto i : v) {
            std::cout << " " << i;
        }
        std::cout << "\n";
    }
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int t;
    std::cin >> t;
    
    while (t--) {
        solve();
    }
    
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3508kb

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: 560ms
memory: 8920kb

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