CF1080B.Margarite and the best present

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them.

Recently, she was presented with an array aa of the size of 10910^9 elements that is filled as follows:

  • a1=1a_1 = -1
  • a2=2a_2 = 2
  • a3=3a_3 = -3
  • a4=4a_4 = 4
  • a5=5a_5 = -5
  • And so on ...

That is, the value of the ii -th element of the array aa is calculated using the formula ai=i(1)ia_i = i \cdot (-1)^i .

She immediately came up with qq queries on this array. Each query is described with two numbers: ll and rr . The answer to a query is the sum of all the elements of the array at positions from ll to rr inclusive.

Margarita really wants to know the answer to each of the requests. She doesn't want to count all this manually, but unfortunately, she couldn't write the program that solves the problem either. She has turned to you — the best programmer.

Help her find the answers!

输入格式

The first line contains a single integer qq ( 1q1031 \le q \le 10^3 ) — the number of the queries.

Each of the next qq lines contains two integers ll and rr ( 1lr1091 \le l \le r \le 10^9 ) — the descriptions of the queries.

输出格式

Print qq lines, each containing one number — the answer to the query.

输入输出样例

  • 输入#1

    5
    1 3
    2 5
    5 5
    4 4
    2 3
    

    输出#1

    -2
    -2
    -5
    4
    -1
    

说明/提示

In the first query, you need to find the sum of the elements of the array from position 11 to position 33 . The sum is equal to a1+a2+a3=1+23=2a_1 + a_2 + a_3 = -1 + 2 -3 = -2 .

In the second query, you need to find the sum of the elements of the array from position 22 to position 55 . The sum is equal to a2+a3+a4+a5=23+45=2a_2 + a_3 + a_4 + a_5 = 2 -3 + 4 - 5 = -2 .

In the third query, you need to find the sum of the elements of the array from position 55 to position 55 . The sum is equal to a5=5a_5 = -5 .

In the fourth query, you need to find the sum of the elements of the array from position 44 to position 44 . The sum is equal to a4=4a_4 = 4 .

In the fifth query, you need to find the sum of the elements of the array from position 22 to position 33 . The sum is equal to a2+a3=23=1a_2 + a_3 = 2 - 3 = -1 .

首页