简体   繁体   English

对3d点的查询

[英]Queries on 3d Points

I have an array of 3d points. 我有一个3d点数组。 Each point has an x,y and z coordinate. 每个点都有一个x,y和z坐标。 The maximum size of the array can be 777777. I have Q queries each providing me with four numbers A, B, C, D. for each query I have to output the following sum. 数组的最大大小可以是777777.我有Q个查询,每个查询为我提供四个数字A,B,C,D。对于每个查询,我必须输出以下总和。

在此输入图像描述

Q <=77
1 <= A, B, C <=77
1 <= Xi, Yi, Zi <=77
1 <= Di <= 777
N <= 777777

What I have done: For each query calculate the given sum using two nested loops giving me a complexity of O(Q*N^2). 我做了什么:对于每个查询,使用两个嵌套循环计算给定的总和,给出了复杂度O(Q * N ^ 2)。 Is there a better way to calculate it ? 有更好的计算方法吗?

Edit: What I know for sure is this is not a geometric problem. 编辑:我确切知道这不是一个几何问题。 The maximum value of xi-xj is 76 and min is -76. xi-xj的最大值为76,min为-76。 This applies to yi and zi too. 这也适用于yi和zi。 so total possible combinations are 153*153*153. 所以总可能的组合是153 * 153 * 153。 Now in a query we have to count how many times a particular combination occurs in the array and solve the sum for that combination only once. 现在在查询中,我们必须计算特定组合在数组中出现的次数,并且只解析该组合的总和一次。 The problem reduces to finding how many times a particular combination of ( xi-xj , yi-yj, zi-zj). 问题减少到找到(xi-xj,yi-yj,zi-zj)的特定组合的次数。 Can someone take it ahead from here? 有人可以从这里领先吗? I suspect we can use fast Fourier transform here. 我怀疑我们可以在这里使用快速傅立叶变换。 I have seen them getting used in these kind of problems before. 我之前见过他们已经习惯了这些问题。 But I have no clue how to start 但我不知道如何开始

The following is a mistake, because it neglects the absolute value function. 以下是一个错误,因为它忽略了绝对值函数。 I don't see a way to get past this. 我没有办法解决这个问题。

You can rewrite the query as A * SUM_i!=j (Xi-Xj)/sqrt(...) + B * SUM_i!=j(Yi-Yj)/sqrt(...) + ... 您可以将查询重写为A * SUM_i!= j(Xi-Xj)/ sqrt(...)+ B * SUM_i!= j(Yi-Yj)/ sqrt(...)+ ...

Once you have done this you can see that if you have calculated the values for A=1, B=C=D=0, and B=1,A=C=D=0 and C=1,A=B=D=0 and D=1, A=B=C=0 as eg Qa, Qb, Qc, Qd, then you can find the values for any other values of A, B, C, and D as A * Qa + B * Qb + C * Qc + D * Qd. 完成此操作后,您可以看到如果计算出A = 1的值,B = C = D = 0,B = 1,则A = C = D = 0且C = 1,A = B = D = 0和D = 1,A = B = C = 0,例如Qa,Qb,Qc,Qd,那么你可以找到A,B,C和D的任何其他值的值为A * Qa + B * Qb + C * Qc + D * Qd。

This takes the complexity down to O(N^2) 这将复杂性降低到O(N ^ 2)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM