# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
24859 | 2017-06-16T08:26:28 Z | chpipis | medians (balkan11_medians) | C++11 | 133 ms | 22736 KB |
#include <bits/stdc++.h> using namespace std; #define fi first #define se second #define mp make_pair #define pb push_back #define pf push_front #define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++) #define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL) #define all(v) (v).begin(), (v).end() #define rep(i, s, e) for (int i = s; i < e; i++) #ifdef __linux__ #define gc getchar_unlocked #define pc putchar_unlocked #else #define gc getchar #define pc putchar #endif #if __cplusplus <= 199711L template<class BidirIt> BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) { advance(it, -n); return it; } template<class ForwardIt> ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) { advance(it, n); return it; } #endif typedef long long ll; typedef pair<int, int> ii; typedef vector<int> vi; typedef vector<ii> vii; typedef long double ldouble; const double EPS = 1e-9; const double PI = 3.141592653589793238462; template<typename T> inline T sq(T a) { return a * a; } //#ifdef LOCAL_MACHINE //#endif const int MAXN = 2e5 + 5; #define left agqwq #define right tqwpwep int which[MAXN]; vi prv[MAXN], nxt[MAXN]; int left, right; set<int> exist; void updateLeft() { while (*exist.upper_bound(left) - left - 1 == (int)nxt[left].size()) { for (int j = 0; j < (int)nxt[left].size(); j++) { which[nxt[left][j]] = left + j + 1; exist.insert(left + j + 1); } left += (int)nxt[left].size() + 1; } } void updateRight() { while (right - *prev(exist.find(right)) - 1 == (int)prv[right].size()) { for (int j = 0; j < (int)prv[right].size(); j++) { which[prv[right][j]] = right - j - 1; exist.insert(right - j - 1); } right -= (int)prv[right].size() + 1; } } int main() { //freopen("", "r", stdin); //freopen("", "w", stdout); int n; scanf("%d", &n); left = 0; right = 2 * n; exist.insert(0); exist.insert(2 * n); int x; scanf("%d", &x); int last = x; exist.insert(x); which[1] = x; updateLeft(); updateRight(); for (int i = 2; i <= n; i++) { scanf("%d", &x); if (x == last) { nxt[left].pb(2 * i - 2); prv[right].pb(2 * i - 1); } else if (x > last) { if (!exist.count(x)) { exist.insert(x); which[2 * i - 1] = x; updateLeft(); updateRight(); } else { prv[right].pb(2 * i - 1); updateLeft(); updateRight(); } prv[right].pb(2 * i - 2); } else { if (!exist.count(x)) { exist.insert(x); which[2 * i - 1] = x; updateLeft(); updateRight(); } else { nxt[left].pb(2 * i - 1); updateLeft(); updateRight(); } nxt[left].pb(2 * i - 2); } updateLeft(); updateRight(); last = x; } for (int i = 1; i <= 2 * n - 1; i++) printf("%d ", which[i]); puts(""); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 12180 KB | Output is correct |
2 | Correct | 3 ms | 12180 KB | Output is correct |
3 | Correct | 0 ms | 12180 KB | Output is correct |
4 | Correct | 3 ms | 12180 KB | Output is correct |
5 | Correct | 0 ms | 12180 KB | Output is correct |
6 | Correct | 3 ms | 12180 KB | Output is correct |
7 | Correct | 3 ms | 12180 KB | Output is correct |
8 | Correct | 3 ms | 12180 KB | Output is correct |
9 | Correct | 3 ms | 12180 KB | Output is correct |
10 | Correct | 0 ms | 12180 KB | Output is correct |
11 | Correct | 3 ms | 12180 KB | Output is correct |
12 | Correct | 3 ms | 12312 KB | Output is correct |
13 | Correct | 3 ms | 12312 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 12444 KB | Output is correct |
2 | Correct | 0 ms | 12576 KB | Output is correct |
3 | Correct | 9 ms | 13104 KB | Output is correct |
4 | Correct | 19 ms | 13896 KB | Output is correct |
5 | Correct | 39 ms | 15492 KB | Output is correct |
6 | Correct | 93 ms | 18916 KB | Output is correct |
7 | Correct | 133 ms | 22736 KB | Output is correct |