#P17533. [JAG 2026 Summer Camp #1] Longest Symmetry

    ID: 20263 远端评测题 2000ms 2048MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>线段树二分树状数组cdq 分治哈希 hashing扫描线Manacher 算法ICPC2026

[JAG 2026 Summer Camp #1] Longest Symmetry

Problem Description

There are NN houses numbered 1,2,…,N1,2,\ldots,N on a number line. House ii is located at coordinate XiX_i. It is guaranteed that Xi<Xi+1X_i<X_{i+1} for every ii (1≤i≤N−11\le i\le N-1).

For integers a,ba,b with 1≤a<b≤N1\le a<b\le N, we say that the consecutive houses a,a+1,…,ba,a+1,\ldots,b form a symmetric interval of houses if the following condition holds:

  • For every i=0,1,…,b−ai=0,1,\ldots,b-a, Xa+Xb=Xa+i+Xb−iX_a+X_b=X_{a+i}+X_{b-i} holds.

You are given QQ queries. Process them in order.

  • In the ii-th query, you are given integers li,ril_i,r_i (1≤li<ri≤N1\le l_i<r_i\le N). Among all pairs of integers (s,t)(s,t) satisfying li≤s<t≤ril_i\le s<t\le r_i such that the consecutive houses s,s+1,…,ts,s+1,\ldots,t form a symmetric interval of houses, output the maximum possible width Xt−XsX_t-X_s of the interval.

Input Format

The input consists of a single test case of the following format:

N
X_1 X_2 ... X_N
Q
l_1 r_1
l_2 r_2
...
l_Q r_Q

The first line contains an integer NN, representing the number of houses (2≤N≤2×1052\le N\le 2\times 10^5).

The second line contains NN integers X1,X2,…,XNX_1,X_2,\ldots,X_N, representing the coordinates of the houses (−109≤Xi≤109-10^9\le X_i\le 10^9). It is guaranteed that Xi<Xi+1X_i<X_{i+1} for every ii (1≤i≤N−11\le i\le N-1).

The third line contains an integer QQ, representing the number of queries (1≤Q≤2×1051\le Q\le 2\times 10^5).

Each of the following QQ lines contains two integers lil_i and rir_i, representing the left and right endpoints of the range specified in the ii-th query (1≤li<ri≤N1\le l_i<r_i\le N).

Output Format

For each query, output the maximum possible width.

7
-5 -2 0 4 6 9 12
5
1 7
2 6
3 7
4 7
3 6
14
8
6
6
4