Submission #146114

#TimeUsernameProblemLanguageResultExecution timeMemory
146114HellAngelArranging Shoes (IOI19_shoes)C++14
10 / 100
197 ms141560 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; int n, BIT[maxn]; queue<int> q[maxn]; void Update(int u, int v) { for(; u < maxn; u += u & -u) BIT[u]+= v; } long long Get(int u) { long long ans = 0; for(; u > 0; u -= u & -u) ans += BIT[u]; return ans; } long long count_swaps(vector<int> vt) { long long ans = 0; n = vt.size() / 2; for(int i = 0; i < n * 2; i++) { if(vt[i] > 0) { q[vt[i]].push(i); } Update(i + 1, 1); } int cnt = 1; for(int i = 0; i < n * 2; i++) { if(vt[i] < 0) { int gau = Get(i + 1); ans += gau - cnt; cnt++; Update(1, 1); Update(i + 1, -1); int posr = q[-vt[i]].front(); q[-vt[i]].pop(); int meo = Get(posr + 1); ans += meo - cnt; cnt++; Update(1, 1); Update(posr + 1, -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...