Submission #590919

#TimeUsernameProblemLanguageResultExecution timeMemory
590919someoneArranging Shoes (IOI19_shoes)C++14
100 / 100
305 ms358600 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; const int M = 1 << 18, N = M << 1; bool b[N]; int val[N]; deque<int> pos[N]; int update(int i, int add) { i += M; int ans = 0; while(i > 0) { val[i] += add; if(i % 2 == 0) ans += val[i+1]; i >>= 1; } return ans; } long long count_swaps(std::vector<int> s) { long long sum = 0; int n = (int)s.size(); for(int i = 0; i < n; i++) pos[s[i] + M].push_back(i); for(int i = 0; i < n; i++) { if(!b[i]) { while(b[pos[M-s[i]][0]]) { cout << pos[M-s[i]][0] << '\n'; pos[M-s[i]].pop_front(); } int position1 = i + update(i, 0), position2 = pos[M-s[i]][0] + update(pos[M-s[i]][0], 1); sum += position2 - position1; if(s[i] < 0) sum--; b[pos[M-s[i]][0]] = true; pos[M+s[i]].pop_front(); pos[M-s[i]].pop_front(); } } return sum; }
#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...