int n;//input size of array
cin >> n;
vector <int> a(n);
vector <int> in;
for (int i = 0; i < n; i++)
cin >> a[i];//input array elements
if (n == 1) {
cout << "1" << "\n";
return 0;
}
for (int i = 1; i <= n ; i++)//to get longest incresing subsequence in the array
{
int flag = 0, j = i;
while (j < n && a[j] >= a[j - 1] ) {
j++;
flag = 1;
}
if (flag == 1) {
in.push_back(j - i + 1);
i = j;
}
}
int maxval = in[0]; //to get maximum sized element from in
for (int i = 1; i < in.size(); i++)
if (in[i] > maxval)
maxval = in[i];
cout << maxval << "\n";
我为 < 10000 的值尝试了相同的代码,它工作正常...我已经用 long long int 替换了所有 int 然后它还显示矢量下标超出范围错误...
样本输入:
10
49532 49472 49426 49362 49324 49247 49165 49162 49108 49093
我期待 0 但它显示“向量下标超出范围”