Submission #398457

#TimeUsernameProblemLanguageResultExecution timeMemory
398457iulia13Arranging Shoes (IOI19_shoes)C++14
10 / 100
8 ms9708 KiB
#include <iostream> #include <vector> #include "shoes.h" using namespace std; const int nmax = 1e5 + 5; #define ll long long ll aib[nmax * 4]; int moved[nmax], n; vector <int> a[nmax * 4]; int lsb(int x) { return x & (-x); } void upd(int x, int val) { for (x; x <= n; x += lsb(x)) aib[x] += val; } ll qry(int x) { int s = 0; while (x) { s += aib[x]; x -= lsb(x); } return x; } ll count_swaps(vector<int> v) { ll i, ans = 0; n = v.size(); for (i = n - 1; 0 <= i; i--) a[v[i] + n].push_back(i); for (i = 0; i < n; i++) { if (moved[i]) continue; ll j = a[n - v[i]].back(), swaps = 0; ///i < j if (v[i] > 0) swaps = 1; ///aduci j langa i adica pe i + 1 swaps += j - i - 1 - (qry(j) - qry(i)); upd(j, 1); ans += swaps; moved[j] = 1; a[n - v[i]].pop_back(); a[n + v[i]].pop_back(); } return ans; }/* int main() { int N, i; cin >> N; vector <int> v; v.resize(N); for (i = 0; i < N; i++) cin >> v[i]; cout << count_swaps(v); return 0; }*/

Compilation message (stderr)

shoes.cpp: In function 'void upd(int, int)':
shoes.cpp:16:10: warning: statement has no effect [-Wunused-value]
   16 |     for (x; x <= n; x += lsb(x))
      |          ^
#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...