Submission #39703

# Submission time Handle Problem Language Result Execution time Memory
39703 2018-01-17T12:16:09 Z Pajaraja medians (balkan11_medians) C++14
100 / 100
69 ms 7872 KB
#include <bits/stdc++.h>
using namespace std;
bool u[200007],k[200007];
int b[100007],add;
vector<int> ub[100007];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&b[i]);
	priority_queue<int> g,l;
	//for(int i=0;i<n-1;i++) for(int j=fmin(b[i],b[i+1]);j<fmax(b[i],b[i+1]);j++) k[j]=true;
	for(int i=1;i<2*n;i++) if(!k[i])
	{
		g.push(i);
		l.push(-i);
	} 
	u[b[0]]=true;
	add=1;
	printf("%d ",b[0]);
	for(int i=0;i<n-1;i++)
	{
		if(!u[b[i+1]])
		{
		    u[b[i+1]]=true;
	        add++;
	        printf("%d ",b[i+1]);
		}
		if(b[i]>b[i+1])
		{
			while(add<2*i+3)
			{
				int c=-l.top();
				l.pop();
				if(u[c]) continue;
				u[c]=true;
	            add++;
	            printf("%d ",c);
			}
		}
		if(b[i]==b[i+1])
		{
			while(add<2*i+2)
			{
				int c=-l.top();
				l.pop();
				if(u[c]) continue;
				u[c]=true;
	            add++;
	            printf("%d ",c);
			}
			while(add<2*i+3)
			{
				int c=g.top();
				g.pop();
				if(u[c]) continue;
				u[c]=true;
	            add++;
	            printf("%d ",c);
			}
		}
		if(b[i]<b[i+1])
		{
			while(add<2*i+3)
			{
				int c=g.top();
				g.pop();
				if(u[c]) continue;
				u[c]=true;
	            add++;
	            printf("%d ",c);
			}
		}
		/*for(int j=fmin(b[i],b[i+1]);j<fmax(b[i],b[i+1]);j++)
		{
		    g.push(j);
		    l.push(-j);	
		}*/
	}
}

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:9:16: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d",&n);
                ^
medians.cpp:10:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=0;i<n;i++) scanf("%d",&b[i]);
                                        ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5140 KB Output is correct
2 Correct 0 ms 5140 KB Output is correct
3 Correct 0 ms 5140 KB Output is correct
4 Correct 0 ms 5140 KB Output is correct
5 Correct 0 ms 5140 KB Output is correct
6 Correct 0 ms 5140 KB Output is correct
7 Correct 0 ms 5140 KB Output is correct
8 Correct 0 ms 5140 KB Output is correct
9 Correct 0 ms 5140 KB Output is correct
10 Correct 0 ms 5140 KB Output is correct
11 Correct 0 ms 5140 KB Output is correct
12 Correct 0 ms 5140 KB Output is correct
13 Correct 0 ms 5140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 5140 KB Output is correct
2 Correct 0 ms 5300 KB Output is correct
3 Correct 6 ms 5300 KB Output is correct
4 Correct 6 ms 5432 KB Output is correct
5 Correct 13 ms 5820 KB Output is correct
6 Correct 29 ms 6592 KB Output is correct
7 Correct 69 ms 7872 KB Output is correct