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 nn plants ordered in a straight line, consisting of plant 1,2,3,…n1, 2, 3, \ldots n. Initially, every plant contains 00 millilitres of water.

He wants to perform qq watering operations as follows :

  • Given l,rl, r for each operation
  • water f(i−l+1)f(i-l+1) millilitres of water onto the ii-th plant for every l≤i≤rl \leq i \leq r

where f(x)f(x) denotes the product of xx and the value of the least significant set bit of xx ∗^{\text{∗}} Your task is to figure out the amount of water in each plant after all watering operations are done.

∗^{\text{∗}}The value of the least significant set bit of xx is the value of the rightmost set bit (bit that is 1) in the binary representation of xx. For instance, the value of the least significant set bit of 10=1010210 = 1010_2 is 00102=20010_2 = 2

Blackslex 在紧张的人际关系、高压的政治环境以及繁重的科研工作带来的持续压力中,从植物与树木中找到了慰藉。

Blackslex 拥有 nn 株植物,按直线排列,编号为 1,2,3,…,n1, 2, 3, \ldots, n。初始时,每株植物中的水量均为 00 毫升。

他将执行 qq 次浇水操作,每次操作如下:

  • 给定区间 l,rl, r;
  • 对每个满足 l≤i≤rl \leq i \leq r 的第 ii 株植物,浇灌 f(i−l+1)f(i-l+1) 毫升水。

其中,f(x)f(x) 表示 xx 与其最低位的置位比特(least significant set bit)的值之积∗^{\text{∗}}。你的任务是计算所有浇水操作完成后,每株植物中的水量。

∗^{\text{∗}} 整数 xx 的最低位置位比特的值,是指其二进制表示中最右侧的值为 1 的比特位所代表的数值。例如,10=1010210 = 1010_2 的最低位置位比特的值为 00102=20010_2 = 2。

输入格式

The first line contains an integer tt (1≤t≤1041 \leq t \leq 10^4) — the number of test cases.

The first line of each test case contains two integers nn, qq (1≤n,q≤2⋅1051 \leq n, q \leq 2\cdot 10^5) — the number of plants and the number of watering operations, respectively.

The next qq lines of each test case contain two integers ll, rr (1≤l≤r≤n1 \leq l \leq r \leq n) — the left bound and the right bound for each watering operation.

It is guaranteed that the sum of all values of nn and the sum of all values of qq across all test cases do not exceed 2⋅1052 \cdot 10^5.

第一行包含一个整数 tt(1≤t≤1041 \leq t \leq 10^4)—— 测试用例的数量。

每个测试用例的第一行包含两个整数 nn、qq(1≤n,q≤2⋅1051 \leq n, q \leq 2\cdot 10^5)—— 分别表示植物的数量和浇水操作的次数。

每个测试用例接下来的 qq 行,每行包含两个整数 ll、rr(1≤l≤r≤n1 \leq l \leq r \leq n)—— 表示每次浇水操作的左边界和右边界。

保证所有测试用例中 nn 的总和与 qq 的总和均不超过 2⋅1052 \cdot 10^5。

输出格式

For each test case, output nn integers representing the amount of water in the ii-th plant for each i=1,2,3,…,ni = 1, 2, 3, \ldots, n

对于每个测试用例,输出 nn 个整数,分别表示第 ii 株植物中的水量,其中 i=1,2,3,…,ni = 1, 2, 3, \ldots, 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 :

  1. The first operation will :
    • water the 11-st plant using f(1−1+1)=f(1)=1f(1-1+1) = f(1) = 1 millilitres of water.
    • water the 22-nd plant using f(2−1+1)=f(2)=4f(2 - 1 + 1) = f(2) = 4 millilitres of water.
    • water the 33-rd plant using f(3−1+1)=f(3)=3f(3 - 1 + 1) = f(3) = 3 millilitres of water.
    • water the 44-th plant using f(4−1+1)=f(4)=16f(4 - 1 + 1) = f(4) = 16 millilitres of water.
    • water the 55-th plant using f(5−1+1)=f(5)=5f(5 - 1 + 1) = f(5) = 5 millilitres of water.
  2. The second operation will :
    • water the 22-nd plant using f(2−2+1)=f(1)=1f(2 - 2 + 1) = f(1) = 1 millilitres of water.
    • water the 33-rd plant using f(3−2+1)=f(2)=4f(3 - 2 + 1) = f(2) = 4 millilitres of water.
  3. The third operation will :
    • water the 22-nd plant using f(2−2+1)=f(1)=1f(2 - 2 + 1) = f(1) = 1 millilitres of water.
    • water the 33-rd plant using f(3−2+1)=f(2)=4f(3 - 2 + 1) = f(2) = 4 millilitres of water.
    • water the 44-th plant using f(4−2+1)=f(3)=3f(4 - 2 + 1) = f(3) = 3 millilitres of water.
    • water the 55-th plant using f(5−2+1)=f(4)=16f(5 - 2 + 1) = f(4) = 16 millilitres of water.

Hence, the total amount of water in each plant is :

  1. 11 millilitres
  2. 4+1+1=64 + 1 + 1 = 6 millilitres
  3. 3+4+4=113 + 4 + 4 = 11 millilitres
  4. 16+3=1916 + 3 = 19 millilitres
  5. 5+16=215 + 16 = 21 millilitres

在第一种情况下,每次操作将按如下方式执行:

  1. 第一次操作将:
    • 使用 f(1−1+1)=f(1)=1f(1-1+1) = f(1) = 1 毫升水浇灌第 11 株植物。
    • 使用 f(2−1+1)=f(2)=4f(2 - 1 + 1) = f(2) = 4 毫升水浇灌第 22 株植物。
    • 使用 f(3−1+1)=f(3)=3f(3 - 1 + 1) = f(3) = 3 毫升水浇灌第 33 株植物。
    • 使用 f(4−1+1)=f(4)=16f(4 - 1 + 1) = f(4) = 16 毫升水浇灌第 44 株植物。
    • 使用 f(5−1+1)=f(5)=5f(5 - 1 + 1) = f(5) = 5 毫升水浇灌第 55 株植物。
  2. 第二次操作将:
    • 使用 f(2−2+1)=f(1)=1f(2 - 2 + 1) = f(1) = 1 毫升水浇灌第 22 株植物。
    • 使用 f(3−2+1)=f(2)=4f(3 - 2 + 1) = f(2) = 4 毫升水浇灌第 33 株植物。
  3. 第三次操作将:
    • 使用 f(2−2+1)=f(1)=1f(2 - 2 + 1) = f(1) = 1 毫升水浇灌第 22 株植物。
    • 使用 f(3−2+1)=f(2)=4f(3 - 2 + 1) = f(2) = 4 毫升水浇灌第 33 株植物。
    • 使用 f(4−2+1)=f(3)=3f(4 - 2 + 1) = f(3) = 3 毫升水浇灌第 44 株植物。
    • 使用 f(5−2+1)=f(4)=16f(5 - 2 + 1) = f(4) = 16 毫升水浇灌第 55 株植物。

因此,每株植物中水的总量为:

  1. 11 毫升
  2. 4+1+1=64 + 1 + 1 = 6 毫升
  3. 3+4+4=113 + 4 + 4 = 11 毫升
  4. 16+3=1916 + 3 = 19 毫升
  5. 5+16=215 + 16 = 21 毫升

输入解题思路,AI测评打分。不知道怎么写?

首页