# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
850312 | 2023-09-16T10:20:33 Z | ssense | 중앙값 배열 (balkan11_medians) | C++14 | 58 ms | 13140 KB |
#include <bits/stdc++.h> #define startt ios_base::sync_with_stdio(false);cin.tie(0); typedef long long ll; using namespace std; #define vint vector<int> #define all(v) v.begin(), v.end() #define MOD 1000000007 #define MOD2 998244353 #define MX 1000000000 #define MXL 1000000000000000000 #define PI (ld)2*acos(0.0) #define pb push_back #define sc second #define fr first #define int long long #define endl '\n' #define ld long double #define NO cout << "NO" << endl #define YES cout << "YES" << endl int ceildiv(int one, int two) {if (one % two == 0) {return one / two;}else {return one / two + 1;}} int power(int n, int pow, int m) {if (pow == 0) return 1;if (pow % 2 == 0) {ll x = power(n, pow / 2, m);return (x * x) % m;}else return (power(n, pow - 1, m) * n) % m;} int gcd(int a, int b) { if (!b)return a; return gcd(b, a % b);} int factorial(int n, int mod) {if (n > 1)return (n * factorial(n - 1, mod)) % mod; else return 1;} int lcm(int a, int b) {return (a * b) / gcd(a, b);} vector<int> read(int n) {vector<int> a; for (int i = 0; i < n; i++) { int x; cin >> x; a.pb(x);} return a;}struct prefix_sum{vint pref;void build(vint a){pref.pb(0);for(int i = 0; i < a.size(); i++){pref.pb(pref.back()+a[i]);}}int get(int l, int r){return pref[r]-pref[l-1];}};//mesanu void solve() { int n; cin >> n; deque<int> smaller, bigger; vector<int> perm(2*n); set<int> aval; for(int i = 1; i <= 2*n-1; i++) { aval.insert(i); } int last = -1; for(int i = 0; i < n; i++) { int med; cin >> med; if(i == 0) { perm[1] = med; last = med; aval.erase(med); } else { if(last == med) { perm[2*i] = *aval.begin(); aval.erase(aval.begin()); perm[2*i+1] = *prev(aval.end()); aval.erase(prev(aval.end())); } else if(last > med) { if(!aval.count(med)) { perm[2*i] = *aval.begin(); aval.erase(aval.begin()); perm[2*i+1] = *aval.begin(); aval.erase(aval.begin()); } else { perm[2*i] = med; aval.erase(med); perm[2*i+1] = *aval.begin(); aval.erase(aval.begin()); } } else if(last < med) { if(!aval.count(med)) { perm[2*i] = *prev(aval.end()); aval.erase(prev(aval.end())); perm[2*i+1] = *prev(aval.end()); aval.erase(prev(aval.end())); } else { perm[2*i] = med; aval.erase(med); perm[2*i+1] = *prev(aval.end()); aval.erase(prev(aval.end())); } } last = med; } } for(int i = 1; i <= 2*n-1; i++) { cout << perm[i] << " "; } cout << endl; } int32_t main(){ startt int t = 1; //cin >> t; while (t--) { solve(); } } /* 5 1 3 3 4 5 */
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 344 KB | Output is correct |
2 | Correct | 0 ms | 348 KB | Output is correct |
3 | Correct | 0 ms | 348 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 0 ms | 348 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 1 ms | 708 KB | Output is correct |
10 | Correct | 0 ms | 348 KB | Output is correct |
11 | Correct | 1 ms | 344 KB | Output is correct |
12 | Correct | 1 ms | 348 KB | Output is correct |
13 | Correct | 1 ms | 348 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 1 ms | 604 KB | Output is correct |
2 | Correct | 2 ms | 860 KB | Output is correct |
3 | Correct | 5 ms | 1368 KB | Output is correct |
4 | Correct | 9 ms | 2332 KB | Output is correct |
5 | Correct | 20 ms | 4524 KB | Output is correct |
6 | Correct | 35 ms | 8528 KB | Output is correct |
7 | Correct | 58 ms | 13140 KB | Output is correct |