Submission #60491

#TimeUsernameProblemLanguageResultExecution timeMemory
60491junodevelopermedians (balkan11_medians)C++17
100 / 100
65 ms3244 KiB
#include <bits/stdc++.h>
#define SZ(x) ((int)x.size())
#define ALL(x) (x).begin(), (x).end()
using namespace std;
int n, b[100010], a[200010], c1,c2;
bool chk[200010];
int getc1() { while(c1 <=2*n-1 && chk[c1]) c1++; return c1; }
int getc2() { while(c2 && chk[c2]) c2--; return c2; }
int main() {
	scanf("%d", &n);
	c1 = 1, c2 = 2*n-1;
	for(int i=1; i<=n; i++) {
		scanf("%d", b+i);
		if(i == 1) {
			chk[a[1] = b[i]] = 1;
			continue;
		}
		if(b[i-1] > b[i]) {
			if(!chk[b[i]]) chk[a[2*(i-1)] = b[i]] = chk[a[2*(i-1)+1] = getc1()] = 1;
			else chk[a[2*(i-1)] = getc1()] = chk[a[2*(i-1)+1] = getc1()] = 1;
		} else if(b[i-1] < b[i]) {
			if(!chk[b[i]]) chk[a[2*(i-1)] = b[i]] = chk[a[2*(i-1)+1] = getc2()] = 1;
			else chk[a[2*(i-1)] = getc2()] = chk[a[2*(i-1)+1] = getc2()] = 1;
		} else chk[a[2*(i-1)] = getc1()] = chk[a[2*(i-1)+1] = getc2()] = 1;
	}
	for(int i=1; i<2*n; i++) printf("%d ", a[i]);
	return 0;
}

Compilation message (stderr)

medians.cpp: In function 'int main()':
medians.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
medians.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", b+i);
   ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...