# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1115015 |
2024-11-19T22:21:37 Z |
RED1 |
medians (balkan11_medians) |
C++14 |
|
111 ms |
16320 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Algerian ios::sync_with_stdio(false);
#define OI cin.tie(nullptr);
const int MAX = 200000;
struct segtree {
int size;
vector<ll> sums;
void init(int n){
size = 1;
while(size<n) size *= 2;
sums.assign(2*size, 0LL);
}
void set(int i, int v, int x, int lx, int rx){
if(rx-lx==1){
sums[x]=v;
return;
}
int m = (lx+rx)/2;
if(i<m) set(i,v,2*x+1,lx,m);
else set(i,v,2*x+2,m,rx);
sums[x]=sums[2*x+1]+sums[2*x+2];
}
void set(int i, int v){
set(i,v,0,0,size);
}
ll sum(int l, int r, int x, int lx, int rx){
if(lx>=r ||l>=rx) return 0;
if(lx>=l && rx<=r) return sums[x];
int m = (lx+rx)/2;
ll s1 = sum(l,r,2*x+1,lx,m);
ll s2 = sum(l,r,2*x+2,m,rx);
return s1+s2;
}
ll sum(int l, int r){
return sum(l,r,0,0,size);
}
};
int main()
{
Algerian OI;
int N; cin >> N;
vector<int> B(N);
for(auto &i : B) cin >> i;
segtree ST;
ST.init(MAX);
map<int,bool> put;
vector<int> ans;
set<int> nums;
for(int i=1;i<=2*N-1;++i) nums.insert(i);
ans.push_back(B[0]);
put[B[0]]=true;
ST.set(B[0],1);
nums.erase(nums.find(B[0]));
int j = 2;
for(int i = 1;i<N;++i) {
int cur = B[i];
if(!put[cur]) {
put[cur]=true;
++j;
nums.erase(nums.find(cur));
ans.push_back(cur);
ST.set(cur,1);
}
int numofbigger = ST.sum(cur+1,MAX);
while(j<=2*(i+1)-1) {
if(numofbigger<i) {
auto it = nums.lower_bound(cur);
put[*it]=true;
ans.push_back(*it);
ST.set(*it,1);
++numofbigger;
nums.erase(it);
}
else {
auto it = nums.begin();
put[*it]=true;
ans.push_back(*it);
ST.set(*it,1);
nums.erase(it);
}
++j;
}
}
for(auto i: ans) cout << i << ' ';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4432 KB |
Output is correct |
2 |
Correct |
2 ms |
4432 KB |
Output is correct |
3 |
Incorrect |
2 ms |
4432 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
5 |
Incorrect |
2 ms |
4432 KB |
Output isn't correct |
6 |
Correct |
2 ms |
4432 KB |
Output is correct |
7 |
Incorrect |
1 ms |
4600 KB |
Output isn't correct |
8 |
Incorrect |
3 ms |
4432 KB |
Output isn't correct |
9 |
Incorrect |
2 ms |
4432 KB |
Output isn't correct |
10 |
Incorrect |
2 ms |
4432 KB |
Output isn't correct |
11 |
Incorrect |
1 ms |
4432 KB |
Output isn't correct |
12 |
Incorrect |
2 ms |
4432 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
4688 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
4688 KB |
Output isn't correct |
2 |
Incorrect |
4 ms |
5116 KB |
Output isn't correct |
3 |
Incorrect |
9 ms |
5412 KB |
Output isn't correct |
4 |
Incorrect |
18 ms |
6480 KB |
Output isn't correct |
5 |
Incorrect |
32 ms |
8408 KB |
Output isn't correct |
6 |
Incorrect |
75 ms |
12224 KB |
Output isn't correct |
7 |
Incorrect |
111 ms |
16320 KB |
Output isn't correct |