QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#377416 | #6788. Heap Partition | Zhou_JK | AC ✓ | 508ms | 19572kb | C++23 | 1.5kb | 2024-04-05 13:23:52 | 2024-04-05 13:23:53 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
const int N=100005;
int n;
int a[N];
vector<int>pos[N];
int fa[N],cnt[N];
set<int>s;
vector<int>G[N];
vector<int>p;
void dfs(int u)
{
p.emplace_back(u);
for(int v:G[u])
dfs(v);
return;
}
void solve()
{
cin>>n;
for(int i=1;i<=n;i++)
cin>>a[i];
for(int i=1;i<=n;i++)
pos[i].clear(),G[i].clear();
for(int i=1;i<=n;i++)
pos[a[i]].emplace_back(i);
s.clear();
for(int i=1;i<=n;i++)
{
for(int u:pos[i])
{
auto it=s.upper_bound(u);
if(it==s.begin()) fa[u]=0;
else
{
int f=*prev(it);
fa[u]=f;
G[f].emplace_back(u);
cnt[f]++;
if(cnt[f]>=2) s.erase(s.find(f));
}
cnt[u]=0;
s.insert(u);
}
}
vector<vector<int>>res;
for(int i=1;i<=n;i++)
if(!fa[i])
{
p.clear();
dfs(i);
res.emplace_back(p);
}
int m=res.size();
cout<<m<<"\n";
for(auto &p:res)
{
sort(p.begin(),p.end());
int c=p.size();
cout<<c;
for(int u:p)
cout<<" "<<u;
cout<<"\n";
}
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr),cout.tie(nullptr);
int T;
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: 5600kb
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 1 1 1 2 3 3 4 5
result:
ok ok
Test #2:
score: 0
Accepted
time: 508ms
memory: 19572kb
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 1 1 2 2 3 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 1 1 2 2 3 2 1 1 2 2 3 1 3 1 2 3 1 3 1 2 3 2 1 ...
result:
ok ok