답안 #104118

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
104118 2019-04-04T06:28:13 Z faustaadp 중앙값 배열 (balkan11_medians) C++17
100 / 100
260 ms 22796 KB
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
using namespace std;
ll n,i,a[202020],b[202020],sud[202020],jaw[202020],j;
set<ll> st;
set<ll> st2;
int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin>>n;
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=1;i<n;i++)b[a[i]]++;
	for(i=1;i<=n*2-1;i++)
		if(b[i]==0)
		{
			st.insert(i);
			st2.insert(-i);
		}
	jaw[1]=a[1];
	for(i=n-1;i>=1;i--)
	{
		if(a[i]<a[i+1])
		{
			j=*st.lower_bound(a[i]);
			jaw[i*2]=j;
			st.erase(j);
			st2.erase(-j);
			j=*st.lower_bound(a[i]);
			jaw[i*2+1]=j;
			st.erase(j);
			st2.erase(-j);
		}
		else
		if(a[i]>a[i+1])
		{
			j=*st2.lower_bound(-a[i]);
			j=-j;
			jaw[i*2]=j;
			st.erase(j);
			st2.erase(-j);
			j=*st2.lower_bound(-a[i]);
			j=-j;
			jaw[i*2+1]=j;
			st.erase(j);
			st2.erase(-j);
		}
		else
		{
			j=*st.lower_bound(a[i]);
			jaw[i*2]=j;
			st.erase(j);
			st2.erase(-j);
			j=*st2.lower_bound(-a[i]);
			//cout<<*st2.begin()<<"\n";
			//cout<<j<<"\n";
			j=-j;
			jaw[i*2+1]=j;
			st.erase(j);
			st2.erase(-j);
		}	
		b[a[i]]--;
		if(b[a[i]]==0&&sud[a[i]]==0)st.insert(a[i]);
		if(b[a[i]]==0&&sud[a[i]]==0)st2.insert(-a[i]);
	}
	for(i=1;i<=(n*2-1);i++)
		if(i<(n*2-1))
			cout<<jaw[i]<<" ";
		else
			cout<<jaw[i]<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 3 ms 384 KB Output is correct
7 Correct 2 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 3 ms 384 KB Output is correct
11 Correct 3 ms 384 KB Output is correct
12 Correct 4 ms 512 KB Output is correct
13 Correct 3 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 740 KB Output is correct
2 Correct 10 ms 1280 KB Output is correct
3 Correct 13 ms 2176 KB Output is correct
4 Correct 30 ms 3960 KB Output is correct
5 Correct 57 ms 7532 KB Output is correct
6 Correct 128 ms 14968 KB Output is correct
7 Correct 260 ms 22796 KB Output is correct