fork(6) download
  1. const int INF=2e9;
  2.  
  3. struct skip_list
  4. {
  5. struct node
  6. {
  7. int num;
  8. vector<node*> nxt;
  9. vector<node*> prv;
  10. node(int x):num(x){}
  11. } *begin,*end;
  12.  
  13. skip_list()
  14. {
  15. begin=new node(-INF);
  16. end =new node(+INF);
  17. begin->nxt={ end};
  18. begin->prv={ 0};
  19. end ->nxt={ 0};
  20. end ->prv={begin};
  21. }
  22.  
  23. node *find(int x)
  24. {
  25. node *cur=begin;
  26. int cl=begin->nxt.size();
  27. while(cl>=0)
  28. {
  29. while(cl<cur->nxt.size() && cur->nxt[cl]->num<x) cur=cur->nxt[cl];
  30. cl--;
  31. }
  32. return cur->nxt[0];
  33. }
  34. void insert(int x)
  35. {
  36. node *r=find(x);
  37. node *l=r->prv[0];
  38. node *it=new node(x);
  39. int cl=-1;
  40. while(cl==-1 || rand()%2)
  41. {
  42. cl++;
  43. if(cl>=begin->nxt.size())
  44. {
  45. begin->nxt.push_back(0);begin->prv.push_back(0);
  46. end ->nxt.push_back(0);end ->prv.push_back(0);
  47. }
  48. while(cl>=l->nxt.size()) l=l->prv[cl-1];
  49. while(cl>=r->nxt.size()) r=r->nxt[cl-1];
  50. l->nxt[cl]=it;
  51. r->prv[cl]=it;
  52. it->nxt.push_back(r);
  53. it->prv.push_back(l);
  54. }
  55.  
  56. }
  57.  
  58. void erase(int x)
  59. {
  60. node *it=find(x);
  61. for(int i=0;i<it->nxt.size();i++)
  62. {
  63. it->nxt[i]->prv[i]=it->prv[i];
  64. it->prv[i]->nxt[i]=it->nxt[i];
  65. }
  66. delete it;
  67. }
  68. } me;
  69.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:8:9: error: ‘vector’ does not name a type
         vector<node*> nxt;
         ^
prog.cpp:9:9: error: ‘vector’ does not name a type
         vector<node*> prv;
         ^
prog.cpp: In constructor ‘skip_list::skip_list()’:
prog.cpp:17:16: error: ‘struct skip_list::node’ has no member named ‘nxt’
         begin->nxt={  end};
                ^
prog.cpp:18:16: error: ‘struct skip_list::node’ has no member named ‘prv’
         begin->prv={    0};
                ^
prog.cpp:19:16: error: ‘struct skip_list::node’ has no member named ‘nxt’
         end  ->nxt={    0};
                ^
prog.cpp:20:16: error: ‘struct skip_list::node’ has no member named ‘prv’
         end  ->prv={begin};
                ^
prog.cpp: In member function ‘skip_list::node* skip_list::find(int)’:
prog.cpp:26:23: error: ‘struct skip_list::node’ has no member named ‘nxt’
         int cl=begin->nxt.size();
                       ^
prog.cpp:29:27: error: ‘struct skip_list::node’ has no member named ‘nxt’
             while(cl<cur->nxt.size() && cur->nxt[cl]->num<x) cur=cur->nxt[cl];
                           ^
prog.cpp:29:46: error: ‘struct skip_list::node’ has no member named ‘nxt’
             while(cl<cur->nxt.size() && cur->nxt[cl]->num<x) cur=cur->nxt[cl];
                                              ^
prog.cpp:29:71: error: ‘struct skip_list::node’ has no member named ‘nxt’
             while(cl<cur->nxt.size() && cur->nxt[cl]->num<x) cur=cur->nxt[cl];
                                                                       ^
prog.cpp:32:21: error: ‘struct skip_list::node’ has no member named ‘nxt’
         return cur->nxt[0];
                     ^
prog.cpp: In member function ‘void skip_list::insert(int)’:
prog.cpp:37:20: error: ‘struct skip_list::node’ has no member named ‘prv’
         node *l=r->prv[0];
                    ^
prog.cpp:40:30: error: ‘rand’ was not declared in this scope
         while(cl==-1 || rand()%2)
                              ^
prog.cpp:43:27: error: ‘struct skip_list::node’ has no member named ‘nxt’
             if(cl>=begin->nxt.size())
                           ^
prog.cpp:45:24: error: ‘struct skip_list::node’ has no member named ‘nxt’
                 begin->nxt.push_back(0);begin->prv.push_back(0);
                        ^
prog.cpp:45:48: error: ‘struct skip_list::node’ has no member named ‘prv’
                 begin->nxt.push_back(0);begin->prv.push_back(0);
                                                ^
prog.cpp:46:24: error: ‘struct skip_list::node’ has no member named ‘nxt’
                 end  ->nxt.push_back(0);end  ->prv.push_back(0);
                        ^
prog.cpp:46:48: error: ‘struct skip_list::node’ has no member named ‘prv’
                 end  ->nxt.push_back(0);end  ->prv.push_back(0);
                                                ^
prog.cpp:48:26: error: ‘struct skip_list::node’ has no member named ‘nxt’
             while(cl>=l->nxt.size())  l=l->prv[cl-1];
                          ^
prog.cpp:48:44: error: ‘struct skip_list::node’ has no member named ‘prv’
             while(cl>=l->nxt.size())  l=l->prv[cl-1];
                                            ^
prog.cpp:49:26: error: ‘struct skip_list::node’ has no member named ‘nxt’
             while(cl>=r->nxt.size())  r=r->nxt[cl-1];
                          ^
prog.cpp:49:44: error: ‘struct skip_list::node’ has no member named ‘nxt’
             while(cl>=r->nxt.size())  r=r->nxt[cl-1];
                                            ^
prog.cpp:50:16: error: ‘struct skip_list::node’ has no member named ‘nxt’
             l->nxt[cl]=it;
                ^
prog.cpp:51:16: error: ‘struct skip_list::node’ has no member named ‘prv’
             r->prv[cl]=it;
                ^
prog.cpp:52:17: error: ‘struct skip_list::node’ has no member named ‘nxt’
             it->nxt.push_back(r);
                 ^
prog.cpp:53:17: error: ‘struct skip_list::node’ has no member named ‘prv’
             it->prv.push_back(l);
                 ^
prog.cpp: In member function ‘void skip_list::erase(int)’:
prog.cpp:61:27: error: ‘struct skip_list::node’ has no member named ‘nxt’
         for(int i=0;i<it->nxt.size();i++)
                           ^
prog.cpp:63:17: error: ‘struct skip_list::node’ has no member named ‘nxt’
             it->nxt[i]->prv[i]=it->prv[i];
                 ^
prog.cpp:63:36: error: ‘struct skip_list::node’ has no member named ‘prv’
             it->nxt[i]->prv[i]=it->prv[i];
                                    ^
prog.cpp:64:17: error: ‘struct skip_list::node’ has no member named ‘prv’
             it->prv[i]->nxt[i]=it->nxt[i];
                 ^
prog.cpp:64:36: error: ‘struct skip_list::node’ has no member named ‘nxt’
             it->prv[i]->nxt[i]=it->nxt[i];
                                    ^
prog.cpp: In member function ‘int skip_list::count(int)’:
prog.cpp:76:20: error: ‘struct skip_list::node’ has no member named ‘nxt’
             it=it->nxt[0];
                    ^
stdout
Standard output is empty