#include <bits/stdc++.h>
using namespace std;
#define MAX 302020
int l[MAX], r[MAX];
int tree[MAX];
int arr[MAX];
int s, d;
vector<int>ans;
set<int>S;
void update(int loc) {
ans.push_back(loc);
arr[loc] = 1;
S.erase(loc);
loc += s - 1;
while (loc > 0) {
tree[loc]++;
loc /= 2;
}
}
int sumquery(int low, int high, int loc = 1) {
int l, r;
int ll, rr;
int a = (d - (int)(log2(loc)));
l = (loc - (1 << (int)(log2(loc)))) << a;
r = l + (1 << a) - 1;
rr = (l + r) / 2;
ll = rr + 1;
l++;
r++;
ll++;
rr++;
if (l == low && r == high) return tree[loc];
else if (rr >= high) return sumquery(low, high, loc * 2);
else if (ll <= low) return sumquery(low, high, loc * 2 + 1);
else return sumquery(low, rr, loc * 2) + sumquery(ll, high, loc * 2 + 1);
}
int minn() {
return *S.begin();
}
int maxn() {
set<int>::iterator it;
it = S.end();
it--;
return *it;
}
int main(void) {
int N;
cin >> N;
s = 1 << (int)ceil(log2(2 * N - 1));
d = (int)log2(s);
int i;
for (i = 1; i <= 2 * N - 1; i++) S.insert(i);
int a;
cin >> a;
update(a);
for (i = 1; i <= N - 1; i++) {
cin >> a;
if (arr[a] == 0) update(a);
while (sumquery(1, a) < (i + 1)) update(minn());
while (sumquery(a, 2 * N - 1) < (i + 1)) update(maxn());
}
for (auto i : ans) cout << i << endl;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
3 ms |
364 KB |
Output is correct |
12 |
Correct |
6 ms |
364 KB |
Output is correct |
13 |
Correct |
10 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
620 KB |
Output is correct |
2 |
Correct |
44 ms |
876 KB |
Output is correct |
3 |
Correct |
91 ms |
1408 KB |
Output is correct |
4 |
Correct |
191 ms |
2412 KB |
Output is correct |
5 |
Execution timed out |
407 ms |
4588 KB |
Time limit exceeded |
6 |
Execution timed out |
838 ms |
8684 KB |
Time limit exceeded |
7 |
Execution timed out |
1090 ms |
12780 KB |
Time limit exceeded |