# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
26657 | top34051 | medians (balkan11_medians) | C++14 | 69 ms | 2996 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;
int n;
bool ok[200005];
int tree[200005];
void add(int x,int val) {
while(x<=2*n-1) {
tree[x] += val;
x += x&-x;
}
}
int sum(int x) {
int ans = 0;
while(x) {
ans += tree[x];
x -= x&-x;
}
return ans;
}
main() {
int i,j,x,sz;
scanf("%d",&n);
i = 1; j = 2*n-1;
for(sz=1;sz<=2*n-1;sz+=2) {
scanf("%d",&x);
if(!ok[x]) {
ok[x] = 1;
add(x,1);
printf("%d ",x);
}
while(sum(x-1)<sz/2) {
while(ok[i]) i++;
ok[i] = 1;
add(i,1);
printf("%d ",i);
}
while(sum(2*n-1)-sum(x)<sz/2) {
while(ok[j]) j--;
ok[j] = 1;
add(j,1);
printf("%d ",j);
}
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |