2100: [USACO 2026 First Contest, Platinum] Problem 2. Lineup Counting Queries

文件提交:无需freopen 内存限制:256 MB 时间限制:2.000 S
评测方式:普通裁判 命题人:
提交:0 解决:0

题目描述

There is a line of cows, initially (i.e. at time ) containing only cow  at position  (here, a cow is at position  if there are  cows in front of it). At time  for , the cow at position 0 moves to position , every cow in positions  moves forward one position, and cow  joins the line at the end of the line (position ).

Answer  () independent queries each of the following form:

  • Out of cows , how many are located at positions  immediately after time ? ()

输入

The first line contains , the number of queries.

The next  lines each contain five integers specifying a query of the form "    ."

输出

Output the answer to each query on a separate line.

样例输入

4
0 9 0 9 9
3 5 4 5 9
4 5 3 5 9
1 1 3 3 9

样例输出

10
2
1
1

提示

Lineups at various times:

t = 0 | 0
t = 1 | 0 1
t = 2 | 1 0 2
t = 3 | 0 1 2 3
t = 4 | 1 2 0 3 4
t = 5 | 2 0 1 3 4 5
t = 6 | 0 1 3 2 4 5 6
t = 7 | 1 3 2 0 4 5 6 7
t = 8 | 3 2 0 4 1 5 6 7 8
t = 9 | 2 0 4 1 3 5 6 7 8 9

At  the cows from front to back are .

To answer the third query, the cows at positions  are , and only one of them is in the range .


SAMPLE INPUT:

1
0 1000000000000000000 0 1000000000000000000 1000000000000000000


SAMPLE OUTPUT:

1000000000000000001


SCORING:

  • Input 3: 
  • Inputs 4-7:  for all queries
  • Inputs 8-14:  for all queries
  • Inputs 15-21: No additional constraints

来源/分类