103543: [Atcoder]ABC354 D - AtCoder Wallpaper
Description
Score : $450$ points
Problem Statement
The pattern of AtCoder's wallpaper can be represented on the $xy$-plane as follows:
-
The plane is divided by the following three types of lines:
- $x = n$ (where $n$ is an integer)
- $y = n$ (where $n$ is an even number)
- $x + y = n$ (where $n$ is an even number)
- Each region is painted black or white. Any two regions adjacent along one of these lines are painted in different colors.
- The region containing $(0.5, 0.5)$ is painted black.
The following figure shows a part of the pattern.
You are given integers $A, B, C, D$. Consider a rectangle whose sides are parallel to the $x$- and $y$-axes, with its bottom-left vertex at $(A, B)$ and its top-right vertex at $(C, D)$. Calculate the area of the regions painted black inside this rectangle, and print twice that area.
It can be proved that the output value will be an integer.
Constraints
- $-10^9 \leq A, B, C, D \leq 10^9$
- $A < C$ and $B < D$.
- All input values are integers.
Input
The input is given from Standard Input in the following format:
$A$ $B$ $C$ $D$
Output
Print the answer on a single line.
Sample Input 1
0 0 3 3
Sample Output 1
10
We are to find the area of the black-painted region inside the following square:
The area is $5$, so print twice that value: $10$.
Sample Input 2
-1 -2 1 3
Sample Output 2
11
The area is $5.5$, which is not an integer, but the output value is an integer.
Sample Input 3
-1000000000 -1000000000 1000000000 1000000000
Sample Output 3
4000000000000000000
This is the case with the largest rectangle, where the output still fits into a 64-bit signed integer.
Output
问题描述
AtCoder的壁纸图案在笛卡尔坐标系$xy$平面上可以表示如下:
-
平面被以下三种类型的线分成多个区域:
- $x = n$(其中$n$是整数)
- $y = n$(其中$n$是偶数)
- $x + y = n$(其中$n$是偶数)
- 每个区域被涂成黑色或白色。沿着这些线相邻的两个区域颜色不同。
- 包含点$(0.5, 0.5)$的区域被涂成黑色。
以下图显示了图案的一部分。
给你四个整数$A, B, C, D$。考虑一个长和宽平行于$x$轴和$y$轴的矩形,其左下角坐标为$(A, B)$,右上角坐标为$(C, D)$。计算这个矩形内部被涂成黑色的区域的面积,并输出该面积的两倍。
可以证明输出的值是一个整数。
约束
- $-10^9 \leq A, B, C, D \leq 10^9$
- $A < C$ 且 $B < D$。
- 所有输入值都是整数。
输入
标准输入提供以下格式的输入:
$A$ $B$ $C$ $D$
输出
在一行中打印答案。
样例输入1
0 0 3 3
样例输出1
10
我们需要找到以下正方形内黑色区域的面积:
面积为$5$,所以输出其两倍值:$10$。
样例输入2
-1 -2 1 3
样例输出2
11
面积为$5.5$,不是一个整数,但输出值是一个整数。
样例输入3
-1000000000 -1000000000 1000000000 1000000000
样例输出3
4000000000000000000
这是最大的矩形情况,输出仍然能容纳在一个64位有符号整数内。