# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
480780 | duchung | medians (balkan11_medians) | C++17 | 48 ms | 2564 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n;
int bit[N];
bool used[N];
void update(int idx , int val)
{
for (idx ; idx <= 2 * n - 1 ; idx += idx & -idx) bit[idx] += 1;
}
int get(int idx)
{
int ret = 0;
for (idx ; idx >= 1 ; idx -= idx & -idx) ret += bit[idx];
return ret;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n;
int pt1 = 1 , pt2 = 2 * n - 1;
for (int sz = 1 ; sz <= 2 * n - 1 ; sz += 2)
{
int tmp;
cin >> tmp;
if (!used[tmp])
{
used[tmp] = true;
update(tmp , 1);
cout << tmp << " ";
}
while(get(tmp - 1) < sz / 2)
{
while(used[pt1]) ++pt1;
used[pt1] = true;
update(pt1 , 1);
cout << pt1 << " ";
}
while(get(2 * n - 1) - get(tmp) < sz / 2)
{
while(used[pt2]) --pt2;
used[pt2] = true;
update(pt2 , 1);
cout << pt2 << " ";
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |