# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1115023 |
2024-11-19T22:46:44 Z |
RED1 |
medians (balkan11_medians) |
C++14 |
|
112 ms |
14272 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define Algerian ios::sync_with_stdio(false);
#define OI cin.tie(nullptr);
int MAX = 200001;
struct segtree {
int size;
vector<int> sums;
void init(int n){
size = 1;
while(size<n) size *= 2;
sums.assign(2*size, 0);
}
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;
MAX = 2*N;
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+1);
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 |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
6 |
Correct |
1 ms |
508 KB |
Output is correct |
7 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
11 |
Incorrect |
2 ms |
336 KB |
Output isn't correct |
12 |
Incorrect |
1 ms |
336 KB |
Output isn't correct |
13 |
Incorrect |
2 ms |
592 KB |
Output isn't correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
592 KB |
Output isn't correct |
2 |
Incorrect |
7 ms |
1016 KB |
Output isn't correct |
3 |
Incorrect |
9 ms |
1360 KB |
Output isn't correct |
4 |
Incorrect |
25 ms |
2484 KB |
Output isn't correct |
5 |
Incorrect |
32 ms |
4792 KB |
Output isn't correct |
6 |
Incorrect |
72 ms |
9152 KB |
Output isn't correct |
7 |
Incorrect |
112 ms |
14272 KB |
Output isn't correct |