제출 #528274

#제출 시각아이디문제언어결과실행 시간메모리
528274happypotatoArranging Shoes (IOI19_shoes)C++17
0 / 100
0 ms204 KiB
#include "shoes.h" #include <bits/stdc++.h> using namespace std; const int mxN = 2e5 + 1; int seg[4 * mxN]; int n; void update(int tar, int l = 0, int r = n * 4 - 1, int idx = 1) { if (l == r) { seg[idx] ^= 1; return; } int mid = (l + r) >> 1; if (tar <= mid) update(tar, l, mid, (idx << 1)); else update(tar, mid + 1, r, (idx << 1) + 1); seg[idx] = seg[(idx << 1)] + seg[(idx << 1) + 1]; return; } int query(int tarl, int tarr, int l = 0, int r = n * 4 - 1, int idx = 1) { if (tarl <= l && r <= tarr) return seg[idx]; else if (tarr < l || r < tarl) return 0; int mid = (l + r) >> 1; return query(tarl, min(tarr, mid), l, mid, (idx << 1)) + query(max(tarl, mid + 1), tarr, mid + 1, r, (idx << 1) + 1); } long long count_swaps(vector<int> s) { n = s.size() / 2; queue<int> q[n + 1]; for (int i = 0; i < n * 2; i++) { if (s[i] < 0) q[-s[i]].push(i * 2); } for (int i = 0; i < n * 2; i++) update(i * 2); long long ans = 0; for (int i = 0; i < n * 2; i++) { if (s[i] < 0) continue; int cur = i * 2; int tar = q[s[i]].front(); q[s[i]].pop(); if (cur < tar) ans += query(cur + 1, tar - 1); else ans += query(tar + 1, cur); update(tar); update(cur + 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...