Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Algorithm 执行查询以从数组中的给定元素查找三角形的最大周长_Algorithm_Sorting_Math_Max - Fatal编程技术网

Algorithm 执行查询以从数组中的给定元素查找三角形的最大周长

Algorithm 执行查询以从数组中的给定元素查找三角形的最大周长,algorithm,sorting,math,max,Algorithm,Sorting,Math,Max,我们将获得一个数字数组。我们将执行两种类型的查询:- 1)Find the triangle with the maximum perimeter in a given interval (l,r). 2)Update the array element at the given index i to a new given value x. 例如:- 我们将总共执行4(q)个查询。第一个查询是查找区间(1,5)中的最大周长。因此,我们将返回24,因为范围(1,5)中三角形的最大可能周长是24

我们将获得一个数字数组。我们将执行两种类型的查询:-

1)Find the triangle with the maximum perimeter in a given interval (l,r).
2)Update the array element at the given index i to a new given value x.
例如:-

我们将总共执行4(q)个查询。第一个查询是查找区间(1,5)中的最大周长。因此,我们将返回24,因为范围(1,5)中三角形的最大可能周长是24(8+9+7)。 第二个查询是将索引2处的值更新为12。因此,现在我们的数组变成[]=3,12,8,9,7。 第三个查询是查找区间(1,3)中的最大周长,即从数组元素3,1,8开始。我们不能从这些元素形成任何三角形。因此,我们返回0。
现在我得到了一个O(q*nlogn)方法是首先对每个查询的元素进行排序,但我想知道是否还有其他更好的方法。我曾考虑应用平方根分解或分段树,但不确定。

不要在这里问codechef当前正在进行的挑战问题

我投票将这个问题作为离题题来结束,因为没有做出任何努力。

制造?它不能回答这个问题。如果您认为它不属于StackOveflow,请标记它。