记录编号 425009 评测结果 AAAWWWWWWWWWTTTTTTTTTTTTT
题目名称 2594.[Keller战纪·正传·妖姬篇][HZOI 2015]Keller非.a.t.e 最终得分 12
用户昵称 rewine 是否通过 未通过
代码语言 C++ 运行时间 154.141 s
提交时间 2017-07-14 16:07:55 内存使用 10.23 MiB
显示代码纯文本
#include <cstdio>
#include <iostream>
#include <queue>

using namespace std;

typedef long long LL;

void read(int &x) {static char c; static bool flag;for (flag = 0; (c=getchar())<'0'||c>'9'; flag |= c=='-');for (x=c-'0'; (c=getchar())>='0'&&c<='9'; x=x*10+c-'0');if(flag) x = -x;}
void read(LL &x) {static char c; static bool flag;for (flag = 0; (c=getchar())<'0'||c>'9'; flag |= c=='-');for (x=c-'0'; (c=getchar())>='0'&&c<='9'; x=x*10+c-'0');if(flag) x = -x;}

inline LL F(LL x) {return x*x*x*x;}
#define N 200000 

int D;
struct Data {
  int t,l,r; LL v[5];
  void in() {
    read(t);
    for (int i = 0; i < t; i++) read(v[i]);
  }
  bool operator < (const Data &lhs) const {
  	return v[D] < lhs.v[D];   
  }
}t[N],q;
priority_queue<LL> ans;

int C,n,Q;

LL Dis(const Data &a,const Data &b) {
   LL t = 0;
   for (int i = 0; i < 5; i++) t += F(a.v[i]-b.v[i]);
   return t;
}

void Push(LL v) {
   ans.push(v);
   if(ans.size()>C) ans.pop();
}

void Out() {
	static vector<LL> t;
	t.clear();
	while(ans.size()) {
	   t.push_back(ans.top()); ans.pop();
	}
	for (int i = t.size()-1; i >= 0; i--)
	 printf("%lld\n",t[i]);
}
///////////
#define L t[o].l
#define R t[o].r
int rt;
/*
void build(int &o,int l,int r,int cas) {
	
	o = (l+r)>>1;
	cas = (cas+1)%5;
	build(l,mid-1,);
	build(mid+1,r,cas);
}*/
int main() {
  freopen("Keller_Deal.in","r",stdin);freopen("Keller_Deal.out","w",stdout);
  read(n); read(Q);
  for (int i = 1; i <= n; i++) t[i].in();
 // build(rt,1,n,0);
  for (int i = 1; i <= Q; i++) {
    read(q.t); read(C);
    for (int i = 0; i < q.t; i++) read(q.v[i]);
    for (int i = q.t; i < 5; i++) q.v[i] = 0;
    printf("the closest %d strings' distance are:\n",C);
    for (int i = 1; i <= n; i++) Push(Dis(q,t[i]));
    Out(); 
  }
  return 0;
}