Submission #636445

#TimeUsernameProblemLanguageResultExecution timeMemory
636445borisAngelovArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> #include "shoes.h" const int MAXN = 200005; int n; vector<pair<int, int>> same_size[MAXN]; vector<pair<int, int>> matchings; struct FenwickTree { int fenwick[MAXN]; void update(int pos, int val) { while (pos < 2 * n) { fenwick[pos] += val; pos += (pos & (-pos)); } } int query(int pos) { int result = 0; while (pos > 0) { result += fenwick[pos]; pos -= (pos & (-pos)); } return result; } }; FenwickTree Fenwick; long long count_swaps(std::vector<int> shoes) { n = int(shoes.size()) / 2; for (int i = 0; i < 2 * n; i++) { same_size[abs(shoes[i])].push_back({shoes[i], i}); } long long ans = 0; for (int i = 1; i <= n; i++) { sort(same_size[i].begin(), same_size[i].end()); for (int j = 0; j < int(same_size[i].size()) / 2; j++) { int l = same_size[i][j].second; int r = same_size[i][j + int(same_size[i].size()) / 2].second; if (l > r) { swap(l, r); ans++; } matchings.push_back({l + 1, r + 1}); } } sort(matchings.begin(), matchings.end()); for (int i = 1; i <= 2 * n; i++) Fenwick.update(i, 1); for (int i = 0; i < matchings.size(); i++) { int l = matchings[i].first; int r = matchings[i].second; if (r - l > 1) ans += Fenwick.query(r - 1) - Fenwick.query(l); Fenwick.update(l, -1); Fenwick.update(r, -1); } return ans; }

Compilation message (stderr)

shoes.cpp:8:1: error: 'vector' does not name a type
    8 | vector<pair<int, int>> same_size[MAXN];
      | ^~~~~~
shoes.cpp:9:1: error: 'vector' does not name a type
    9 | vector<pair<int, int>> matchings;
      | ^~~~~~
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:38:9: error: 'same_size' was not declared in this scope
   38 |         same_size[abs(shoes[i])].push_back({shoes[i], i});
      |         ^~~~~~~~~
shoes.cpp:44:14: error: 'same_size' was not declared in this scope
   44 |         sort(same_size[i].begin(), same_size[i].end());
      |              ^~~~~~~~~
shoes.cpp:44:9: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
   44 |         sort(same_size[i].begin(), same_size[i].end());
      |         ^~~~
      |         std::sort
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from shoes.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:4880:5: note: 'std::sort' declared here
 4880 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
shoes.cpp:51:17: error: 'swap' was not declared in this scope
   51 |                 swap(l, r);
      |                 ^~~~
shoes.cpp:51:17: note: suggested alternatives:
In file included from /usr/include/c++/10/regex:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:110,
                 from shoes.cpp:1:
/usr/include/c++/10/bits/regex.h:2141:5: note:   'std::__cxx11::swap'
 2141 |     swap(match_results<_Bi_iter, _Alloc>& __lhs,
      |     ^~~~
In file included from /usr/include/c++/10/exception:147,
                 from /usr/include/c++/10/ios:39,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from shoes.cpp:1:
/usr/include/c++/10/bits/exception_ptr.h:169:5: note:   'std::__exception_ptr::swap'
  169 |     swap(exception_ptr& __lhs, exception_ptr& __rhs)
      |     ^~~~
In file included from /usr/include/c++/10/bits/nested_exception.h:40,
                 from /usr/include/c++/10/exception:148,
                 from /usr/include/c++/10/ios:39,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from shoes.cpp:1:
/usr/include/c++/10/bits/move.h:189:5: note:   'std::swap'
  189 |     swap(_Tp& __a, _Tp& __b)
      |     ^~~~
shoes.cpp:55:13: error: 'matchings' was not declared in this scope
   55 |             matchings.push_back({l + 1, r + 1});
      |             ^~~~~~~~~
shoes.cpp:59:10: error: 'matchings' was not declared in this scope
   59 |     sort(matchings.begin(), matchings.end());
      |          ^~~~~~~~~
shoes.cpp:59:5: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
   59 |     sort(matchings.begin(), matchings.end());
      |     ^~~~
      |     std::sort
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from shoes.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:4880:5: note: 'std::sort' declared here
 4880 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~