【CF 1080B】Margarite and the best present

                          B. Margarite and the best present

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 109109 elements that is filled as follows:

  • a1=−1a1=−1
  • a2=2a2=2
  • a3=−3a3=−3
  • a4=4a4=4
  • a5=−5a5=−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)iai=i⋅(−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!

Input

The first line contains a single integer qq (1≤q≤1031≤q≤103) — the number of the queries.

Each of the next qq lines contains two integers ll and rr (1≤l≤r≤1091≤l≤r≤109) — the descriptions of the queries.

Output

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

Example

input

5
1 3
2 5
5 5
4 4
2 3

output

-2
-2
-5
4
-1

代码:

#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
using namespace std;
#define ll long long
#define inf 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
#define closeio std::ios::sync_with_stdio(false)
 
int main()
{
	ll n,a,b,i,t;
	cin>>n;
	while(n--)
	{
		cin>>a>>b;
		if(a%2==1)
		{
			if(b%2==1)
				t=(b-a)/2-b;
			else
				t=(b+1-a)/2;		
		}
		else
		{
			if(b%2==1)
				t=(a-b-1)/2;
			else
				t=(a-b)/2+b;
		}
		cout<<t<<endl;
	}	
	return 0;
}

 

全部评论

相关推荐

11-28 16:00
已编辑
武汉理工大学 Java
想干测开的tomca...:这份简历是“短期项目硬堆中大型系统技术”的“技术炫技式造假模板”,槽点密集到能当反面教材: ### 1. 「项目时长」和「技术密度」严重脱节,造假痕迹焊死在简历上 两个项目时长分别是**3个月、2个月**,但堆了Spring AI、Elasticsearch、MinIO、Kafka、ShardingSphere、Docker、Sentinel等近20个中大型项目才用的技术——正常情况下,光把这些中间件的文档看完+环境搭好,3个月都不够,更别说实现“AI多轮对话、分库分表、RBAC权限、大模型调用”这些功能。 说白了:你这不是“做项目”,是把“后端技术栈清单”往项目里硬塞,明摆着“只调用了API,没碰过核心逻辑”。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务