Submission #536518

#TimeUsernameProblemLanguageResultExecution timeMemory
536518fuad27Arranging Shoes (IOI19_shoes)C++17
100 / 100
240 ms274480 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; const int MAXN = 200'010; int n; namespace fenwick { long long fen[MAXN]; void update(int in, int val) { in++; while(in < MAXN) { fen[in]+=val; in+=in&(-in); } } long long query(int l) { l++; long long ans = 0; while(l > 0) { ans += fen[l]; l-=l&(-l); } return ans; } }; long long getNum(long long i) { return i + n; } long long count_swaps(std::vector<int> v) { n = v.size(); for(int i = 0;i<MAXN;i++) { fenwick::fen[i] = 0; } for(int i = 0;i<MAXN;i++) { fenwick::update(i, 1); } long long ans = 0; queue<int> q[2*n+1]; for(int i = 0;i<n;i++) { if(q[getNum(-v[i])].size()!=0) { int at = q[getNum(-v[i])].front(); q[getNum(-v[i])].pop(); ans+=fenwick::query(i) - fenwick::query(at)-1; if(v[i] < 0)ans++; fenwick::update(i, -1); fenwick::update(at, 1); } else { q[getNum(v[i])].push(i); } } 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...