CF2179H.Blackslex and Plants
提高+/省选-
通过率:0%
时间限制:2.00s
内存限制:512MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Blackslex has found solace in plants and trees amidst accumulated stress from strained relationships, stressful politics, and strenuous research.
Blackslex has n plants ordered in a straight line, consisting of plant 1,2,3,…n. Initially, every plant contains 0 millilitres of water.
He wants to perform q watering operations as follows :
- Given l,r for each operation
- water f(i−l+1) millilitres of water onto the i-th plant for every l≤i≤r
where f(x) denotes the product of x and the value of the least significant set bit of x ∗ Your task is to figure out the amount of water in each plant after all watering operations are done.
∗The value of the least significant set bit of x is the value of the rightmost set bit (bit that is 1) in the binary representation of x. For instance, the value of the least significant set bit of 10=10102 is 00102=2
Blackslex 在紧张的人际关系、高压的政治环境以及繁重的科研工作带来的持续压力中,从植物与树木中找到了慰藉。
Blackslex 拥有 n 株植物,按直线排列,编号为 1,2,3,…,n。初始时,每株植物中的水量均为 0 毫升。
他将执行 q 次浇水操作,每次操作如下:
- 给定区间 l,r;
- 对每个满足 l≤i≤r 的第 i 株植物,浇灌 f(i−l+1) 毫升水。
其中,f(x) 表示 x 与其最低位的置位比特(least significant set bit)的值之积∗。你的任务是计算所有浇水操作完成后,每株植物中的水量。
∗ 整数 x 的最低位置位比特的值,是指其二进制表示中最右侧的值为 1 的比特位所代表的数值。例如,10=10102 的最低位置位比特的值为 00102=2。
输入格式
The first line contains an integer t (1≤t≤104) — the number of test cases.
The first line of each test case contains two integers n, q (1≤n,q≤2⋅105) — the number of plants and the number of watering operations, respectively.
The next q lines of each test case contain two integers l, r (1≤l≤r≤n) — the left bound and the right bound for each watering operation.
It is guaranteed that the sum of all values of n and the sum of all values of q across all test cases do not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤104)—— 测试用例的数量。
每个测试用例的第一行包含两个整数 n、q(1≤n,q≤2⋅105)—— 分别表示植物的数量和浇水操作的次数。
每个测试用例接下来的 q 行,每行包含两个整数 l、r(1≤l≤r≤n)—— 表示每次浇水操作的左边界和右边界。
保证所有测试用例中 n 的总和与 q 的总和均不超过 2⋅105。
输出格式
For each test case, output n integers representing the amount of water in the i-th plant for each i=1,2,3,…,n
对于每个测试用例,输出 n 个整数,分别表示第 i 株植物中的水量,其中 i=1,2,3,…,n
输入输出样例
输入#1
2 5 3 1 5 2 3 2 5 7 7 1 3 1 6 3 7 4 7 7 7 1 6 5 5
输出#1
1 6 11 19 21 3 12 10 37 18 43 22
说明/提示
In the first case, each operation will be performed as follows :
- The first operation will :
- water the 1-st plant using f(1−1+1)=f(1)=1 millilitres of water.
- water the 2-nd plant using f(2−1+1)=f(2)=4 millilitres of water.
- water the 3-rd plant using f(3−1+1)=f(3)=3 millilitres of water.
- water the 4-th plant using f(4−1+1)=f(4)=16 millilitres of water.
- water the 5-th plant using f(5−1+1)=f(5)=5 millilitres of water.
- The second operation will :
- water the 2-nd plant using f(2−2+1)=f(1)=1 millilitres of water.
- water the 3-rd plant using f(3−2+1)=f(2)=4 millilitres of water.
- The third operation will :
- water the 2-nd plant using f(2−2+1)=f(1)=1 millilitres of water.
- water the 3-rd plant using f(3−2+1)=f(2)=4 millilitres of water.
- water the 4-th plant using f(4−2+1)=f(3)=3 millilitres of water.
- water the 5-th plant using f(5−2+1)=f(4)=16 millilitres of water.
Hence, the total amount of water in each plant is :
- 1 millilitres
- 4+1+1=6 millilitres
- 3+4+4=11 millilitres
- 16+3=19 millilitres
- 5+16=21 millilitres
在第一种情况下,每次操作将按如下方式执行:
- 第一次操作将:
- 使用 f(1−1+1)=f(1)=1 毫升水浇灌第 1 株植物。
- 使用 f(2−1+1)=f(2)=4 毫升水浇灌第 2 株植物。
- 使用 f(3−1+1)=f(3)=3 毫升水浇灌第 3 株植物。
- 使用 f(4−1+1)=f(4)=16 毫升水浇灌第 4 株植物。
- 使用 f(5−1+1)=f(5)=5 毫升水浇灌第 5 株植物。
- 第二次操作将:
- 使用 f(2−2+1)=f(1)=1 毫升水浇灌第 2 株植物。
- 使用 f(3−2+1)=f(2)=4 毫升水浇灌第 3 株植物。
- 第三次操作将:
- 使用 f(2−2+1)=f(1)=1 毫升水浇灌第 2 株植物。
- 使用 f(3−2+1)=f(2)=4 毫升水浇灌第 3 株植物。
- 使用 f(4−2+1)=f(3)=3 毫升水浇灌第 4 株植物。
- 使用 f(5−2+1)=f(4)=16 毫升水浇灌第 5 株植物。
因此,每株植物中水的总量为:
- 1 毫升
- 4+1+1=6 毫升
- 3+4+4=11 毫升
- 16+3=19 毫升
- 5+16=21 毫升
输入解题思路,AI测评打分。不知道怎么写?