include [HTML_REMOVED]
int a[1005];
void swap(int i, int j)
{
if (i ^ j)
{
a[i] ^= a[j];
a[j] ^= a[i];
a[i] ^= a[j];
}
}
void down(int l, int r, int p)
{
int t = p;
if ((p << 1) <= r - l && a[t] < a[(p << 1) - l])
t = (p << 1) - l;
if ((p << 1) + 1 - l <= r && a[t] < a[(p << 1) + 1 - l])
t = (p << 1) + 1 - l;
if (t != p)
{
swap(t, p);
down(l, r, t);
}
}
void heap_sort(int l, int r)
{
for (int i = r - l >> 1; i; i – )
down(l, r, i);
while (r ^ l)
{
swap(1, r – );
down(l, r, 1);
}
}
int main()
{
int n, l, r;
scanf(“%d%d%d”, &n, &l, &r);
for (int i = 1; i <= n; i ++ )
scanf(“%d”, &a[i]);
heap_sort(l, r + 1);
for (int i = 1; i <= n; i ++ )
printf("%d ", a[i]);
return 0;
}
沙发
大佬666