ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#214959 | #3856. 排序 | 13270460609 | 70 | 401ms | 3408kb | C++ | 2.0kb | 2024-11-24 12:57:45 | 2024-11-24 13:16:32 |
answer
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
const int maxn = 1e5 + 5;
#define mid (l + r >> 1)
int n, tot, ls[maxn * 100], rs[maxn * 100], seg[maxn * 100];
void update(int &p, int l, int r, int s, int t, int val) {
if (r < s || t < l) return;
if (!p) seg[p = ++tot] = -1;
if (seg[p] >= val) return;
if (s <= l && r <= t) return void(seg[p] = max(seg[p], val));
update(ls[p], l, mid, s, t, val), update(rs[p], mid + 1, r, s, t, val);
return;
}
int query(int p, int l, int r, int s, int t) {
if (r < s || t < l || !p) return -1;
if (s <= l && r <= t) return seg[p];
return max(max(query(ls[p], l, mid, s, t), query(rs[p], mid + 1, r, s, t)), seg[p]);
}
#define lp (p << 1)
#define rp (p << 1 | 1)
int rt[maxn << 2];
void modify(int p, int l, int r, int s, int t, int ql, int qr, int val) {
if (r < s || t < l) return;
if (s <= l && r <= t) return update(rt[p], 1, n, ql, qr, val);
modify(lp, l, mid, s, t, ql, qr, val), modify(rp, mid + 1, r, s, t, ql, qr, val);
return;
}
int query(int p, int l, int r, int pos, int s, int t) {
if (l == r) return query(rt[p], 1, n, s, t);
if (pos <= mid) return max(query(rt[p], 1, n, s, t), query(lp, l, mid, pos, s, t));
else return max(query(rt[p], 1, n, s, t), query(rp, mid + 1, r, pos, s, t));
}
#undef lp
#undef rp
#undef mid
int a[maxn];
int ans, dp[maxn];
int top, stack[maxn], nxt[maxn];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", a + i);
memset(dp, -1, sizeof(dp));
dp[0] = 0;
for (int i = 0; i <= n; i++) {
if (!(~dp[i])) continue;
ans = max(ans, dp[i]);
int j;
for (j = i + 1; a[i] >= a[j] && j <= n; j++);
if (j <= n) {
dp[j] = max(dp[j], dp[i] + 1);
for (int k = j + 1; a[j] >= a[k] && k <= n; k++)
if (a[i] < a[k]) dp[k] = max(dp[k], dp[i] + 1);
}
}
printf("%d\n", ans);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Subtask #1:
score: 20
Accepted
Test #1:
score: 20
Accepted
time: 0ms
memory: 1584kb
input:
475 319 474 473 472 471 183 108 346 43 466 465 464 168 462 461 309 459 458 457 456 455 38 372 312 94...
output:
11
result:
ok 1 number(s): "11"
Test #2:
score: 0
Accepted
time: 0ms
memory: 1588kb
input:
469 96 407 467 466 240 146 463 462 119 261 459 304 266 456 385 454 453 452 79 450 133 400 447 123 21...
output:
10
result:
ok 1 number(s): "10"
Test #3:
score: 0
Accepted
time: 1ms
memory: 1584kb
input:
492 139 64 490 25 488 61 486 133 167 483 482 124 88 479 100 220 476 475 474 90 112 273 470 16 468 46...
output:
17
result:
ok 1 number(s): "17"
Test #4:
score: 0
Accepted
time: 0ms
memory: 1588kb
input:
480 480 479 328 477 410 112 125 44 472 26 470 469 468 24 92 342 68 463 462 191 460 459 62 457 114 45...
output:
19
result:
ok 1 number(s): "19"
Subtask #2:
score: 50
Accepted
Test #5:
score: 50
Accepted
time: 0ms
memory: 1600kb
input:
3838 27 26 25 24 23 22 21 20 19 18 17 16 997 14 3442 12 11 10 9 8 7 2498 5 4 3 2 1 2834 2833 2832 28...
output:
25
result:
ok 1 number(s): "25"
Test #6:
score: 0
Accepted
time: 0ms
memory: 1600kb
input:
3734 594 15 14 13 12 11 2581 1179 8 2073 6 5 4 3 2 1 45 44 43 42 41 40 39 38 37 36 35 34 146 32 1536...
output:
18
result:
ok 1 number(s): "18"
Test #7:
score: 0
Accepted
time: 0ms
memory: 1596kb
input:
3813 3769 3768 3767 3766 3765 3764 3763 3762 3558 3760 985 3758 3757 3756 3755 3754 3753 2121 3751 3...
output:
15
result:
ok 1 number(s): "15"
Test #8:
score: 0
Accepted
time: 0ms
memory: 1596kb
input:
3828 1791 1790 1021 1788 1787 1042 1785 1784 1783 1782 2875 1780 2445 1778 1777 1776 1775 1774 1773 ...
output:
22
result:
ok 1 number(s): "22"
Subtask #3:
score: 0
Time Limit Exceeded
Test #9:
score: 0
Time Limit Exceeded
input:
499758 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 ...
output:
result:
Subtask #4:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 400ms
memory: 3408kb
input:
466818 447360 121353 327541 289718 71942 242279 307652 438765 78054 253024 190170 21720 292462 72832...
output:
466884
result:
wrong answer 1st numbers differ - expected: '32', found: '466884'
Subtask #5:
score: 0
Skipped