제출 #1306452

#제출 시각아이디문제언어결과실행 시간메모리
1306452baodatArranging Shoes (IOI19_shoes)C++20
10 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define FOR(i, l, r) for(int i = l; i <= r; i++) #define FORD(i, l, r) for(int i = l; i >= r; i--) #define all(x) (x).begin(), (x).end() struct BIT{ int n; vector<int> bit; BIT(int __n = 0){ init(__n); } void init(int __n = 0){ n = __n; bit.assign(n + 5, 0); } void update(int i, int v){ ++i; while(i <= n){ bit[i] += v; i += i &-i; } } int query(int i){ ++i; int ans = 0; while(i > 0){ ans += bit[i]; i -= i &-i; } return ans; } int query(int l, int r){ return query(r) - query(l - 1); } }; ll count_swaps(vector<int> a){ int m = a.size(); int maxi = 0; for (int x : a) maxi = max(maxi, abs(x)); vector<int> last(maxi + 1, -1); vector<int> match(m, -1); for (int i = 0; i < m; ++i) { int x = abs(a[i]); if (last[x] == -1) last[x] = i; else { match[i] = last[x]; match[last[x]] = i; } } BIT bit(m); FOR(i, 0, m - 1)bit.update(i, 1); vector<char> used(m, 0); ll ans = 0; FOR(i, 0, m - 1){ if (used[i]) continue; int j = match[i]; if (j == -1) continue; if (i > j) continue; ans += bit.query(i + 1, j - 1); if (a[i] > 0) ++ans; used[i] = used[j] = 1; bit.update(i, -1); bit.update(j, -1); } 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...