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

using namespace std;

typedef long long LL;

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 

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

priority_queue<long double> ans;

LL C,n,Q;

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

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

void Out() {
	static vector<long double> 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",(LL)(t[i]+0.5));
}
///////////

#define L t[o].l
#define R t[o].r
LL rt;

void up(LL o) {
	
}

void build(LL &o,LL l,LL r,LL cas) {
	if(r <= l) return;
	o = (l+r)>>1; D = cas;
	nth_element(t+l,t+o,t+r+1);
	cas = (cas+1)%5;
	build(L,l,o-1,cas); build(R,o+1,r,cas);
	up(o);
}

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 %lld strings' distance are:\n",C);
    for (int i = 1; i <= n; i++) Push(Dis(q,t[i]));
    //quert(rt);
    Out(); 
  }
  return 0;
}