Codeforces Round 1068 (Div. 2)
F
Isla's Memory Thresholds
Codeforces
2600
原题
← E→
翻译中…

I hope one day, you'll be reunited with the one you cherish.— Plastic Memories

翻译中…

In the world of Plastic Memories, Isla is collecting $n$ memory fragments. The $i$-th fragment has size $a_i$, and the sizes are non-increasing, that is, $a_1 \ge a_2 \ge \cdots \ge a_n$.

翻译中…

During retrieval, Isla processes fragments on a range and stores their sizes into a buffer. Whenever the buffer reaches a given threshold $x$, it overflows: one capsule is recorded, and the buffer is cleared to zero.

翻译中…

There are $q$ independent queries, each described by a triple $(l,r,x)$. For each query, $x$ denotes Isla's memory capacity. Isla then picks up the $i$-th memory fragment one by one for each $l \le i \le r$. At any moment, if the total size of the fragments she is currently holding is at least $x$, she clears her memory completely (keeping nothing). You must determine how many times Isla clears her memory and the final sum of the size of the fragments she holds.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $q$ ($1 \le n, q \le 150,000$) — the length of $a$ and the number of queries.

翻译中…

The second line of each test case contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1 \le a_i \le 10^9$) — the elements of $a$. It is guaranteed that $a_1 \ge a_2 \ge \cdots \ge a_n$.

翻译中…

Then $q$ lines follow, each containing three integers $l$, $r$, and $x$ ($1 \le l \le r \le n$, $1 \le x \le 10^9$) — a query.

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $150,000$.

翻译中…

It is guaranteed that the sum of $q$ over all test cases does not exceed $150,000$.

翻译中…

Output

翻译中…

For each test case, output two integers for each query — the number of times Isla clears her memory and the final sum of the size of the fragments she holds.

翻译中…

Note

翻译中…

Let $\texttt{cnt}$ be how many times Isla has cleared her memory, and $\texttt{sum}$ be the total size of the fragments she is holding.

翻译中…

In the first test case, for the first query $(l, r, x) = (1, 3, 10)$:

翻译中…
  • start with $\texttt{sum}=0$;
  • add $a_1=7 \Rightarrow \texttt{sum}=7$ (still $ \lt 10$);
  • add $a_2=5 \Rightarrow \texttt{sum}=12 \ge 10 \Rightarrow \texttt{sum} \gets 0$, $\texttt{cnt} \gets 1$;
  • add $a_3=5 \Rightarrow \texttt{sum}=5$.
翻译中…

Thus, we print $\texttt{cnt}=1$ and $\texttt{sum}=5$.

翻译中…

In the second test case, for the fifth query $(l, r, x) = (2, 5, 3)$:

翻译中…
  • start with $\texttt{sum}=0$;
  • add $a_2=6 \Rightarrow \texttt{sum}=6 \ge 3 \Rightarrow \texttt{sum} \gets 0$, $\texttt{cnt} \gets 1$;
  • add $a_3=5 \Rightarrow \texttt{sum}=5 \ge 3 \Rightarrow \texttt{sum} \gets 0$, $\texttt{cnt} \gets 2$;
  • add $a_4=3 \Rightarrow \texttt{sum}=3 \ge 3 \Rightarrow \texttt{sum} \gets 0$, $\texttt{cnt} \gets 3$;
  • add $a_5=2 \Rightarrow \texttt{sum}=2$ (still $ \lt 3$);
翻译中…

Thus, we print $\texttt{cnt}=3$ and $\texttt{sum}=2$.

翻译中…

样例

Input #1
3
5 4
7 5 5 2 1
1 3 10
2 5 6
1 5 7
3 5 4
6 5
6 6 5 3 2 2
1 6 2
1 6 7
2 6 7
2 5 4
2 5 3
11 7
938412006 792864920 746880066 729862150 704473377 550436315 381392172 326088331 316506801 301443698 190862681
1 3 417253102
9 11 857592497
1 11 344359921
1 7 408760015
8 8 544749974
7 10 361090133
3 11 888178376
Output #1
1 5
1 3
2 3
1 3
6 0
2 4
2 0
3 0
3 2
3 0
0 808813180
9 0
6 381392172
0 326088331
2 301443698
3 492306379
InputCopy OutputCopy
题目信息
题号
2173F
时间限制
6 s
内存限制
1024 MB
标签
二分
暴力
数据结构
分治
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。