链表60分TLE 求调
查看原帖
链表60分TLE 求调
338144
tkth楼主2022/10/16 14:53
#include<iostream>
#include<cstring>
#include<cstdio>
#define ll long long
using namespace std;
const int Max = 1e5+1;
ll n;
struct s{
    ll prev,next,id;int num;
};
s node[Max*2];
ll head,tail,tot;
inline ll reAd(){
    short f = 1;ll num = 0;char c = getchar();
    while(c < '0'||c > '9'){
        if(c == '-')f=-1;
        c=getchar();
    }
    while(c >='0'&&c <='9'){
        num=(num<<3)+(num<<1)+c-'0';
        c=getchar();
    }
    return f*num;
}
inline void build(){
	tot = 2;
	head = 1;tail = 2;
	node[head].next = tail;
	node[tail].prev = head;
} 
inline void add(int x,int num,int id){
	int y = ++tot;
	node[y].num = num;
	node[y].id = id;
	node[node[x].next].prev = y;
	node[y].next = node[x].next;
	node[x].next = y;
	node[y].prev = x;
}
inline void date(int x){
	node[node[x].prev].next = node[x].next;
	node[node[x].next].prev = node[x].prev;
}
inline void clean(){
	memset(node,0,sizeof node);
	head = 0;tail = 0;tot = 0;
}
int main (){
    n = reAd();
	build();
	int hhead = head;
    for(int i = 1;i<= n;i++){
        bool x = reAd();
        add(hhead,x,i);
        hhead = node[hhead].next;
	}
	while(n>0){
		bool ff = !node[node[head].next].num;
		for(int i = node[head].next;i != tail;i=node[i].next){
			if(ff != node[i].num){
				ff = node[i].num;
				printf("%lld ",node[i].id);
				date(i);
				n--;
			}	
		}
		printf("\n");
	}
    return 0;
}

提交记录

2022/10/16 14:53
加载中...