Submission #487114

#TimeUsernameProblemLanguageResultExecution timeMemory
487114Spade1Arranging Shoes (IOI19_shoes)C++14
0 / 100
5 ms5068 KiB
#include <bits/stdc++.h> #include "shoes.h" #define ll long long #define pii pair<int, int> #define st first #define nd second #define pb push_back using namespace std; int fw[200020]; vector<pii> pos[200020]; vector<pii> swp; void update(int i, int val) { for (; i <= 200000; i += i&-i) { fw[i] += val; } } int query(int i) { int cnt = 0; for (; i > 0; i -= i&-i) { cnt += fw[i]; } } ll count_swaps(vector<int> s) { int n = s.size()/2; s.insert(s.begin(), 0); ll ans = 0; for (int i = 1; i <= n; ++i) { update(i, 1); pos[abs(s[i])].pb({s[i], i}); } for (int i = 1; i <= n; ++i) { sort(pos[i].begin(), pos[i].end()); int m = pos[i].size(); for (int j = 0; j < m/2; ++j) { int l = pos[i][j].nd; int r = pos[i][j + m/2].nd; if (l > r) { ++ans; swap(l, r); } swp.pb({l, r}); } } sort(swp.begin(), swp.end()); for (auto [l, r] : swp) { ans += query(r - 1) - query(l); update(r, -1); update(l, -1); } return ans; }

Compilation message (stderr)

shoes.cpp: In function 'int query(int)':
shoes.cpp:25:1: warning: no return statement in function returning non-void [-Wreturn-type]
   25 | }
      | ^
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:53:15: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   53 |     for (auto [l, r] : swp) {
      |               ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...