QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#576004#6788. Heap PartitionZhi_zIAC ✓644ms38168kbC++171.5kb2024-09-19 17:51:552024-09-19 17:52:02

Judging History

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

  • [2024-09-19 17:52:02]
  • 评测
  • 测评结果:AC
  • 用时:644ms
  • 内存:38168kb
  • [2024-09-19 17:51:55]
  • 提交

answer

// Problem: F - F
// Contest: Virtual Judge - 24-09-18-训练赛-23浙江省赛
// URL: https://vjudge.net/contest/656323#problem/F
// Memory Limit: 256 MB
// Time Limit: 3000 ms
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const long long N=1e6+10,mod=998244353,INF=1e15;
ll n,m,k,a[N],cnt;
bool st[N];
vector<int>p[N];
void solve()
{
	cin>>n;
	multiset<pii>s;
	for(int i=1;i<=cnt;i++)p[i].clear();
	cnt=0;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=1;i<=n;i++)
	{
		if(!s.size()||(s.begin()->first)>a[i])
		{
			cnt++;
			s.insert({a[i],cnt});
			s.insert({a[i],cnt});
			p[cnt].push_back(i);
			//cout<<i<<' '<<cnt<<endl;
		}
		else{
			auto it=s.begin();
			if(s.rbegin()->first<=a[i])it=--s.end();
			else 
			{
				it=s.lower_bound({a[i],0});
				//for(auto y:s)cout<<y.first<<'*'<<y.second<<endl;
				auto x=*it;
				//if(i==5)cout<<x.first<<' '<<a[i]<<' '<<x.second<<endl;
				if(x.first!=a[i])it--;
			}
			pii t=*it;
			//cout<<i<<' '<<t.second<<endl;
			s.erase(it);
			p[t.second].push_back(i);
			s.insert({a[i],t.second});
			s.insert({a[i],t.second});
		}
	}
	cout<<cnt<<endl;
	for(int i=1;i<=cnt;i++)
	{
		cout<<p[i].size()<<' ';
		for(auto x:p[i])cout<<x<<' ';cout<<endl;
	}
}
signed main()
{
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int T;cin>>T;
    while(T--)solve();
    return 0;
}

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

詳細信息

Test #1:

score: 100
Accepted
time: 2ms
memory: 29652kb

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: 644ms
memory: 38168kb

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...

result:

ok ok