QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#715454 | #8837. Increasing Income | IllusionaryWhiteTraveler | WA | 1ms | 5804kb | C++20 | 1.5kb | 2024-11-06 12:10:53 | 2024-11-06 12:10:54 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 200000 + 5;
int N, M, p[MAX_N], q[MAX_N], f[MAX_N], pre[MAX_N];
void solve() {
M = 0;
cin >> N;
for (int i = 1; i <= N; i ++) {
cin >> p[i]; q[p[i]] = i;
int pos = lower_bound(f + 1, f + M + 1, p[i]) - f;
if (M < pos) M = pos;
f[pos] = p[i];
pre[i] = q[f[pos - 1]];
}
vector <int> keypos(0), ans(0);
for (int i = q[f[M]]; i; i = pre[i]) keypos.emplace_back(i);
assert((int)keypos.size() == M);
reverse(keypos.begin(), keypos.end());
priority_queue <pair <int, int>> pq;
for (int i = 1, j = 0, k = keypos[0]; i <= N; i ++) {
if (j < (int)keypos.size() && keypos[j] == i) {
ans.emplace_back(i); k = keypos[++ j];
while (!pq.empty() && (j == (int)keypos.size() || keypos[j] + pq.top().first > 0)) {
ans.emplace_back(pq.top().second); pq.pop();
}
}else {
if (p[i] < k) {
ans.emplace_back(i);
}else {
pq.push(pair(-p[i], i));
}
}
}
while (!pq.empty()) {
ans.emplace_back(pq.top().second); pq.pop();
}
assert((int)ans.size() == N);
for (int i = 0; i < N; i ++) {
cout << ans[i] << "\n "[i != N - 1];
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T = 1;
cin >> T;
while (T --) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5804kb
input:
3 3 1 2 3 4 2 4 3 1 5 1 5 2 4 3
output:
1 2 3 1 3 2 4 1 3 4 5 2
result:
ok Correct (3 test cases)
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5588kb
input:
153 4 2 4 3 1 4 1 4 2 3 5 2 1 4 5 3 5 1 4 5 3 2 4 1 3 2 4 5 1 5 2 4 3 5 5 3 1 2 4 5 4 1 2 5 3 5 1 2 5 3 4 5 3 1 4 2 5 5 5 4 2 3 1 5 2 1 5 4 3 5 3 4 1 5 2 5 1 4 3 5 2 5 5 1 3 4 2 5 5 3 2 4 1 5 1 5 3 2 4 5 2 4 3 1 5 5 1 5 4 3 2 5 1 2 4 5 3 5 4 2 5 3 1 5 1 3 5 2 4 5 3 1 4 5 2 3 2 1 3 5 1 2 4 3 5 5 5 1 ...
output:
1 3 2 4 1 3 4 2 2 1 3 4 5 1 2 3 5 4 1 3 2 4 1 3 4 5 2 3 2 4 5 1 2 3 1 5 4 1 2 4 5 3 2 1 4 3 5 3 4 2 1 5 2 1 4 5 3 1 2 3 4 5 1 3 4 2 5 2 3 4 1 5 3 2 4 1 5 1 3 4 5 2 1 3 2 4 5 1 3 4 5 2 1 2 3 4 5 2 4 1 3 5 1 2 4 5 3 2 3 1 4 5 2 1 3 1 2 4 3 5 2 3 4 5 1 3 1 4 5 2 3 2 4 5 1 2 3 1 2 1 4 3 1 2 3 4 3 1 4 2 ...
result:
wrong answer Jury found better answer than participant (test case 4)