TLE 80pts求调 玄关
  • 板块灌水区
  • 楼主_0o0_
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/8/7 16:02
  • 上次更新2024/8/7 16:40:52
查看原帖
TLE 80pts求调 玄关
671610
_0o0_楼主2024/8/7 16:02

TLE#8#9

P7912

#include<bits/stdc++.h>
using namespace std;
const int N=200010;
int n;
int a[N];
queue<int>p[2][100001];
int tot[2];
int main()
{
	a[0]=-1;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]!=a[i-1])
		{
			tot[a[i]]++;
		}
		p[a[i]][tot[a[i]]].push(i);
	}
	while(n)
	{
		bool flag=true;
		int str=1,now=a[1],last=0,k=0;
		while(str<=tot[now])
		{
			if(p[now][str].empty())
			{
				if(flag)
				{
					int tmp=last;
					last=str;
					str=tmp+1;
					now^=1;
				}
				else
				{
					str++;
					k++;
				}
			}
			else
			{
				flag=false;
				printf("%d ",p[now][str].front());
				p[now][str].pop();
				now^=1;
				int tmp=last;
				last=str;
				str=tmp+k+1;
				k=0;
				n--;
			}
		}
		printf("\n");
	}
	return 0;
}
2024/8/7 16:02
加载中...