Submission #39702

# Submission time Handle Problem Language Result Execution time Memory
39702 2018-01-17T12:03:08 Z Pajaraja medians (balkan11_medians) C++14
100 / 100
183 ms 15556 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 5144 KB Output is correct
2 Correct 0 ms 5144 KB Output is correct
3 Correct 0 ms 5144 KB Output is correct
4 Correct 0 ms 5144 KB Output is correct
5 Correct 0 ms 5144 KB Output is correct
6 Correct 0 ms 5144 KB Output is correct
7 Correct 0 ms 5144 KB Output is correct
8 Correct 0 ms 5144 KB Output is correct
9 Correct 0 ms 5144 KB Output is correct
10 Correct 0 ms 5144 KB Output is correct
11 Correct 0 ms 5144 KB Output is correct
12 Correct 0 ms 5144 KB Output is correct
13 Correct 0 ms 5144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 5304 KB Output is correct
2 Correct 0 ms 5436 KB Output is correct
3 Correct 13 ms 6340 KB Output is correct
4 Correct 26 ms 6516 KB Output is correct
5 Correct 46 ms 7876 KB Output is correct
6 Correct 99 ms 10436 KB Output is correct
7 Correct 183 ms 15556 KB Output is correct