CF2173F.Isla's Memory Thresholds
省选/NOI-
通过率:0%
时间限制:6.00s
内存限制:1024MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
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 ai, and the sizes are non-increasing, that is, a1≥a2≥⋯≥an.
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≤i≤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.
我希望终有一天,你能与你所珍视之人重逢。
——《塑料 Memories》
在《塑料 Memories》的世界中,Isla 正在收集 n 个记忆碎片。第 i 个碎片的大小为 ai,且这些大小是非递增的,即满足 a1≥a2≥⋯≥an。
在检索过程中,Isla 会处理某一区间内的碎片,并将其大小存入一个缓冲区。每当缓冲区总和达到给定阈值 x 时,缓冲区就会溢出:此时记录一个胶囊,缓冲区被清空为零。
共有 q 个独立查询,每个查询由三元组 (l,r,x) 描述。对每个查询,x 表示 Isla 的记忆容量。Isla 将依次拾取下标满足 l≤i≤r 的每一个记忆碎片。在任意时刻,若她当前所持碎片的总大小至少为 x,她便会完全清空自己的记忆(即不保留任何碎片)。你需要计算 Isla 清空记忆的次数,以及最终她所持碎片大小的总和。
输入格式
Each test contains multiple test cases. The first line contains the number of test cases t (1≤t≤1000). The description of the test cases follows.
The first line of each test case contains two integers n and q (1≤n,q≤150,000) — the length of a and the number of queries.
The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — the elements of a. It is guaranteed that a1≥a2≥⋯≥an.
Then q lines follow, each containing three integers l, r, and x (1≤l≤r≤n, 1≤x≤109) — 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.
每个测试包含多个测试用例。第一行包含测试用例的数量 t(1≤t≤1000)。随后是各测试用例的描述。
每个测试用例的第一行包含两个整数 n 和 q(1≤n,q≤150,000)—— 分别表示数组 a 的长度和查询次数。
每个测试用例的第二行包含 n 个整数 a1,a2,…,an(1≤ai≤109)—— 即数组 a 的元素。保证满足 a1≥a2≥⋯≥an。
接下来是 q 行,每行包含三个整数 l、r 和 x(1≤l≤r≤n,1≤x≤109)—— 表示一次查询。
保证所有测试用例的 n 之和不超过 150,000。
保证所有测试用例的 q 之和不超过 150,000。
输出格式
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.
对于每个测试用例,针对每个查询,输出两个整数——Isla 清空其记忆的次数,以及她所持有的碎片大小之和的最终值。
输入输出样例
输入#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
输出#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
说明/提示
Let cnt be how many times Isla has cleared her memory, and 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 sum=0;
- add a1=7⇒sum=7 (still $ \lt 10$);
- add a2=5⇒sum=12≥10⇒sum←0, cnt←1;
- add a3=5⇒sum=5.
Thus, we print cnt=1 and sum=5.
In the second test case, for the fifth query (l,r,x)=(2,5,3):
- start with sum=0;
- add a2=6⇒sum=6≥3⇒sum←0, cnt←1;
- add a3=5⇒sum=5≥3⇒sum←0, cnt←2;
- add a4=3⇒sum=3≥3⇒sum←0, cnt←3;
- add a5=2⇒sum=2 (still $ \lt 3$);
Thus, we print cnt=3 and sum=2.
令 cnt 表示伊莎清空内存的次数,sum 表示她当前持有的碎片总大小。
在第一个测试用例中,对于第一个查询 (l,r,x)=(1,3,10):
- 初始时 sum=0;
- 加入 a1=7⇒sum=7(仍 $ \lt 10$);
- 加入 a2=5⇒sum=12≥10⇒sum←0,cnt←1;
- 加入 a3=5⇒sum=5。
因此,我们输出 cnt=1 和 sum=5。
在第二个测试用例中,对于第五个查询 (l,r,x)=(2,5,3):
- 初始时 sum=0;
- 加入 a2=6⇒sum=6≥3⇒sum←0,cnt←1;
- 加入 a3=5⇒sum=5≥3⇒sum←0,cnt←2;
- 加入 a4=3⇒sum=3≥3⇒sum←0,cnt←3;
- 加入 a5=2⇒sum=2(仍 $ \lt 3$);
因此,我们输出 cnt=3 和 sum=2。
输入解题思路,AI测评打分。不知道怎么写?