fork 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. vector<int> nxt_len;
  11. vector<int> prv_len;
  12. node(int x):num(x){}
  13. } *begin,*end;
  14.  
  15. int size;
  16.  
  17. skip_list()
  18. {
  19. size=0;
  20. begin=new node(-INF);
  21. end =new node(+INF);
  22. begin->nxt={ end};
  23. end ->prv={begin};
  24. begin->nxt_len=end->prv_len={1};
  25. }
  26.  
  27. node *find(int x)
  28. {
  29. node *cur=begin;
  30. int cl=begin->nxt.size();
  31. while(cl>=0)
  32. {
  33. while(cl<cur->nxt.size() && cur->nxt[cl]->num<x)
  34. cur=cur->nxt[cl];
  35. cl--;
  36. }
  37. return cur->nxt[0];
  38. }
  39.  
  40. node *find_by_order(int x)
  41. {
  42. node *cur=begin;
  43. int cl=begin->nxt.size();
  44. int cx=-1;
  45. while(cl>=0)
  46. {
  47. while(cl<cur->nxt.size() && cx+cur->nxt_len[cl]<x)
  48. {
  49. cx+=cur->nxt_len[cl];
  50. cur=cur->nxt[cl];
  51. }
  52. cl--;
  53. }
  54. return cur->nxt[0];
  55. }
  56.  
  57. int order_of_key(int x)
  58. {
  59. {
  60. node *cur=begin;
  61. int cl=begin->nxt.size();
  62. int cx=0;
  63. while(cl>=0)
  64. {
  65. while(cl<cur->nxt.size() && cur->nxt[cl]->num<x)
  66. {
  67. cx+=cur->nxt_len[cl];
  68. cur=cur->nxt[cl];
  69. }
  70. cl--;
  71. }
  72. return cx;
  73. }
  74.  
  75. }
  76.  
  77. void insert(node *r,int x)
  78. {
  79. node *it=new node(x);
  80. int cl=0;
  81. int c_len=1;
  82. do
  83. {
  84. if(cl==begin->nxt.size())
  85. {
  86. begin->nxt.push_back(end);
  87. end ->prv.push_back(begin);
  88. begin->nxt_len.push_back(size+1);
  89. end ->prv_len.push_back(size+1);
  90. }
  91. while(cl==r->prv.size())
  92. {
  93. c_len+=r->nxt_len[cl-1];
  94. r=r->nxt[cl-1];
  95. }
  96. it->nxt.push_back(r);
  97. it->prv.push_back(r->prv[cl]);
  98. it->nxt_len.push_back(c_len);
  99. it->prv_len.push_back(r->prv_len[cl]-c_len+1);
  100. r->prv[cl]->nxt[cl]=it;
  101. r->prv[cl]->nxt_len[cl]=it->prv_len[cl];
  102. r->prv[cl]=it;
  103. r->prv_len[cl]=c_len;
  104. cl++;
  105. }
  106. while(rand()&1);
  107.  
  108. while(cl<begin->nxt.size())
  109. {
  110. while(cl==r->prv.size())
  111. r=r->nxt[cl-1];
  112. r->prv_len[cl]++;
  113. r->prv[cl]->nxt_len[cl]++;
  114. cl++;
  115. }
  116. size++;
  117. }
  118.  
  119. void insert(int x)
  120. {
  121. insert(find(x),x);
  122. }
  123.  
  124. void erase(node *it)
  125. {
  126. int cl=0;
  127. for(;cl<it->nxt.size();cl++)
  128. {
  129. it->nxt[cl]->prv_len[cl]=it->prv[cl]->nxt_len[cl]=it->prv_len[cl]+it->nxt_len[cl]-1;
  130. it->nxt[cl]->prv[cl]=it->prv[cl];
  131. it->prv[cl]->nxt[cl]=it->nxt[cl];
  132. }
  133. node *r=it->nxt[cl-1];
  134. for(;cl<begin->nxt.size();cl++)
  135. {
  136. while(cl==r->prv.size())
  137. r=r->nxt[cl-1];
  138. r->prv[cl]->nxt_len[cl]--;
  139. r->prv_len[cl]--;
  140. }
  141. delete it;
  142. size--;
  143. }
  144.  
  145. void erase(int x)
  146. {
  147. erase(find(x));
  148. }
  149. void erase_by_order(int x)
  150. {
  151. erase(find_by_order(x));
  152. }
  153.  
  154. int &at(int x)
  155. {
  156. return find_by_order(x)->num;
  157. }
  158. int &operator [](int x)
  159. {
  160. return at(x);
  161. }
  162. } me;
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:10:9: error: ‘vector’ does not name a type
         vector<int> nxt_len;
         ^
prog.cpp:11:9: error: ‘vector’ does not name a type
         vector<int> prv_len;
         ^
prog.cpp: In constructor ‘skip_list::skip_list()’:
prog.cpp:22:16: error: ‘struct skip_list::node’ has no member named ‘nxt’
         begin->nxt={  end};
                ^
prog.cpp:23:16: error: ‘struct skip_list::node’ has no member named ‘prv’
         end  ->prv={begin};
                ^
