#P10763. [BalticOI 2024] Tiles

    ID: 12231 远端评测题 1000ms 500MiB 尝试: 0 已通过: 0 难度: 8 上传者: 标签>线段树平衡树2024扫描线BalticOI(波罗的海)

[BalticOI 2024] Tiles

Background

Translated from BalticOI 2024 Day2 T2.

Problem Description

There is a cathedral with NN vertices, whose coordinates are (xi,yi)(x_i,y_i) in order. For each 1i<N1 \leq i < N, there is an edge between ii and i+1i+1. In addition, there is an edge between NN and 11.

Each edge of the cathedral is parallel to the xx axis or the yy axis. Also, the cathedral is a simple polygon, meaning that:

  • Each vertex is incident to exactly two edges.
  • Any pair of edges can intersect only at a vertex.

You have infinitely many 2×22 \times 2 tiles, and you want to use these tiles to cover most of the cathedral region. More precisely, you want to choose a vertical line and cover the part of the cathedral to the left of that line. For any integer kk, let LkL_k be the vertical line that contains the points with xx coordinate equal to kk. Covering the part of the cathedral to the left of LkL_k means placing some tiles on the plane such that:

  • Every point inside the polygon with xx coordinate less than kk is covered by some tile.
  • No point outside the polygon, or with xx coordinate greater than kk, is covered by any tile.
  • The interiors of the tiles do not overlap.

The minimum xx coordinate among all vertices of the cathedral is 00. Let MM be the maximum xx coordinate among all vertices of the cathedral.

Please find the maximum k (0kM)k\ (0 \leq k \leq M) that satisfies the conditions. By definition, an answer of 00 always exists.

Input Format

The first line contains two integers N,MN,M.

The next NN lines each contain two integers (xi,yi)(x_i,y_i). The vertices are given in clockwise or counterclockwise order.

Output Format

Output the answer kk.

14 6
0 1
0 3
2 3
2 4
0 4
0 6
3 6
3 7
4 7
6 7
6 5
3 5
3 2
3 1

2
4 3
0 0
0 3
3 3
3 0
0
18 9
0 2
2 2
2 1
4 1
4 0
9 0
9 2
4 2
4 4
7 4
7 3
9 3
9 6
4 6
4 5
2 5
2 4
0 4
6

Hint

Subtask ID Special Property Score
11 N=4N=4 44
22 N6N \leq 6 99
33 xN=0,yN=0x_N=0,y_N=0,for 1iN21 \leq i \leq N-2xixi+1,yiyi+1x_i \leq x_{i+1},y_i \geq y_{i+1} 1111
44 M1000M \leq 1000 and yi1000y_i \leq 1000 1919
55 All yiy_i are even 2222
66 All xix_i are even 2525
77 No special property 1010

For all testdata, 4N2×1054 \leq N \leq 2 \times 10^5, 1M1091 \leq M \leq 10^9, 0yi1090 \leq y_i \leq 10^9, min({xi})=0,max({xi})=M\min(\{x_i\}) = 0,\max(\{x_i\}) = M.

For Sample 1, below is the covering for k=2k=2.

You can see that this is the largest possible case.

For Sample 2, there is no positive kk such that the part of the cathedral to the left of LkL_k can be covered with tiles.

For Sample 3, the diagram is as follows.

Translated by ChatGPT 5