# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1249327 | duyanhloveav | medians (balkan11_medians) | C++20 | 23 ms | 2372 KiB |
#include <bits/stdc++.h>
using namespace std;
#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1LL)
using ll = long long;
const int mxn = 9 + 1e6;
const int inf = 0x3f3f3f3f;
const ll lnf = 0x3f3f3f3f3f3f3f3f;
template <class T>
struct Fenwick {
vector<T> fenw;
int n;
Fenwick(int n) : n(n) { fenw.resize(n); }
void upd(int x, T v) {
for (; x < n; x |= x + 1) {
fenw[x] += v;
}
}
T get(int x) {
T v{};
for (; x >= 0; x &= x + 1, --x) {
v += fenw[x];
}
return v;
}
};
void _27augain(void) {
int n;
cin >> n;
int l = 1, r = 2 * n - 1;
vector<bool> used(r + 1);
Fenwick<int> fenw(r + 1);
for (int sz = 1; sz <= 2 * n - 1; sz += 2) {
int x;
cin >> x;
if (!used[x]) {
used[x] = true;
fenw.upd(x, 1);
cout << x << " ";
}
while (fenw.get(x - 1) < sz / 2) {
while (used[l]) ++l;
used[l] = true;
fenw.upd(l, 1);
cout << l << " ";
}
while (fenw.get(2 * n - 1) - fenw.get(x) < sz / 2) {
while (used[r]) --r;
used[r] = true;
fenw.upd(r, 1);
cout << r << " ";
}
}
}
int32_t main(void) {
#define task "27augain"
cin.tie(0)->sync_with_stdio(0);
for (string iext : {"in", "inp"}) {
if (fopen((task "." + iext).c_str(), "r")) {
freopen((task "." + iext).c_str(), "r", stdin);
freopen(task ".out", "w", stdout);
}
}
int testcase = 1;
// cin >> testcase;
while (testcase--) {
_27augain();
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |