| 比赛 |
?板子大赛 |
评测结果 |
AAATATATTA |
| 题目名称 |
最小函数值 |
最终得分 |
60 |
| 用户昵称 |
赵飞羽 |
运行时间 |
6.143 s |
| 代码语言 |
C++ |
内存使用 |
4.64 MiB |
| 提交时间 |
2026-01-17 10:11:35 |
显示代码纯文本
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1000010;
int n, m, A, B, C, y, heap[N], tot;
int f(int x, int a, int b, int c) {
return a * x * x + b * x + c;
}
void _push(int x) {
heap[++tot] = x;
int p = tot;
while (p != 1) {
if (x > heap[p/2]) {
swap(heap[p], heap[p/2]);
p /= 2;
} else {
break;
}
}
return;
}
void _pop() {
swap(heap[1], heap[tot]);
heap[tot] = 0;
tot--;
int p = 1, x = heap[1];
while ((int)log2(p) != (int)log2(tot)) {
if (x < max(heap[p*2], heap[p*2+1])) {
if (heap[p*2] > heap[p*2+1]) {
swap(heap[p], heap[p*2]);
p *= 2;
} else {
swap(heap[p], heap[p*2+1]);
p *= 2;
p++;
}
} else {
break;
}
}
return;
}
signed main() {
freopen("minval.in", "r", stdin);
freopen("minval.out", "w", stdout);
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> A >> B >> C;
if (i == 1) {
for (int j = 1; j <= m; j++) {
y = f(j, A, B, C);
_push(y);
}
} else {
for (int j = 1; j <= m; j++) {
y = f(j, A, B, C);
if (heap[1] < y) {
break;
} else {
_pop();
_push(y);
}
}
}
}
sort(heap+1, heap+1+tot);
for (int i = 1; i <= tot; i++) cout << heap[i] << " ";
return 0;
}