源代码如下:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#define maxn 10000010
using namespace std;
//用前缀和?
int a[maxn];
int b[maxn] = {0};
int temp;
int i = 1; //从1开始计数
int last = 1;
void sss() {
for (int j = 1; j <= last; j++) {
cout << b[j] << ' ';
}
cout << endl;
}
int main() {
int n;
cin >> n;
for (int j = 1; j <= n; j++) {
cin >> a[j];
}
// while (scanf("%d", &temp) != EOF) {
// a[i++] = temp;
// }
b[last] = a[1];
for (int j = 2; j <= n; j++) {
if (b[last] >= a[j]) {
last++;
b[last] = a[j];
// cout << 1 << endl;
} else {
// cout << a[j] << endl;
// sss();
int p = upper_bound(b + 1, b + last + 1, a[j]) - b;
b[p] = a[j];
}
}
cout << last << endl;
return 0;
}
数据如下;
389 207 155 300 299 170 158 65
我尝试输出第一次的p,结果显示是0。
是哪里错了吗???
我是真没发现
哭了