Submission #683368

#TimeUsernameProblemLanguageResultExecution timeMemory
683368Tenis0206Abracadabra (CEOI22_abracadabra)C++11
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; struct queries { int t,poz,cnt; }; struct Node { Node *st, *dr; int prior, sz; int val, Min; }; Node *modfiu(Node *nod, bool care, Node *son) { if(care==0) { nod -> st = son; } else { nod -> dr = son; } nod -> sz = nod -> st -> sz + 1 + nod -> dr -> sz; nod -> Min = nod -> val; nod -> Min = min(nod -> Min, nod->st->Min); nod -> Min = min(nod -> Min, nod->dr->Min); return nod; } Node *join(Node *st, Node *dr, bool care) { if(st==&nil[care]) { return dr; } if(dr==&nil[care]) { return st; } if(st->prior >= dr->prior) { return modfiu(st,1,join(st->dr,dr,care)); } else { return modfiu(dr,0,join(st,dr->st,care)); } } pair<Node*,Node*> split(Node *nod, int k, bool care) { if(nod==&nil[care]) { return {&nil[care],&nil[care]}; } if(nod->st->sz>=k) { auto t = split(nod->st,k,care); return {t.first,modfiu(nod,0,t.second)}; } else { auto t = split(nod->dr,k - nod->st->sz - 1,care); return {modfiu(nod,1,t.first),t.second}; } } int get_cnt_first(Node *nod, bool care) { if(nod->st == &nil[care]) { return nod -> sz; } return get_cnt_first(nod->st,care); } int query(int poz) { auto t = split(T,poz-1,0); auto t2 = split(t,1,0); int val = t2.first -> val; T = join(t.first,join(t2.first,t2.second,0),0); return val; } bool next_perm() { auto t = split(I,n/2,1); int cnt = get_cnt_first(t.second,1); auto t2 = split(t.second,cnt,1); t2.first -> sz = n / 2 - t.first -> sz; I = join(t.first,join(t2.first,t2.second,1),1); } int main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>m; for(int i=1; i<=n; i++) { cin>>v[i]; } for(int i=1; i<=m; i++) { cin>>q[i].t>>q[i].poz; q[i].cnt = i; } auto cmp = [](queries a, queries b) { return a.t < b.t; }; sort(q+1,q+m+1,cmp); int first = v[1]; int nr = 0; for(int i=1; i<=n; i++) { if(v[i] > first || i == n / 2 + 1) { if(i!=1) { I = join(I,new Node{&nil[1],&nil[1],my_rand(),nr,first,0},1); } first = v[i]; nr = 0; } ++nr; T = join(T,new Node{&nil[0],&nil[0],my_rand(),1,v[i],v[i]},0); } int poz = 1; while(q[poz].t == 0) { rez[q[poz].cnt] = query(q[poz].poz); ++poz; } for(int t=1;t<=n;t++) { bool ok = next_perm(); if(!ok) { break; } while(poz<=m && q[poz].t==t) { rez[q[poz].cnt] = query(q[poz].poz); } } for(int i=poz;i<=m;i++) { rez[q[i].cnt] = query(q[i].poz); } for(int i=1;i<=m;i++) { cout<<rez[i]<<'\n'; } return 0; }

Compilation message (stderr)

Main.cpp: In function 'Node* join(Node*, Node*, bool)':
Main.cpp:36:13: error: 'nil' was not declared in this scope
   36 |     if(st==&nil[care])
      |             ^~~
Main.cpp:40:13: error: 'nil' was not declared in this scope
   40 |     if(dr==&nil[care])
      |             ^~~
Main.cpp: In function 'std::pair<Node*, Node*> split(Node*, int, bool)':
Main.cpp:56:14: error: 'nil' was not declared in this scope
   56 |     if(nod==&nil[care])
      |              ^~~
Main.cpp:58:38: error: could not convert '{<expression error>, <expression error>}' from '<brace-enclosed initializer list>' to 'std::pair<Node*, Node*>'
   58 |         return {&nil[care],&nil[care]};
      |                                      ^
      |                                      |
      |                                      <brace-enclosed initializer list>
Main.cpp: In function 'int get_cnt_first(Node*, bool)':
Main.cpp:74:20: error: 'nil' was not declared in this scope
   74 |     if(nod->st == &nil[care])
      |                    ^~~
