제출 #201411

#제출 시각아이디문제언어결과실행 시간메모리
201411khulegubArranging Shoes (IOI19_shoes)C++14
0 / 100
755 ms1048580 KiB
#include "shoes.h" #include <bits/stdc++.h> #define mp make_pair #define pb push_back #define xx first #define yy second #define ll(x) (x*2) + 1 #define rr(x) (x*2) + 2 using namespace std; typedef long long i64; vector<int> tt; vector<int> st; void build(int l, int r, int ti){ if (l == r){ st[ti] = tt[l]; return; } int mid = (l + r) >> 1; build(l, mid - 1, ll(ti)); build(mid, r, rr(ti)); st[ti] = st[ll(ti)] + st[rr(ti)]; } void update(int ui, int l, int r, int ti){ if (l == r){ st[ti] = tt[l]; return; } int mid = (l + r) >> 1; if (ui >= l && ui <= mid - 1) build(l, mid - 1, ll(ti)); if (ui >= mid && ui <= r) build(mid, r, rr(ti)); st[ti] = st[ll(ti)] + st[rr(ti)]; } int query(int ql, int qr, int l, int r, int ti){ if (l > qr || r < ql) return 0; if (ql <= l && r <= qr){ return st[ti]; } int mid = (l + r) >> 1; return query(ql, qr, l, mid - 1, ll(ti)) + query(ql, qr, mid, r, rr(ti)); } i64 count_swaps(std::vector<int> s) { i64 ans = 0LL; int n = s.size(); tt.resize(n); st.resize(4 * n); build(0, n - 1, 0); map<int, vector<int> > maap; for (int i = n - 1; i >= 0; i--){ maap[s[i]].pb(i); } vector<bool> taken(n, 0); for (int i = 0; i < n; i++){ if (!taken[i]){ maap[s[i]].pop_back(); int tmp = maap[s[i] * -1].back(); maap[s[i] * -1].pop_back(); taken[tmp] = 1; if (s[i] < 0){ ans += tmp - i - 1; } else{ ans += tmp - i; } ans -= query(i, tmp, 0, n - 1, 0); tt[tmp]++; update(tmp, 0, n - 1, 0); } } 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...