Submission #220190

#TimeUsernameProblemLanguageResultExecution timeMemory
220190t12345Arranging Shoes (IOI19_shoes)C++14
0 / 100
166 ms138232 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=1; i<=sz; i++) { t = a[i-1]; 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...