QOJ.ac

QOJ

実行時間制限: 2 s メモリ制限: 256 MB 満点: 100

#4496. 忍爱线段树

統計

作为一个冷血、热血且铁血的吸血鬼,Shinobu 喜欢构建线段树。 她使用 build() 函数来构建线段树,构建线段树的过程会增加某些数值。 build() 函数的具体内容如下:

void build(int id, int l, int r) :
  value[id] += r - l + 1;
  if(l == r) return;
  int mid = (r + l)/2;
  build(id * 2, l, mid);
  build(id * 2 + 1, mid + 1, r);
  return;

例如,如果 Shinobu 调用一次 build(1, 1, 2),那么 value[1] 将增加 2,value[2]value[3] 将增加 1。

在吸血鬼漫长的生命中,Shinobu 每天都会构建一棵线段树。她从第 1 天开始这样做,在第 $i$ 天,她会调用 build(1, 1, i) 来构建一棵线段树。

作为 Shinobu 的粉丝,playf 得到了一个粉丝编号 $x$。现在他想问你一个问题:在第 $n$ 天结束时,value[x] 的值是多少?

输入格式

第一行包含一个整数 $t(1 \le t \le 10^5)$,表示测试用例的数量。 接下来的 $t$ 行,每行包含两个整数 $n, x(1 \le n \le 10^9, 1 \le x \le 4 \times n)$,表示 playf 的询问。

输出格式

对于每个询问,输出一行,包含一个整数,即第 $i$ 个询问的答案。

样例

输入 1

3
2 3
3 3
4 3

输出 1

1
2
4

输入 2

1
26 49

输出 2

9

输入 3

3
1000000000 4000000000
1000000000 1
11451419 19810

输出 3

0
500000000500000000
4004478229

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.