#P15133. [ROIR 2026] 最后的滑动窗口问题

    ID: 17044 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度NOI/NOI+/CTS 上传者: 标签>线段树扫描线2026单调栈ROIR(俄罗斯)

[ROIR 2026] 最后的滑动窗口问题

Problem Description

Consider a numeric array b1,…,bmb_1, \dots, b_m. A sliding window of length kk (k≤mk \le m) on this array refers to all subsegments of length kk, i.e. {b1,…,bk}\{b_1, \dots, b_k\}, {b2,…,bk+1}\{b_2, \dots, b_{k + 1}\}, …\dots, {bm−k+1,…,bm}\{b_{m-k+1}, \dots, b_m\}.

Given a numeric array a1,…,ana_1, \dots, a_n of length nn, answer qq queries about this array. Each query is as follows: for given ll, rr, and kk, find the sum of the minimum values of all sliding windows of length kk on the subsegment {al,…,ar}\{a_l, \dots, a_r\}.

Input Format

The first line contains two integers nn and qq (1≤n,q≤100 0001 \le n, q \le 100\,000), the length of the array and the number of queries.

The second line contains nn integers a1,…,ana_1, \dots, a_n (1≤ai≤1091 \le a_i \le 10^9), the values in the array.

The next qq lines describe the queries. The ii-th line contains three integers lil_i, rir_i, and kik_i (1≤l≤r≤n1 \le l \le r \le n, 1≤k≤r−l+11 \le k \le r - l + 1), the left and right boundaries of the subsegment and the sliding window length for the ii-th query.

Output Format

Output qq lines, each containing the answer to the corresponding query. On the ii-th line, output one number, the sum of the minimum values of all sliding windows of length kik_i on the subsegment {ali,…,ari}\{a_{l_i}, \dots, a_{r_i}\}.

6 3
4 6 1 2 5 3
2 5 2
2 4 1
1 6 6
4
9
1

Hint

Subtask Score Additional Constraints Dependencies
1 6 n,q≤300n, q \le 300
2 12 n,q≤4000n, q \le 4000 1
3 8 n,q≤10 000n, q \le 10\,000 1–2
4 11 n≤4 000n \le 4\,000
5 10 All queries have the same kik_i
6 14 ai≤2a_i \le 2
7 ai≤20a_i \le 20 6
8 15 li=1,ri=nl_i = 1, r_i = n
9 17 No additional constraints 1–8

Translated by ChatGPT 5