Submission #184045

#TimeUsernameProblemLanguageResultExecution timeMemory
184045Ruxandra985Arranging Shoes (IOI19_shoes)C++14
100 / 100
297 ms140272 KiB
#include <bits/stdc++.h> #include "shoes.h" #define DIMN 200010 using namespace std; int aib[DIMN] , f[DIMN]; deque <int> poz[DIMN]; void update (int i , int n , int x){ for (;i<=n;i = i + (i & (-i))) aib[i]+=x; } int query (int i){ int sol = 0; for (;i;i = i - (i & (-i))) sol+=aib[i]; return sol; } long long count_swaps (vector <int> v){ int n , i , p1 , p2 , aux; long long sol=0; n = v.size() / 2; for (i=0;i<2*n;i++){ poz[max(v[i] , -v[i])].push_back(i); /// a doua pozitie } for (i=0;i<2*n;i++){ if (!f[i]){ /// nu ai mai intalnit p1 = i + query(i + 1); p2 = poz[max(v[i] , -v[i])].front(); poz[max(v[i] , -v[i])].pop_front(); while (p2 <= i || v[p2] == v[i]){ p2 = poz[max(v[i] , -v[i])].front(); poz[max(v[i] , -v[i])].pop_front(); } f[p2] = 1; aux = p2; p2 += query(p2 + 1); sol = sol + (p2 - p1 - 1); if (v[i] > 0) sol++; /// mai faci un swap update (i + 1, 2*n , 1); update (aux+1 , 2*n , -1); } } return sol; }
#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...