QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#587887 | #6788. Heap Partition | piggy123# | WA | 174ms | 63404kb | C++20 | 3.4kb | 2024-09-24 22:16:06 | 2024-09-24 22:16:07 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a[200005],st[21][200005],st2[21][200005];
ll getmip(ll l,ll r){
ll k=log2(r-l+1);
return (st[k][l]<=st[k][r-(1ll<<k)+1]?st2[k][l]:st2[k][r-(1ll<<k)+1]);
}
int main(){
cin.tie(0);cout.tie(0);
ios::sync_with_stdio(false);
ll t;
cin >> t;
while (t--){
ll n;
cin >> n;
for (ll i=1;i<=n;i++){
cin >> a[i];
st[0][i]=a[i],st2[0][i]=i;
}
for (ll i=1;i<=19;i++){
for (ll j=1;j+(1ll<<i)-1<=n;j++){
st[i][j]=min(st[i-1][j],st[i-1][j+(1ll<<(i-1))]);
if (st[i-1][j]<=st[i-1][j+(1ll<<(i-1))]){
st2[i][j]=st2[i-1][j];
}else{
st2[i][j]=st2[i-1][j+(1ll<<(i-1))];
}
// cout<<i<<","<<j<<":"<<st2[i][j]<<" "<< st[i][j]<<"\n";
}
}
ll nr=n;
vector<vector<ll>> vv;
while (nr>=1){
ll pp=getmip(1,nr);
// cout<<pp<< "\n";
vector<ll> vv2;
for (ll j=pp;j<=nr;j++){
vv2.push_back(j);
}
vv.push_back(vv2);
nr=pp-1;
}
cout<< vv.size()<<"\n";
for (auto i:vv){
cout<<i.size()<<" ";
for (auto j:i)cout<<j<<" ";
cout<<"\n";
}
}
return 0;
}
/*
■■■■■ ■■ ■■■ ■■■ ■ ■ ■ ■■■■ ■■■■
■ ■■ ■■ ■ ■■ ■ ■■ ■ ■ ■■ ■ ■■ ■■ ■
■ ■ ■■ ■ ■ ■ ■ ■ ■ ■■■ ■■ ■■ ■ ■■
■ ■ ■■ ■ ■ ■ ■ ■ ■ ■■ ■ ■■ ■■
■ ■ ■■ ■ ■ ■■ ■■ ■■ ■
■ ■■ ■■ ■ ■■■ ■ ■■■ ■■ ■■ ■■ ■■■
■■■■■ ■■ ■ ■ ■ ■ ■■ ■■ ■■ ■■
■ ■■ ■ ■ ■ ■ ■■ ■■ ■■ ■
■ ■■ ■ ■ ■ ■ ■■ ■■ ■ ■ ■■
■ ■■ ■■ ■■ ■■ ■■ ■■ ■■ ■ ■■ ■■
■ ■■ ■■■■ ■■■■ ■■ ■■ ■■■■■■ ■■■■
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 16172kb
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 3 3 4 5 1 2 1 1
result:
ok ok
Test #2:
score: -100
Wrong Answer
time: 174ms
memory: 63404kb
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 2 2 3 1 1 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 2 2 3 1 1...
result:
wrong answer the 1-th sequence on case 57 is not heapable.