Submission #330767

# Submission time Handle Problem Language Result Execution time Memory
330767 2020-11-26T13:56:05 Z BeanZ medians (balkan11_medians) C++14
100 / 100
32 ms 3564 KB
// I_Love_LPL
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define endl '\n'
const int N = 2e5 + 5;
const int lg = 60;
const int mod = 998244353;
const long long oo = 1e18;
const int lim = 1e6 + 5;
long double eps = 1e-3;
ll vis[N], b[N], a[N];
ll l, r;
void addl(ll id){
    while (vis[l]) l++;
    b[id] = l;
    vis[l] = 1;
}
void addr(ll id){
    while (vis[r]) r--;
    b[id] = r;
    vis[r] = 1;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    if (fopen("test.inp", "r")){
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    ll n;
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    b[1] = a[1];
    vis[b[1]] = 1;
    l = 1, r = 2 * n - 1;
    for (int i = 2; i <= n; i++){
        if (a[i] == a[i - 1]){
            addl(i * 2 - 2);
            addr(i * 2 - 1);
        } else if (a[i] > a[i - 1]){
            if (vis[a[i]]){
                addr(i * 2 - 2);
                addr(i * 2 - 1);
            } else {
                vis[a[i]] = 1;
                b[i * 2 - 2] = a[i];
                addr(i * 2 - 1);
            }
        } else {
            if (vis[a[i]]){
                addl(i * 2 - 2);
                addl(i * 2 - 1);
            } else {
                vis[a[i]] = 1;
                b[i * 2 - 2] = a[i];
                addl(i * 2 - 1);
            }
        }
    }
    for (int i = 1; i <= (2 * n - 1); i++) cout << b[i] << " ";
}
/*
*/

Compilation message

medians.cpp: In function 'int main()':
medians.cpp:28:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   28 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
medians.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   29 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2 ms 492 KB Output is correct
3 Correct 3 ms 620 KB Output is correct
4 Correct 6 ms 900 KB Output is correct
5 Correct 11 ms 1388 KB Output is correct
6 Correct 20 ms 2540 KB Output is correct
7 Correct 32 ms 3564 KB Output is correct