ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#167197 | #46. delete | zzh090309 | 100 | 571ms | 16784kb | C++ | 1.4kb | 2022-12-25 20:42:08 | 2022-12-25 20:42:11 |
answer
#include<bits/stdc++.h>
using namespace std;
int f[1000006], b[2000006], n, m, ans;
struct node {
int num, name;
} a[1000006];
int readNum() {
int x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') {
x = (x << 1) + (x << 3) + (ch ^ 48);
ch = getchar();
}
return x * f;
}
void writeNum(int x) {
if (x < 0) {
putchar('-');
x = -x;
}
if (x > 9) {
writeNum(x / 10);
}
putchar(x % 10 + '0');
}
inline void in(int& p) {
p = readNum();
}
inline void out(int p) {
writeNum(p);
}
inline int lowbit(int p) {
return p & -p;
}
inline void add(int p, int q) {
while (p <= 2 * n) {
b[p] = max(b[p], q);
p += lowbit(p);
}
}
inline int query(int p) {
if (p <= 0) return 0;
int cnt = 0;
while (p >= 1) {
cnt = max(cnt, b[p]);
p -= lowbit(p);
}
return cnt;
}
bool cmp(node p, node q) {
return (p.num == q.num) ? p.name < q.name : p.num < q.num;
}
int main() {
in(n);
in(m);
for (int i = 1; i <= n; i++) {
in(a[i].num);
a[i].num = i - a[i].num;
a[i].name = i;
}
sort(a + 1, a + n + 1, cmp);
for (int i = 1; i <= n; i++) {
if (a[i].num < 0) {
f[i] = 0;
continue;
}
f[i] = query(a[i].name - a[i].num) + 1;
add(a[i].name - a[i].num + 1, f[i]);
if (a[i].num <= m && n - a[i].name >= m - a[i].num) {
ans = max(ans, f[i]);
}
}
out(ans);
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 10
Accepted
time: 0ms
memory: 1144kb
input:
20 8 11 9 10 2 4 8 7 4 9 8 12 1 3 12 7 9 9 16 3 15
output:
4
result:
ok single line: '4'
Test #2:
score: 10
Accepted
time: 0ms
memory: 1144kb
input:
20 10 1 12 11 1 2 7 10 2 13 4 11 14 8 15 4 6 1 3 5 12
output:
4
result:
ok single line: '4'
Test #3:
score: 10
Accepted
time: 0ms
memory: 1152kb
input:
500 150 7 2 11 5 1 13 10 10 14 20 20 2 5 17 14 4 5 5 3 2 2 7 10 3 18 2 7 3 5 15 2 8 5 14 3 1 1 4 19 ...
output:
27
result:
ok single line: '27'
Test #4:
score: 10
Accepted
time: 0ms
memory: 1152kb
input:
500 233 8 16 14 3 7 1 14 15 11 8 4 11 13 6 5 18 2 11 10 5 7 3 14 2 7 16 6 5 14 1 13 6 9 7 9 5 5 6 2 ...
output:
26
result:
ok single line: '26'
Test #5:
score: 10
Accepted
time: 0ms
memory: 1228kb
input:
5000 1666 15 23 11 4 10 16 24 9 10 10 9 14 7 3 1 22 4 8 7 18 3 24 19 6 2 16 2 5 7 10 6 12 1 6 18 9 6...
output:
120
result:
ok single line: '120'
Test #6:
score: 10
Accepted
time: 0ms
memory: 1228kb
input:
5000 2333 2 28 15 6 10 2 10 10 26 7 8 16 3 1 15 17 11 7 8 2 8 2 6 3 4 13 6 20 13 18 3 6 24 1 5 26 18...
output:
120
result:
ok single line: '120'
Test #7:
score: 10
Accepted
time: 22ms
memory: 2720kb
input:
100000 23333 158 127 191 174 144 43 80 135 48 54 91 22 135 145 32 109 180 16 51 47 86 69 26 121 161 ...
output:
596
result:
ok single line: '596'
Test #8:
score: 10
Accepted
time: 22ms
memory: 2720kb
input:
100000 55555 81 122 1 146 76 142 36 207 127 17 5 102 123 42 69 15 42 137 94 107 101 49 179 44 48 78 ...
output:
444
result:
ok single line: '444'
Test #9:
score: 10
Accepted
time: 260ms
memory: 16784kb
input:
1000000 233333 536 132 387 278 660 779 239 1629 535 1641 1374 532 53 840 432 180 1457 232 494 580 61...
output:
1819
result:
ok single line: '1819'
Test #10:
score: 10
Accepted
time: 267ms
memory: 16784kb
input:
1000000 666666 1053 405 264 292 1304 414 58 948 985 1112 865 1225 982 595 927 701 623 666 43 1019 43...
output:
1187
result:
ok single line: '1187'
Extra Test:
score: 0
Extra Test Passed