Submission #220193

#TimeUsernameProblemLanguageResultExecution timeMemory
220193t12345Arranging Shoes (IOI19_shoes)C++14
100 / 100
174 ms138680 KiB
#include "shoes.h" #include <iostream> #include <cstdio> #include <queue> #define N 200005 using namespace std; int sz, Z=1e5, tr[N]; long long ans; queue<int> qu[N]; void upd(int p, int q){ for(int i=++p; i<=sz; i += i&-i) tr[i] += q; } int qry(int p){ int re=0; for(int i=++p; i; i -= i&-i) re += tr[i]; return re; } long long count_swaps(vector<int> a) { int i, j, t; sz = a.size(); for(i=0; i<sz; i++) { t = a[i]; if(qu[Z-t].empty()) { qu[Z+t].push(i); upd(i, 1); } else { j = qu[Z-t].front(); qu[Z-t].pop(); ans += i-j; if(a[i]>0) ans--; ans -= qry(i) - qry(j); upd(j, -1); } } return ans; }
#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...