Farmers of the god


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Two farmers, Ahura and Mazda, want to plant vegetable crops on a shared land. Ahura always plants cucumbers, while Mazda always plants tomatoes.

They divide the land into n separate rectangles, with each rectangle aligned parallel to the xx and yy coordinate axes. Each of them then marks specific rectangles where they want plant their crops.

Ahura has chosen n1n_1​ rectangles for planting cucumbers, and Mazda has chosen n2n_2​ rectangles for planting tomatoes. we know we cant plant both cucumber and tomato in exactly one place. because of that, After marking their rectangles, they check for any overlapping areas on the land. To avoid conflicts, they agree not to plant anything in these overlapping areas. They will only plant cucumbers and tomatoes in the non-overlapping parts of their designated rectangles.

The goal is to calculate the difference in the area planted by each farmer. Let:

  • S1S_1​ represent the total area where Ahura will plants cucumbers,
  • S2S_2​ represent the total area where Mazda will plants tomatoes.

Your task is to compute S1S2S_1-S_2​ and output this value

input🔗

The first line contains a positive integer n1n_1​, the number of rectangles Ahura has chosen for planting cucumbers at first. The next n1n_1​ lines each contains the two opposite corners of each rectangles, x1x_1 and y1y_1, the bottom left corner and then x2x_2 ​, y2y_2​ , representing the upper right corner coordinate of the rectangle designated by Ahura.

The following line contains a positive integer n2n_2​, the number of rectangles Mazda has chosen for planting tomatoes at first. The next n2n_2​ lines each contains the two opposite corners of each rectangles, x1x_1 and y1y_1, the bottom left corner and then x2x_2 ​, y2y_2​ , representing the upper right corner coordinate of the rectangle designated by Mazda.

  • It is guaranteed that Ahura's rectangles do not overlap with each other.
  • It is guaranteed that Mazda's rectangles do not overlap with each other.

1n1,n21001 \leq n_1, n_2 \leq 100 1000x1x21000-1000 \leq x_1 \leq x_2 \leq 1000 1000y1y21000-1000 \leq y_1 \leq y_2 \leq 1000

output🔗

Output a single integer, the value of S1S2S_1 - S_2, which is the difference in the areas of land planted by Ahura and Mazda.

example🔗

sample input 1🔗

1
0 0 10 10
1
5 5 15 15
Plain text

Ahura and Mazda have overlapping areas in their marked rectangles. Since they avoid planting in these overlapping areas, the non-overlapping areas for both farmers result in an equal area, making S1​−S2​=0.

sample output 1🔗

0
Plain text

sample input 2🔗

2
0 0 2 4
3 5 4 7
1
1 3 2 9
Plain text

sample output 2🔗

4
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.