sjtu4252
Function value
Title Description
Nn has an upwardly open quadratic function fi (x) = aix2 + bix + cifi (x) = aix2 + bix + ci
we only consider xx is an integer, for each integer xx nn functions with this role of can get the number NN, we also believe that the same value even if a plurality of repeating
the xx runs over all integers, the infinite number of a plurality of obtained, and find the minimum number of small to large output kk
Input Format
The first two row number n, kn, k, represents the number sequence length and the number of required
Subsequently nn rows of three numbers ai, bi, ciai, bi, ci, represent the function fi (x) fi (x )
Output Format
Kk represents the minimum number of line number kk
Sample input 1
2 9
1 0 0
1 2 0
Sample output 1
-1 0 0 0 1 1 3 3 4
Scale data
To 100% of the data have
0 <ai0 <ai
for 30% of the data have
bi% (2 * ai) = 0bi% (2 * ai) = 0
to 60% of the data have
bi% ai = 0bi% ai = 0
for 40% of the data have
n≤500n≤500
k≤500k≤500
for 70% of the data have
n≤3000n≤3000
k≤3000k≤3000
have 100% data
n≤100000n≤100000
k≤100000k≤100000
Code
#pragma GCC optimize(3)
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<climits>
#include<queue>
#include<set>
#define max(x,y) ((x)>(y)?(x):(y))
#define min(x,y) ((x)<(y)?(x):(y))
#define swap(x,y) (x^=y,y^=x,x^=y)
using namespace std;
typedef long long ll;
const int N=1e6+50;
template<typename T>inline void read(T &x)
{
x=0;
T f=1;
char c=getchar();
for(; c<'0'||c>'9'; c=getchar()) if(c=='-') f=-1;
for(; c>='0'&&c<='9'; c=getchar()) x=(x<<1)+(x<<3)+(c&15);
}
template<typename T>inline void print(T x)
{
if(x<0) putchar('-'),x*=-1;
if(x>=10) print(x/10);
putchar(x%10+'0');
}
ll a[N],b[N],c[N];
struct node
{
ll v,x,f;
};
node qq;
multiset<ll>pq;
priority_queue<node>q;
bool operator < (node a,node b) //重载<
{
return a.v>b.v;
}
ll fac(ll i,ll x) //开ll
{
return a[i]*x*x+b[i]*x+c[i];
}
int n,k;
ll t[N];
int main()
{
read(n);read(k);
for(int i=1;i<=n;i++)
{
scanf("%lld%lld%lld",a+i,b+i,c+i);
t[i]=(-b[i])/(2*a[i]);
q.push((node){fac(i,t[i]),t[i],i});
}
ll e,w,r,y;
for(int i=1;i<=2*k;i++) //只循环到k会wa,以防万一扩大入队数目
{
qq=q.top();
// print(qq.v);
//q.pop();
pq.insert(qq.v);
q.pop();
if(qq.x==t[qq.f]){
e=fac(qq.f,qq.x+1);
w=fac(qq.f,qq.x-1);
r=qq.x+1;
y=qq.x-1;
q.push((node){e,r,qq.f});
q.push((node){w,y,qq.f});
}
else if(qq.x>t[qq.f])
{
e=fac(qq.f,qq.x+1);
q.push((node){e,qq.x+1,qq.f});
}
else
{
e=fac(qq.f,qq.x-1);
q.push((node){e,qq.x-1,qq.f});
}
}
int temp=0;
for(multiset<ll>::iterator it=pq.begin();it!=pq.end();it++) //set的遍历
{
cout<<*it<<' ';
temp++;
if(temp==k)
break;
}
cout<<endl;
return 0;
}
ps
- vector can be used instead of push_back emplace_back twice as fast.