Submission #380020

#TimeUsernameProblemLanguageResultExecution timeMemory
380020madlogicArranging Shoes (IOI19_shoes)C++17
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "shoes.h" struct SegmentTree { int n; vector<int> a, st; SegmentTree(vector<int> b) { n = (int) b.size(); a = b; st.resize(4 * n); build(0, n - 1, 1); } inline int L(int n) { return (n << 1); } int build(int l, int r, int node) { if (l == r) { st[node] = a[l]; return st[node]; } int mid = l + r >> 1; int left = build(l, mid, L(node)); int right = build(mid + 1, r, L(node) + 1); return st[node] = st[(node << 1)] + st[(node << 1) + 1]; } int query(int l, int r) { return rsq(0, n - 1, l, r, 1); } void update(int ind, int k) { upd(0, n - 1, ind, k, 1); } int upd(int l, int r, int ind, int val, int node) { if (l == r) { st[node] += val; return st[node]; } int mid = l + r >> 1; if (ind <= mid) upd(l, mid, ind, val, (node << 1)); else upd(mid + 1, r, ind, val, (node << 1) + 1); return st[node] = st[(node << 1)] + st[(node << 1) + 1]; } int rsq(int l, int r, int lb, int rb, int node) { if (l > rb || r < lb) return 0; if (l >= lb && r <= rb) return st[node]; int mid = l + r >> 1; int left = rsq(l, mid, lb, rb, L(node)); int right = rsq(mid + 1, r, lb, rb, L(node) + 1); return left + right; } }; long long count_swaps(std::vector<int> s) { int n = (int) s.size(); map<int, queue<int>> mp; for (int i = 0; i < n; i++) { mp[s[i]].push(i); } SegmentTree st(vector<int>(n, 0)); long long res = 0; vector<bool> vis(n); for (int i = 0; i < n; i++) { if (vis[i]) { continue; } int pos = mp[-s[i]].front(); vis[pos] = true; mp[-s[i]].pop(); mp[s[i]].pop(); int to; if (s[i] < 0) { to = i + 1; } else { to = i; } res += pos - to - st.query(to, pos); st.update(pos, 1); } return res; }

Compilation message (stderr)

shoes.cpp:6:3: error: 'vector' does not name a type
    6 |   vector<int> a, st;
      |   ^~~~~~
shoes.cpp:7:21: error: expected ')' before '<' token
    7 |   SegmentTree(vector<int> b) {
      |              ~      ^
      |                     )
shoes.cpp: In member function 'int SegmentTree::build(int, int, int)':
shoes.cpp:20:7: error: 'st' was not declared in this scope; did you mean 'std'?
   20 |       st[node] = a[l];
      |       ^~
      |       std
shoes.cpp:20:18: error: 'a' was not declared in this scope
   20 |       st[node] = a[l];
      |                  ^
shoes.cpp:23:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |     int mid = l + r >> 1;
      |               ~~^~~
shoes.cpp:26:12: error: 'st' was not declared in this scope; did you mean 'std'?
   26 |     return st[node] = st[(node << 1)] + st[(node << 1) + 1];
      |            ^~
      |            std
shoes.cpp:24:9: warning: unused variable 'left' [-Wunused-variable]
   24 |     int left = build(l, mid, L(node));
      |         ^~~~
shoes.cpp:25:9: warning: unused variable 'right' [-Wunused-variable]
   25 |     int right = build(mid + 1, r, L(node) + 1);
      |         ^~~~~
shoes.cpp: In member function 'int SegmentTree::upd(int, int, int, int, int)':
shoes.cpp:39:7: error: 'st' was not declared in this scope; did you mean 'std'?
   39 |       st[node] += val;
      |       ^~
      |       std
shoes.cpp:42:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |     int mid = l + r >> 1;
      |               ~~^~~
shoes.cpp:47:12: error: 'st' was not declared in this scope; did you mean 'std'?
   47 |     return st[node] = st[(node << 1)] + st[(node << 1) + 1];
      |            ^~
      |            std
shoes.cpp: In member function 'int SegmentTree::rsq(int, int, int, int, int)':
shoes.cpp:54:14: error: 'st' was not declared in this scope; did you mean 'std'?
   54 |       return st[node];
      |              ^~
      |              std
shoes.cpp:55:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   55 |     int mid = l + r >> 1;
      |               ~~^~~
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:64:3: error: 'map' was not declared in this scope
   64 |   map<int, queue<int>> mp;
      |   ^~~
shoes.cpp:64:3: note: suggested alternatives:
In file included from /usr/include/c++/9/map:61,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:81,
                 from shoes.cpp:1:
/usr/include/c++/9/bits/stl_map.h:100:11: note:   'std::map'
  100 |     class map
      |           ^~~
In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:81,
                 from shoes.cpp:1:
/usr/include/c++/9/map:82:13: note:   'std::pmr::map'
   82 |       using map
      |             ^~~
shoes.cpp:64:7: error: expected primary-expression before 'int'
   64 |   map<int, queue<int>> mp;
      |       ^~~
shoes.cpp:66:5: error: 'mp' was not declared in this scope
   66 |     mp[s[i]].push(i);
      |     ^~
shoes.cpp:68:18: error: 'vector' was not declared in this scope
   68 |   SegmentTree st(vector<int>(n, 0));
      |                  ^~~~~~
shoes.cpp:68:18: note: suggested alternatives:
In file included from /usr/include/c++/9/vector:67,
                 from /usr/include/c++/9/functional:62,
                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/9/algorithm:71,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from shoes.cpp:1:
/usr/include/c++/9/bits/stl_vector.h:386:11: note:   'std::vector'
  386 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from /usr/include/c++/9/functional:62,
                 from /usr/include/c++/9/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/9/algorithm:71,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from shoes.cpp:1:
/usr/include/c++/9/vector:90:13: note:   'std::pmr::vector'
   90 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
shoes.cpp:68:25: error: expected primary-expression before 'int'
   68 |   SegmentTree st(vector<int>(n, 0));
      |                         ^~~
shoes.cpp:70:10: error: expected primary-expression before 'bool'
   70 |   vector<bool> vis(n);
      |          ^~~~
shoes.cpp:72:9: error: 'vis' was not declared in this scope
   72 |     if (vis[i]) {
      |         ^~~
shoes.cpp:75:15: error: 'mp' was not declared in this scope
   75 |     int pos = mp[-s[i]].front();
      |               ^~
shoes.cpp:76:5: error: 'vis' was not declared in this scope
   76 |     vis[pos] = true;
      |     ^~~