Main.cpp: In function 'int query(int)':
Main.cpp:83:20: error: 'T' was not declared in this scope
   83 |     auto t = split(T,poz-1,0);
      |                    ^
Main.cpp: In function 'bool next_perm()':
Main.cpp:92:20: error: 'I' was not declared in this scope
   92 |     auto t = split(I,n/2,1);
      |                    ^
Main.cpp:92:22: error: 'n' was not declared in this scope
   92 |     auto t = split(I,n/2,1);
      |                      ^
Main.cpp:98:1: warning: no return statement in function returning non-void [-Wreturn-type]
   98 | }
      | ^
Main.cpp: In function 'int main()':
Main.cpp:104:10: error: 'n' was not declared in this scope; did you mean 'yn'?
  104 |     cin>>n>>m;
      |          ^
      |          yn
Main.cpp:104:13: error: 'm' was not declared in this scope; did you mean 'tm'?
  104 |     cin>>n>>m;
      |             ^
      |             tm
Main.cpp:107:14: error: 'v' was not declared in this scope
  107 |         cin>>v[i];
      |              ^
Main.cpp:111:14: error: 'q' was not declared in this scope
  111 |         cin>>q[i].t>>q[i].poz;
      |              ^
Main.cpp:118:10: error: 'q' was not declared in this scope
  118 |     sort(q+1,q+m+1,cmp);
      |          ^
Main.cpp:119:17: error: 'v' was not declared in this scope
  119 |     int first = v[1];
      |                 ^
Main.cpp:127:17: error: 'I' was not declared in this scope
  127 |                 I = join(I,new Node{&nil[1],&nil[1],my_rand(),nr,first,0},1);
      |                 ^
Main.cpp:127:38: error: 'nil' was not declared in this scope
  127 |                 I = join(I,new Node{&nil[1],&nil[1],my_rand(),nr,first,0},1);
      |                                      ^~~
Main.cpp:127:53: error: 'my_rand' was not declared in this scope; did you mean 'srand'?
  127 |                 I = join(I,new Node{&nil[1],&nil[1],my_rand(),nr,first,0},1);
      |                                                     ^~~~~~~
      |                                                     srand
Main.cpp:127:73: error: could not convert '{<expression error>, <expression error>, <expression error>, nr, first, 0}' from '<brace-enclosed initializer list>' to 'Node'
  127 |                 I = join(I,new Node{&nil[1],&nil[1],my_rand(),nr,first,0},1);
      |                                                                         ^
      |                                                                         |
      |                                                                         <brace-enclosed initializer list>
Main.cpp:133:9: error: 'T' was not declared in this scope
  133 |         T = join(T,new Node{&nil[0],&nil[0],my_rand(),1,v[i],v[i]},0);
      |         ^
Main.cpp:133:30: error: 'nil' was not declared in this scope
  133 |         T = join(T,new Node{&nil[0],&nil[0],my_rand(),1,v[i],v[i]},0);
      |                              ^~~
Main.cpp:133:45: error: 'my_rand' was not declared in this scope; did you mean 'srand'?
  133 |         T = join(T,new Node{&nil[0],&nil[0],my_rand(),1,v[i],v[i]},0);
      |                                             ^~~~~~~
      |                                             srand
Main.cpp:133:66: error: could not convert '{<expression error>, <expression error>, <expression error>, 1, <expression error>, <expression error>}' from '<brace-enclosed initializer list>' to 'Node'
  133 |         T = join(T,new Node{&nil[0],&nil[0],my_rand(),1,v[i],v[i]},0);
      |                                                                  ^
      |                                                                  |
      |                                                                  <brace-enclosed initializer list>
Main.cpp:138:9: error: 'rez' was not declared in this scope
  138 |         rez[q[poz].cnt] = query(q[poz].poz);
      |         ^~~
Main.cpp:150:13: error: 'rez' was not declared in this scope
  150 |             rez[q[poz].cnt] = query(q[poz].poz);
      |             ^~~
Main.cpp:155:9: error: 'rez' was not declared in this scope
  155 |         rez[q[i].cnt] = query(q[i].poz);
      |         ^~~
Main.cpp:159:15: error: 'rez' was not declared in this scope
  159 |         cout<<rez[i]<<'\n';
      |               ^~~