Submission #146146

#TimeUsernameProblemLanguageResultExecution timeMemory
146146HellAngelArranging Shoes (IOI19_shoes)C++14
50 / 100
75 ms27396 KiB
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 7; long long n, BIT[maxn]; bool d2[maxn]; vector<long long> q[2][maxn]; void Update(long long u, long long v) { for(; u < maxn; u += u & -u) BIT[u]+= v; } long long Get(long long 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(long long i = 0; i < n * 2; i++) { if(vt[i] > 0) { q[1][vt[i]].push_back(i); } else q[0][-vt[i]].push_back(i); Update(i + 1, 1); } for(int i = 1; i <= n; i++) reverse(q[0][i].begin(), q[0][i].end()), reverse(q[1][i].begin(), q[1][i].end()); int cnt = 1; for(int i = 0; i < n * 2; i++) { if(d2[i + 1]) continue; int gau = q[0][abs(vt[i])].back() + 1; int meo = q[1][abs(vt[i])].back() + 1; d2[gau] = d2[meo] = true; q[0][abs(vt[i])].pop_back(); q[1][abs(vt[i])].pop_back(); ans += Get(gau) - cnt++; Update(1, 1); Update(gau, -1); ans += Get(meo) - cnt++; Update(1, 1); Update(meo, -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...