PivotOJ

Obstacles for a Llama

시간 제한: 2000ms메모리 제한: 2048MB출처: IOI 2025BOJ 34264

문제

A llama wants to travel through the Andean Plateau. It has a map of the plateau in the form of a grid of N×MN \times M square cells. The rows of the map are numbered from 00 to N1N-1 from top to bottom, and the columns are numbered from 00 to M1M-1 from left to right. The cell of the map in row ii and column jj (0i<N,0j<M0 \leq i < N, 0 \leq j < M) is denoted by (i,j)(i, j).

The llama has studied the climate of the plateau and discovered that all cells in each row of the map have the same temperatureand all cells in each column of the map have the same humidity. The llama has given you two integer arrays TT and HH of length NN and MM respectively. Here T[i]T[i] (0i<N0 \leq i < N) indicates the temperature of the cells in row ii, and H[j]H[j] (0j<M0 \leq j < M) indicates the humidity of the cells in column jj.

The llama has also studied the flora of the plateau and noticed that a cell (i,j)(i, j) is free of vegetation if and only if its temperature is greater than its humidity, formally T[i]>H[j]T[i] > H[j].

The llama can travel across the plateau only by following valid paths. A valid path is a sequence of distinct cells that satisfy the following conditions:

  • Each pair of consecutive cells in the path shares a common side.
  • All cells in the path are free of vegetation.

Your task is to answer QQ questions. For each question, you are given four integers: L,R,SL, R, S, and DD. You must determine whether there exists a valid path such that:

  • The path starts at cell (0,S)(0, S) and ends at cell (0,D)(0, D).
  • All cells in the path lie within columns LL to RR, inclusive.

It is guaranteed that both (0,S)(0, S) and (0,D)(0, D) are free of vegetation.

코드를 제출하려면 로그인하세요.