Submission #636438

#TimeUsernameProblemLanguageResultExecution timeMemory
636438borisAngelovArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; 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(const vector<int>& shoes) { n = 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 < same_size[i].size() / 2; j++) { int l = same_size[i][j].second; int r = same_size[i][j + 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 (auto [l, r] : matchings) { if (r - l > 1) ans += Fenwick.query(r - 1) - Fenwick.query(l); Fenwick.update(l, -1); Fenwick.update(r, -1); } return ans; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int s; cin >> s; vector<int> shoes; for (int i = 0; i < 2 * s; i++) { int x; cin >> x; shoes.push_back(x); } cout << count_swaps(shoes) << endl; return 0; }

Compilation message (stderr)

shoes.cpp: In function 'long long int count_swaps(const std::vector<int>&)':
shoes.cpp:47:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |         for (int j = 0; j < same_size[i].size() / 2; j++) {
      |                         ~~^~~~~~~~~~~~~~~~~~~~~~~~~
shoes.cpp:64:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   64 |     for (auto [l, r] : matchings) {
      |               ^
/usr/bin/ld: /tmp/ccnDGZrm.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/cc6IiWvq.o:shoes.cpp:(.text.startup+0x0): first defined here
/usr/bin/ld: /tmp/ccnDGZrm.o: in function `main':
grader.cpp:(.text.startup+0x29d): undefined reference to `count_swaps(std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status