void dpri(int64 u) { ff(debug,"Node %d:\n",u); int64 son = 0; TRA(x,u) ff(debug,"SON%d: %d\n",++son,lk[x].v); TRA(x,u) dpri(lk[x].v); }
int main() { node *head; head = (node *) malloc (sizeof(node)); char choice[4]; int position, pos1, pos2, caso=0; if (!head) exit(1); start(head); while (scanf(" %s", choice)!=EOF) { if(strcmp(choice, "ADD")==0) { add_data(head); } else if (strcmp(choice, "DEL") == 0) { node_deleter(head); } else if (strcmp(choice, "TRA") == 0) { TRA(head); } else if (strcmp(choice, "SPL") == 0) { scanf("%d", &position); split_master(head, position); } else if (strcmp(choice, "MER") == 0) { scanf("%d %d", &pos1, &pos2); if(pos1!=pos2) { node *head2 = (node *) malloc(sizeof(node)); head2 = merge(head, pos2); merge_master(head, head2->next, pos1); update_tra(head, pos1); if (pos2 == 0) head = merge_node_deleter_head(head); else if (pos2>pos1) merge_node_deleter_pos2(head, head2, pos2); else if (pos1>pos2) merge_node_deleter_pos1(head, pos1); free(head2); } } else if (strcmp(choice, "END") == 0) { printf("caso %d: ", caso); finish_him(head); node *novohead = (node *) malloc(sizeof(node)); if(!novohead) exit(1); head = novohead; start(head); caso++; } } printf("\n"); return 0; }
int main(int argc, char *argv[]) { setIO("sample");CLEAR(st,0xff); n = gi; for(int i = 1;i<=n;fa[i]=i,++i) a[i] = gi,b[i] = a[i]; sort(b+1,b+1+n); int l = unique(b+1,b+1+n)-b-1; for(int i = 1;i<=n;++i) a[i] = lower_bound(b+1,b+l+1,a[i])-b; a[0] = -INF,a[n+1] = -INF; for(int i = 0;i<=n+1;++i) { while(top && a[stk[top]]>a[i]) rm[stk[top]]=i,--top; ++top;stk[top] = i; } top = 0; for(int i = n+1;i>=0;--i) { while(top && a[stk[top]]>a[i]) lm[stk[top]]=i, --top; ++top;stk[top] = i; } top = 0; for(int i = 1;i<=n;++i) add(lm[i]+1,rm[i]-1,0,i); for(int i = 1;i<=n;++i){ while(top && a[stk[top]] <= a[i]) unions(i,stk[top]),--top; ++top; stk[top] = i; TRA(x,i) ans[lk[x].w] = a[gf(lk[x].v)]; } for(int i = 1;i<=n;++i) printf(i==1?"%d":" %d",b[ans[i]]-b[a[i]]); puts(" "); closeIO(); return EXIT_SUCCESS; }