prog.cpp:24:16: error: ‘struct skip_list::node’ has no member named ‘nxt_len’
         begin->nxt_len=end->prv_len={1};
                ^
prog.cpp:24:29: error: ‘struct skip_list::node’ has no member named ‘prv_len’
         begin->nxt_len=end->prv_len={1};
                             ^
prog.cpp: In member function ‘skip_list::node* skip_list::find(int)’:
prog.cpp:30:23: error: ‘struct skip_list::node’ has no member named ‘nxt’
         int cl=begin->nxt.size();
                       ^
prog.cpp:33:27: error: ‘struct skip_list::node’ has no member named ‘nxt’
             while(cl<cur->nxt.size() && cur->nxt[cl]->num<x)
                           ^
prog.cpp:33:46: error: ‘struct skip_list::node’ has no member named ‘nxt’
             while(cl<cur->nxt.size() && cur->nxt[cl]->num<x)
                                              ^
prog.cpp:34:23: error: ‘struct skip_list::node’ has no member named ‘nxt’
              cur=cur->nxt[cl];
                       ^
prog.cpp:37:21: error: ‘struct skip_list::node’ has no member named ‘nxt’
         return cur->nxt[0];
                     ^
prog.cpp: In member function ‘skip_list::node* skip_list::find_by_order(int)’:
prog.cpp:43:23: error: ‘struct skip_list::node’ has no member named ‘nxt’
         int cl=begin->nxt.size();
                       ^
prog.cpp:47:27: error: ‘struct skip_list::node’ has no member named ‘nxt’
             while(cl<cur->nxt.size() && cx+cur->nxt_len[cl]<x)
                           ^
prog.cpp:47:49: error: ‘struct skip_list::node’ has no member named ‘nxt_len’
             while(cl<cur->nxt.size() && cx+cur->nxt_len[cl]<x)
                                                 ^
prog.cpp:49:26: error: ‘struct skip_list::node’ has no member named ‘nxt_len’
                 cx+=cur->nxt_len[cl];
                          ^
prog.cpp:50:26: error: ‘struct skip_list::node’ has no member named ‘nxt’
                 cur=cur->nxt[cl];
                          ^
prog.cpp:54:21: error: ‘struct skip_list::node’ has no member named ‘nxt’
         return cur->nxt[0];
                     ^
prog.cpp: In member function ‘int skip_list::order_of_key(int)’:
prog.cpp:61:23: error: ‘struct skip_list::node’ has no member named ‘nxt’
         int cl=begin->nxt.size();
                       ^
prog.cpp:65:27: error: ‘struct skip_list::node’ has no member named ‘nxt’
             while(cl<cur->nxt.size() && cur->nxt[cl]->num<x)
                           ^
prog.cpp:65:46: error: ‘struct skip_list::node’ has no member named ‘nxt’
             while(cl<cur->nxt.size() && cur->nxt[cl]->num<x)
                                              ^
prog.cpp:67:26: error: ‘struct skip_list::node’ has no member named ‘nxt_len’
                 cx+=cur->nxt_len[cl];
                          ^
prog.cpp:68:26: error: ‘struct skip_list::node’ has no member named ‘nxt’
                 cur=cur->nxt[cl];
                          ^
prog.cpp: In member function ‘void skip_list::insert(skip_list::node*, int)’:
prog.cpp:84:27: error: ‘struct skip_list::node’ has no member named ‘nxt’
             if(cl==begin->nxt.size())
                           ^
prog.cpp:86:24: error: ‘struct skip_list::node’ has no member named ‘nxt’
                 begin->nxt.push_back(end);
                        ^
prog.cpp:87:24: error: ‘struct skip_list::node’ has no member named ‘prv’
                 end  ->prv.push_back(begin);
                        ^
prog.cpp:88:24: error: ‘struct skip_list::node’ has no member named ‘nxt_len’
                 begin->nxt_len.push_back(size+1);
                        ^
prog.cpp:89:24: error: ‘struct skip_list::node’ has no member named ‘prv_len’
                 end  ->prv_len.push_back(size+1);
                        ^
prog.cpp:91:26: error: ‘struct skip_list::node’ has no member named ‘prv’
             while(cl==r->prv.size())
                          ^
prog.cpp:93:27: error: ‘struct skip_list::node’ has no member named ‘nxt_len’
                 c_len+=r->nxt_len[cl-1];
                           ^
prog.cpp:94:22: error: ‘struct skip_list::node’ has no member named ‘nxt’
                 r=r->nxt[cl-1];
                      ^
prog.cpp:96:17: error: ‘struct skip_list::node’ has no member named ‘nxt’
             it->nxt.push_back(r);
                 ^
prog.cpp:97:17: error: ‘struct skip_list::node’ has no member named ‘prv’
             it->prv.push_back(r->prv[cl]);
                 ^
prog.cpp:97:34: error: ‘struct skip_list::node’ has no member named ‘prv’
             it->prv.push_back(r->prv[cl]);
                                  ^
prog.cpp:98:17: error: ‘struct skip_list::node’ has no member named ‘nxt_len’
             it->nxt_len.push_back(c_len);
                 ^
