80分求助
查看原帖
80分求助
709523
no19er楼主2024/9/11 22:07

话说不是三个最大的样例吗,其他八个都20ms-,只有两个T了

#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f,N=2e5+5;
int pc[N],pc0[N],n,s,x,x0,vis[N];
bool f;
void fin(int *z){
    char ch;
    bool f=0;
    int x=0;
    while(ch=getchar()){
        if(ch=='-')f=1;
        if(isdigit(ch))break;
    }while(isdigit(ch)){
        x=x*10+ch-'0';
        ch=getchar();
    }*z=x;if(f)*z=-*z;
}void fout(int x){
    if(x<0)putchar('-'),x=-x;
    if(x<=9)putchar(x+'0');
    else{
        fout(x/10);
        putchar(x%10+'0');
}}int main(){
	cin>>n>>x,x0=x;
	for(int i=1;i<n;i++){
		fin(&x);
		if(x0^x)
			x0=x,s++,
			pc[s]=pc0[s]=i;
	}pc0[s+1]=n;
	while(!f){
		f=1,x=2;
		for(int i=0;i<=s;i++){
			if(pc[i]==inf||x==i%2){
				if(!f&&x==2)x=(i+1)%2;
				continue;
			}f=0,x=2;
			while(pc[i]<pc0[i+1]&&vis[pc[i]])pc[i]++;
			vis[pc[i]]=1;
			fout(pc[i]+1);
			putchar(' ');
			if(pc[i]+1==pc0[i+1])pc[i]=inf;
		}putchar('\n');
	}return 0;
}
2024/9/11 22:07
加载中...