Submission #857560

#TimeUsernameProblemLanguageResultExecution timeMemory
857560sleepntsheepArranging Shoes (IOI19_shoes)C++17
0 / 100
1 ms2396 KiB
#include <vector> #include <cstdint> #include <iostream> #include <algorithm> #define N 200005 int vs[N], fw[N], posraw[N<<1]; int *pos = posraw+N; void upd(int p, int k) { for (++p; p < N; p+=p&-p) fw[p] += k; } int qry(int p) { if(p<0)return 0;int z = 0; for (++p; p; p-=p&-p) z += fw[p]; return z; } int64_t count_swaps(std::vector<int> v) { int64_t z = 0; int n = v.size() >> 1, f = 0; for (int i = 0; i < (int)v.size(); ++i) pos[v[i]] = i; for (int i = 0; i < 2 * n; ++i, ++f) { int h = i; if (qry(i) - qry(i-1) == -1) continue; int corresponding = pos[-v[i]] + (qry(n) - qry(pos[-v[i]])); z += corresponding - h + (v[i] < 0); upd(corresponding, -1); } return z; } #if 0 int main() { std::cout << count_swaps({2, 1, -1, -2}); } #endif
#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...