Submission #424759

#TimeUsernameProblemLanguageResultExecution timeMemory
424759amoo_safarArranging Shoes (IOI19_shoes)C++17
100 / 100
80 ms19060 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int fen[N]; void Add(int idx){ for(; idx < N; idx += idx & (-idx)) fen[idx] ++; } int Get(int idx){ int res = 0; for(; idx; idx -= idx & (-idx)) res += fen[idx]; return res; } vector<int> A[N], B[N]; long long count_swaps(std::vector<int> s) { int n = s.size() / 2; for(int i = 0; i < n + n; i++) (s[i] > 0 ? A : B)[abs(s[i])].push_back(i); vector<int> a(n + n, 0); for(int i = 0; i <= n; i++) for(int j = 0; j < (int) A[i].size(); j++) a[A[i][j]] = a[ B[i][j] ] = min(A[i][j], B[i][j]) + 2; long long ans = 0; for(int i = 0; i <= n; i++) for(int j = 0; j < (int) A[i].size(); j++) ans += (A[i][j] < B[i][j]); for(int i = n + n - 1; i >= 0; i--){ // cerr << "! " << a[i] << '\n'; ans += Get(a[i] - 1); Add(a[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...