CF1098E.Fedya the Potter

普及/提高-

通过率:0%

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 , 1lrn1 \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 , 1lrn(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 .

输入格式

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

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

输出格式

Print a single integer — the lower median of array 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 .

首页