#include #include using namespace std; struct Node{ unsigned long long value; int prev,next; }; int memory_cursor; int counter; Node *nil; Node list[200000]; void init(){ nil = &list[0]; nil->value = -1; nil->next = 0; nil->prev = 0; memory_cursor++; } void customInsert(int base,unsigned long long ins){ Node* add = &list[memory_cursor]; add-> value = ins; add-> next = list[base].next; add->prev = base; list[list[base].next].prev = memory_cursor; list[base].next = memory_cursor; memory_cursor++; counter++; } void insert(int ins){ customInsert(0,ins); } void sortedInsert(unsigned long long key){ Node* cur = &list[nil->next]; while(key < cur->value && cur!=nil) cur = &list[cur->next]; customInsert(cur->prev,key); } bool deleteNode(Node* del){ if (del==nil) return false; list[del->next].prev = del->prev; list[del->prev].next = del->next; counter--; return true; } bool deleteFirst(){ return deleteNode(&list[nil->next]); } void cleanup(){ while(deleteFirst()); } Node* searchNode(unsigned long long key){ Node* cur = &list[nil->next]; while(cur!=nil && cur->value!=key){ cur = &list[cur->next]; } return cur; } Node* bigger_from(int index){ if (index>=counter) return nil; int count=1; Node* cur = &list[nil->next]; while(countnext]; count++; } return cur; } Node* smaller_from(int index){ if (index>=counter) return nil; int count=0; Node* cur = &list[nil->prev]; while(countprev]; count++; } return cur; } void traceNode(){ Node* cur= &list[nil->next]; while(cur!=nil){ cout << cur->value << endl; cur = &list[cur->next]; } } signed main(){ init(); int q,k; scanf("%d %d",&q,&k); for (int i=0;ivalue); deleteNode(temp); } } cleanup(); return 0; }