제출 #278325

#제출 시각아이디문제언어결과실행 시간메모리
278325KastandaArranging Shoes (IOI19_shoes)C++14
10 / 100
9 ms10496 KiB
// M #include<bits/stdc++.h> #include "shoes.h" using namespace std; const int N = 100005 * 2; int M[N], F[N]; vector < int > V[N][2]; inline void Add(int i, int val) { for (i = N - i - 5; i < N; i += i & - i) F[i] += val; } inline int Get(int i) { int rt = 0; for (i = N - i - 5; i; i -= i & - i) rt += F[i]; return rt; } long long count_swaps(vector < int > A) { int n = (int)A.size() / 2; for (int i = 0; i < n + n; i ++) V[abs(A[i])][A[i] > 0].push_back(i); int m = 0; for (int i = 1; i <= n; i ++) { assert(V[i][0].size() == V[i][1].size()); for (int j = 0; j < (int)V[i][0].size(); j ++) m ++, A[V[i][0][j]] = -m, A[V[i][1][j]] = m; } long long tot = 0; memset(M, -1, sizeof(M)); for (int i = 0; i < n + n; i ++) { if (M[abs(A[i])] == -1) Add(i, 1), M[abs(A[i])] = i; else { if (A[i] < 0) tot ++; tot += Get(M[abs(A[i])]) - 1; Add(i, 1); } } return tot; }
#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...