CF1098E.Fedya the Potter

NOI/NOI+/CTSC

通过率:0%

时间限制:2.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Fedya loves problems involving data structures. Especially ones about different queries on subsegments. Fedya had a nice array a1,a2,…ana_1, a_2, \ldots a_n and a beautiful data structure. This data structure, given ll and rr, 1≤l≤r≤n1 \le l \le r \le n, could find the greatest integer dd, such that dd divides each of ala_l, al+1a_{l+1}, ..., ara_{r}.

Fedya really likes this data structure, so he applied it to every non-empty contiguous subarray of array aa, put all answers into the array and sorted it. He called this array bb. It's easy to see that array bb contains n(n+1)/2n(n+1)/2 elements.

After that, Fedya implemented another cool data structure, that allowed him to find sum bl+bl+1+…+brb_l + b_{l+1} + \ldots + b_r for given ll and rr, 1≤l≤r≤n(n+1)/21 \le l \le r \le n(n+1)/2. Surely, Fedya applied this data structure to every contiguous subarray of array bb, called the result cc and sorted it. Help Fedya find the lower median of array cc.

Recall that for a sorted array of length kk the lower median is an element at position ⌊k+12⌋\lfloor \frac{k + 1}{2} \rfloor, if elements of the array are enumerated starting from 11. For example, the lower median of array (1,1,2,3,6)(1, 1, 2, 3, 6) is 22, and the lower median of (0,17,23,96)(0, 17, 23, 96) is 1717.

费迪亚喜欢涉及数据结构的题目,尤其是关于子数组上各类查询的问题。费迪亚有一个优美的数组 a1,a2,…,ana_1, a_2, \ldots, a_n 和一个漂亮的数据结构。该数据结构在给定 ll 和 rr(其中 1≤l≤r≤n1 \le l \le r \le n)时,能求出最大的整数 dd,使得 dd 能整除 al,al+1,…,ara_l, a_{l+1}, \ldots, a_r 中的每一个数。

费迪亚非常喜爱这一数据结构,于是他将其应用于数组 aa 的每一个非空连续子数组,将所有结果收集起来组成一个新数组并排序,称该数组为 bb。显然,数组 bb 包含 n(n+1)/2n(n+1)/2 个元素。

接着,费迪亚实现了另一个酷炫的数据结构,该结构能在给定 ll 和 rr(其中 1≤l≤r≤n(n+1)/21 \le l \le r \le n(n+1)/2)时,快速计算 bl+bl+1+…+brb_l + b_{l+1} + \ldots + b_r 的和。当然,费迪亚又将此数据结构应用于数组 bb 的每一个连续子数组,将所有结果收集起来并排序,得到数组 cc。请帮助费迪亚找出数组 cc 的下中位数(lower median)。

需要回顾的是:对于一个长度为 kk 的已排序数组,其下中位数是位于位置 ⌊k+12⌋\lfloor \frac{k + 1}{2} \rfloor 上的元素(数组下标从 11 开始计数)。例如,数组 (1,1,2,3,6)(1, 1, 2, 3, 6) 的下中位数是 22,而 (0,17,23,96)(0, 17, 23, 96) 的下中位数是 1717。

输入格式

First line contains a single integer nn — number of elements in array aa (1≤n≤50 0001 \le n \le 50\,000).

Second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n — elements of the array (1≤ai≤100 0001 \le a_i \le 100\,000).

第一行包含一个整数 nn —— 数组 aa 的元素个数(1≤n≤50 0001 \le n \le 50\,000)。

第二行包含 nn 个整数 a1,a2,…,ana_1, a_2, \ldots, a_n —— 数组的元素(1≤ai≤100 0001 \le a_i \le 100\,000)。

输出格式

Print a single integer — the lower median of array cc.

输出一个整数——数组 cc 的下中位数。

输入输出样例

  • 输入#1

    2
    6 3

    输出#1

    6
  • 输入#2

    2
    8 8

    输出#2

    8
  • 输入#3

    5
    19 16 2 12 15

    输出#3

    12

说明/提示

In the first sample array bb is equal to 3,3,6{3, 3, 6}, then array cc is equal to 3,3,6,6,9,12{3, 3, 6, 6, 9, 12}, so the lower median is 66.

In the second sample bb is 8,8,8{8, 8, 8}, cc is 8,8,8,16,16,24{8, 8, 8, 16, 16, 24}, so the lower median is 88.

在第一个样例中,数组 bb 为 3,3,6{3, 3, 6},则数组 cc 为 3,3,6,6,9,12{3, 3, 6, 6, 9, 12},因此下中位数为 66。

在第二个样例中,bb 为 8,8,8{8, 8, 8},cc 为 8,8,8,16,16,24{8, 8, 8, 16, 16, 24},因此下中位数为 88。

输入解题思路,AI测评打分。不知道怎么写?

首页