有隐蔽错误
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
int n;
struct tNode {
int prv,nxt;
int left, right;
int d;
} nodes[200005];
bool vis[200005];
int lstnode,head,tail;
int main() {
head = 1;
tail = 2;
lstnode = 3;
nodes[head].left = nodes[head].right = 0;
nodes[tail].left = nodes[tail].right = 0;
nodes[head].nxt = tail;
nodes[head].prv = -1;
nodes[tail].prv = head;
nodes[tail].nxt = -1;
nodes[head].d = 7;
nodes[tail].d = 8;
int last=7;
scanf("%d",&n);
int p=0;
for(int i=1; i<=n; i++) {
int data;
scanf("%d",&data);
if(last != data) {
p = lstnode++;
nodes[p].d = data;
nodes[p].left = i;
nodes[p].right = i;
nodes[p].nxt = tail;
nodes[p].prv = nodes[tail].prv;
nodes[tail].prv = p;
nodes[nodes[p].prv].nxt = p;
last = data;
} else {
nodes[p].right = i;
}
}
for(; nodes[head].nxt != tail; ) {
last = 7;
for( p=nodes[head].nxt; p!=tail; p=nodes[p].nxt) {
if(last != nodes[p].d) {
for(; vis[nodes[p].left] == true; ) nodes[p].left++;
printf("%d ",nodes[p].left);
vis[nodes[p].left] = true;
if(nodes[p].left == nodes[p].right) {
nodes[nodes[p].prv].nxt = nodes[p].nxt;
nodes[nodes[p].nxt].prv = nodes[p].prv;
} else {
nodes[p].left++;
}
last = nodes[p].d;
} else {
int pp = nodes[p].prv;
nodes[pp].right = nodes[p].right;
nodes[pp].nxt = nodes[p].nxt;
nodes[nodes[p].nxt].prv = pp;
}
}
printf("\n");
}
return 0;
}