Yet Another Contest 5 P5 - No More Concerts

View as PDF

Submit solution


Points: 20 (partial)
Time limit: 2.0s
Java 4.0s
Python 4.0s
Memory limit: 512M

Author:
Problem types

Mike is sick of listening to concerts during lunchtime at his school! Unfortunately for him, a single concert will be hosted on the school field on each of the next N days.

The school field can be represented as a rectangle with the bottom-left corner (0,0) and upper-right corner (W,H) on a 2-D Cartesian plane, and the location of each concert can be represented by a single point within the rectangle. There is also a concession area, whose initial location can be represented as a rectangle with the bottom-left corner (0,0) and upper-right corner (W,1).

On the first day, the concert will be hosted at (x1,y1). At the end of the i-th day, the concert will be moved by ai units to the right and bi units upwards. To maximize attraction, the concession stand will adjust accordingly and move its upper-right corner bi units upwards. Note that the bottom-left corner of the concession area always remains at (0,0).

Since Mike does not like listening to repetitive music and would much rather buy snacks from the concession, he wants to choose a rectangular region within the school field to eat his lunch such that over the N days, no point within the rectangular region is ever closer to the concert than the concession area, in terms of Euclidean distance. The rectangular region must be axis-aligned, have a positive area, and the bottom-left corner and upper-right corner of the rectangle must have integral coordinates.

The distance between a point and the concession area is defined as the shortest Euclidean distance between the point and any point inside the rectangular region, including on its boundary. Of course, if a point resides within the concession area, its distance to the concession area is 0.

Can you help Mike find the number of possible rectangle regions that he can eat his lunch at over the next N days? Since this value may be large, output it modulo 998244353.

Constraints

1N,W106

2H109

0x1W

2y1H

|ai|W

|bi|H

It is guaranteed that each concert will remain within the school field, possibly on its boundary.

It is guaranteed that the y-coordinate of the concession area will always be positive.

Subtask 1 [15%]

W=1

Subtask 2 [15%]

ai=0

Subtask 3 [35%]

1N20

Subtask 4 [35%]

No additional constraints.

Input Specification

The first line contains three integers, N, W and H.

The second line contains two integers, x1 and y1.

The next N1 lines contain two integers, ai and bi, representing the horizontal shift and vertical shift of the concert at the end of the i-th day.

Output Specification

On a single line, print the number of possible rectangular regions that Mike can choose modulo 998244353.

Sample Input 1

Copy
2 5 4
2 2
1 1

Sample Output 1

Copy
26

Explanation for Sample Output 1

One possible rectangular region that Mike can select is highlighted yellow in the diagram below. It can be shown that no point within this rectangle is closer to the concert than the concession area on either day.

Sample Input 2

Copy
1 2 2
1 2

Sample Output 2

Copy
3

Explanation for Sample Output 2

The 3 possible rectangular regions that Mike can select are shown below.

Sample Input 3

Copy
3 1000000 1000000000
101010 101010101
101010 101010101
101010 101010101

Sample Output 3

Copy
691313810

Explanation for Sample Output 3

Be sure to print the result modulo 998244353.

Sample Input 4

Copy
6 49 20
9 10
21 0
-30 10
49 -5
0 0
-9 -4

Sample Output 4

Copy
21096

Comments

There are no comments at the moment.