蹲个大佬帮我看看
这样写有啥问题?
小白十分的感谢////敬礼
# include<bits/stdc++.h>
# define int long long
using namespace std;
int n;
signed main()
{
cin >> n;
priority_queue<int, vector<int>, less<int> > heap;
int a[600010];
int k = 1;
for(int i = 1 ; i <= n ; i ++)
cin >> a[i];
int i = 1, j = n;
while(i <= j)
{
if (heap.empty())
{
if (a[i] == a[j])
{
heap.push(a[i]);
i ++;
j --;
}
else if (a[i] < a[j]) heap.push(a[i ++]);
else heap.push(a[j --]);
}
else
{
if (a[i] == a[j])
{
if (a[i] > heap.top())
{
heap.push(a[i]);
i ++;
j --;
}
else break;
}
else if (a[i] < a[j])
{
if (a[i] > heap.top())
heap.push(a[i ++]);
else// 左边堵塞
while (a[j] > heap.top())
heap.push(a[j --]);
}
else if (a[i] > a[j])
{
if (a[j] > heap.top())
heap.push(a[j --]);
else// 右边堵塞
while (a[i] > heap.top())
heap.push(a[i ++]);
}
// 队列不能装下更多的数了
if (max(a[i], a[j]) <= heap.top()) break;
}
}
cout << heap.size() << endl;
return 0;
}
if (heap.empty())
{
if (a[i] == a[j])
{
heap.push(a[i]);
i ;
j –;
}
else if (a[i] < a[j]) heap.push(a[i ]);
else heap.push(a[j –]);
}
只能放其中一个,因为要保证严格递增