답안 #39711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
39711 2018-01-17T14:40:08 Z MladenP 중앙값 배열 (balkan11_medians) C++14
60 / 100
19 ms 2760 KB
#include<bits/stdc++.h>
#define STIZE(x) fprintf(stderr, "STIZE%d\n", x);
#define PRINT(x) fprintf(stderr, "%s = %d\n", #x, x);
#define NL(x) printf("%c", " \n"[(x)]);
#define lld long long
#define pii pair<int,int>
#define pb push_back
#define fi first
#define se second
#define endl '\n'
#define mid (l+r)/2
#define all(a) begin(a),end(a)
#define sz(a) int((a).size())
#define LINF 1000000000000000000LL
#define INF 1000000000
#define EPS 1e-9
using namespace std;
#define MAXN 100010
int n, b[MAXN], l, r;
bool pos[2*MAXN];
void upd() {
    while(l < r && pos[l]) l++;
    while(l < r && pos[r]) r--;
}
int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> b[i];
    l = 1, r = 2*n-1, pos[b[1]] = 1;
    cout << b[1] << ' ';
    for(int i = 2; i <= n; i++) {
        upd();
        if(b[i] == b[i-1]) {
            pos[l] = pos[r] = 1;
            cout << l << ' ' << r << ' ';
        } else if(b[i] > b[i-1]) {
            if(pos[b[i]]) {
                cout << r << ' ';
                pos[r] = 1;
                upd();
                cout << r << ' ';
                pos[r] = 1;
            } else {
                pos[b[i]] = pos[r] = 1;
                cout << b[i] << ' ' << r << ' ';
            }
        } else {
            if(pos[b[i]]) {
                cout << l << ' ';
                pos[l] = 1;
                upd();
                cout << l << ' ';
                pos[l] = 1;
            } else {
                pos[b[i]] = pos[l] = 1;
                cout << b[i] << ' ' << l << ' ';
            }
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 2760 KB Output is correct
2 Correct 0 ms 2760 KB Output is correct
3 Correct 0 ms 2760 KB Output is correct
4 Correct 0 ms 2760 KB Output is correct
5 Correct 0 ms 2760 KB Output is correct
6 Correct 0 ms 2760 KB Output is correct
7 Correct 0 ms 2760 KB Output is correct
8 Correct 0 ms 2760 KB Output is correct
9 Correct 0 ms 2760 KB Output is correct
10 Correct 0 ms 2760 KB Output is correct
11 Correct 0 ms 2760 KB Output is correct
12 Correct 0 ms 2760 KB Output is correct
13 Runtime error 0 ms 2760 KB Execution killed because of forbidden syscall writev (20)
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 2760 KB Execution killed because of forbidden syscall writev (20)
2 Runtime error 0 ms 2760 KB Execution killed because of forbidden syscall writev (20)
3 Runtime error 0 ms 2760 KB Execution killed because of forbidden syscall writev (20)
4 Runtime error 0 ms 2760 KB Execution killed because of forbidden syscall writev (20)
5 Runtime error 0 ms 2760 KB Execution killed because of forbidden syscall writev (20)
6 Runtime error 6 ms 2760 KB Execution killed because of forbidden syscall writev (20)
7 Runtime error 19 ms 2760 KB Execution killed because of forbidden syscall writev (20)