prog.cpp:99:17: error: ‘struct skip_list::node’ has no member named ‘prv_len’
             it->prv_len.push_back(r->prv_len[cl]-c_len+1);
                 ^
prog.cpp:99:38: error: ‘struct skip_list::node’ has no member named ‘prv_len’
             it->prv_len.push_back(r->prv_len[cl]-c_len+1);
                                      ^
prog.cpp:100:16: error: ‘struct skip_list::node’ has no member named ‘prv’
             r->prv[cl]->nxt[cl]=it;
                ^
prog.cpp:101:16: error: ‘struct skip_list::node’ has no member named ‘prv’
             r->prv[cl]->nxt_len[cl]=it->prv_len[cl];
                ^
prog.cpp:101:41: error: ‘struct skip_list::node’ has no member named ‘prv_len’
             r->prv[cl]->nxt_len[cl]=it->prv_len[cl];
                                         ^
prog.cpp:102:16: error: ‘struct skip_list::node’ has no member named ‘prv’
             r->prv[cl]=it;
                ^
prog.cpp:103:16: error: ‘struct skip_list::node’ has no member named ‘prv_len’
             r->prv_len[cl]=c_len;
                ^
prog.cpp:106:20: error: ‘rand’ was not declared in this scope
         while(rand()&1);
                    ^
prog.cpp:108:25: error: ‘struct skip_list::node’ has no member named ‘nxt’
         while(cl<begin->nxt.size())
                         ^
prog.cpp:110:26: error: ‘struct skip_list::node’ has no member named ‘prv’
             while(cl==r->prv.size())
                          ^
prog.cpp:111:22: error: ‘struct skip_list::node’ has no member named ‘nxt’
                 r=r->nxt[cl-1];
                      ^
prog.cpp:112:16: error: ‘struct skip_list::node’ has no member named ‘prv_len’
             r->prv_len[cl]++;
                ^
prog.cpp:113:16: error: ‘struct skip_list::node’ has no member named ‘prv’
             r->prv[cl]->nxt_len[cl]++;
                ^
prog.cpp: In member function ‘void skip_list::erase(skip_list::node*)’:
prog.cpp:127:21: error: ‘struct skip_list::node’ has no member named ‘nxt’
         for(;cl<it->nxt.size();cl++)
                     ^
prog.cpp:129:17: error: ‘struct skip_list::node’ has no member named ‘nxt’
             it->nxt[cl]->prv_len[cl]=it->prv[cl]->nxt_len[cl]=it->prv_len[cl]+it->nxt_len[cl]-1;
                 ^
prog.cpp:129:42: error: ‘struct skip_list::node’ has no member named ‘prv’
             it->nxt[cl]->prv_len[cl]=it->prv[cl]->nxt_len[cl]=it->prv_len[cl]+it->nxt_len[cl]-1;
                                          ^
prog.cpp:129:67: error: ‘struct skip_list::node’ has no member named ‘prv_len’
             it->nxt[cl]->prv_len[cl]=it->prv[cl]->nxt_len[cl]=it->prv_len[cl]+it->nxt_len[cl]-1;
                                                                   ^
prog.cpp:129:83: error: ‘struct skip_list::node’ has no member named ‘nxt_len’
             it->nxt[cl]->prv_len[cl]=it->prv[cl]->nxt_len[cl]=it->prv_len[cl]+it->nxt_len[cl]-1;
                                                                                   ^
prog.cpp:130:17: error: ‘struct skip_list::node’ has no member named ‘nxt’
             it->nxt[cl]->prv[cl]=it->prv[cl];
                 ^
prog.cpp:130:38: error: ‘struct skip_list::node’ has no member named ‘prv’
             it->nxt[cl]->prv[cl]=it->prv[cl];
                                      ^
prog.cpp:131:17: error: ‘struct skip_list::node’ has no member named ‘prv’
             it->prv[cl]->nxt[cl]=it->nxt[cl];
                 ^
prog.cpp:131:38: error: ‘struct skip_list::node’ has no member named ‘nxt’
             it->prv[cl]->nxt[cl]=it->nxt[cl];
                                      ^
prog.cpp:133:21: error: ‘struct skip_list::node’ has no member named ‘nxt’
         node *r=it->nxt[cl-1];
                     ^
prog.cpp:134:24: error: ‘struct skip_list::node’ has no member named ‘nxt’
         for(;cl<begin->nxt.size();cl++)
                        ^
prog.cpp:136:26: error: ‘struct skip_list::node’ has no member named ‘prv’
             while(cl==r->prv.size())
                          ^
prog.cpp:137:22: error: ‘struct skip_list::node’ has no member named ‘nxt’
                 r=r->nxt[cl-1];
                      ^
prog.cpp:138:16: error: ‘struct skip_list::node’ has no member named ‘prv’
             r->prv[cl]->nxt_len[cl]--;
                ^
prog.cpp:139:16: error: ‘struct skip_list::node’ has no member named ‘prv_len’
             r->prv_len[cl]--;
                ^
stdout
Standard output is empty