函数部分中,将
int hil = t[ans];
这一步删去,直接使用
t[ans]代替hil,评测时会从全AC变为2AC 3WA。
对于这一点感到困惑,希望能够得到解答。
#include<iostream>
using namespace std;
int H[100001];
void qp(int x, int y, int t[])
{
int ans = (y + x) / 2; int hil = t[ans];
int m = x, n = y;
for (;m<=n;)
{
for (; t[m] < hil; m++);
for (; t[n] > hil; n--);
if (m <= n)
{
int r = t[m];
t[m] = t[n];
t[n] = r;
m++; n--;
}
}
if (m<y)
{qp(m, y,t);}
if (n>x)
{qp(x, n, t);}
}
以下是两次评测链接:
https://www.luogu.com.cn/record/51914326
https://www.luogu.com.cn/record/51914546