QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#361038 | #6788. Heap Partition | Xiangmy | WA | 160ms | 4504kb | C++20 | 1.5kb | 2024-03-22 18:23:27 | 2024-03-22 18:23:28 |
Judging History
answer
/*
* Author: Xiangmy
* Created: 2024-03-22 16:47
* Problem:
* Description:
*/
// #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<int> a(n + 1);
map<int, vector<int>> mp;
for (int i = 1; i <= n; ++ i) cin >> a[i];
mp[a[1]].push_back(1);
set<int> st; st.insert(a[1]);
for (int i = 2; i <= n; ++ i) {
auto x = st.upper_bound(a[i]);
if (x == st.begin()) {
mp[a[i]].push_back(i);
st.insert(a[i]);
} else {
-- x;
mp[*x].push_back(i);
}
}
cout << mp.size() << "\n";
for (int i = 1; i <= n; ++ i) {
if (mp.count(i)) {
cout << mp[i].size();
for (auto x : mp[i]) {
cout << ' ' << x;
}
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3644kb
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 1 4 3 1 2 3 1 4 1 2 3 4 3 2 3 5 1 2 2 1 4
result:
ok ok
Test #2:
score: -100
Wrong Answer
time: 160ms
memory: 4504kb
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 2 1 1 1 2 1 2 1 2 1 2 1 3 1 2 3 2 2 2 3 1 1 2 2 2 3 1 1 1 3 1 2 3 2 1 3 2 1 2 3 1 3 1 2 1 1 1 3 1 2 3 2 1 3 2 1 2 2 1 3 2 1 2 1 3 1 2 3 2 1 2 2 1 3 2 2 2 3 1 1 1 3 1 2 3 1 3 1 2 3 2 2 2 3 1 1 1 3 1 2 3 1 3 1 2 3 2 1 3 2 1 2 1 3 1 2 3 2 1 2 2 1 3 2 1 2 2 1 3 1 3 1 2 3 1 3 1 2 3 2 1 ...
result:
wrong answer the 1-th sequence on case 57 is not heapable.