GemNuAi

Time limit: 3s Memory limit: 512MB Input: Output:

Jam in eye because you are kinda clumsy. In spite of this, you're a mega chef, and have unreasonably high standards, only cooking with golden knives. This isn't really your story, it's the story of NN chefs numbered from 00 to N1N-1 (sorted by how rare they like their meat cooked). For each such chef, 22 intervals are known, chef ii being represented by the intervals [Ai,Bi][A_i, B_i] and [Ci,Di][C_i, D_i], respectively. These intervals are represented on the culinary axis with values from 11 to NN, where each element represents a type of dish. For each chef ii, it is known that he can prepare any dish in the interval [Ai,Bi][A_i, B_i], but in the event that he takes part in an international culinary competition (very unlikely), he wishes to prepare for the competition the dishes in the interval [Ci,Di][C_i, D_i] (and you know how life is, what you can do isn't always what you want to do).

And boom, an international culinary competition follows (who would have expected it?) called Shawarma Fest — for if it weren't true, it wouldn't be worth mentioning. The chefs started forming teams, and the gossip is in full swing. There are 22 big criteria for a subset of chefs to be able to form a team:

  • They must represent a contiguous interval of indices. For example, the chef with index 33 can team up with the chef with index 66 only if chefs 44 and 55 also join the team. Not for any other reason, but because chef 33, who cooks his meat rarer, won't team up with just any old-fashioned chef with index 66 who cooks his meat more "well done," unless all the other chefs in between are also on the team to mediate the conflict and make sure they don't argue until time runs out.

  • In addition, an interval of chefs [x,y][x, y] can form a team if, for every chef ii in the team and for every dish jj in the interval [Ci,Di][C_i, D_i], there exists at least one chef kk in the team (kk can be equal to ii) who can cook dish jj.

Requirement

You are given QQ queries, each query consisting of two indices xx and yy. For each query, you must determine whether the subsequence [x,y][x, y] of chefs can form a team or not.

Depending on how skilled you feel, you may choose to answer these queries offline (requirement 11) or online (requirement 22), and you will receive points accordingly.

Implementation Details

You will need to implement several functions. The first of them is:

int precompute(int N, int Q, std::vector<int> A, std::vector<int> B, std::vector<int> C, std::vector<int> D)

which receives as parameters:

  • NN, the total number of chefs
  • QQ, the number of queries
  • A,B,CA, B, C and DD, vectors with the meaning given in the statement

The precompute function must process the received data and then return a value from the set {1,2}\{1, 2\} depending on which requirement you choose to solve. Next, you will need to implement one function for each requirement, called cerinta_1 and cerinta_2.

std::vector<bool> cerinta_1(std::vector<std::pair<int, int>> queries)

which:

  • receives as a parameter queries, a vector indexed from 00 containing the QQ queries;
  • returns a vector of length QQ where position ii holds the answer to the ii-th query, for 0i<N0 \leq i < N.
bool cerinta_2(std::pair<int, int> query)

which:

  • receives as a parameter query, a pair representing a single query;
  • returns true if the answer to the query is positive and false otherwise.

For a test in which the precompute function returned the value:

  • 1 1 \ - the cerinta_1 function will be called exactly once;
  • 2 2 \ - the cerinta_2 function will be called QQ times.

Note that if you always opt for the same requirement, then you are not required to implement a valid solution for both cases, but you must still include a definition of the function. See the template in sample-solution.cpp.

Constraints and Notes

  • 1N500 0001 \leq N \leq 500 \ 000.
  • 1Q5 000 0001 \leq Q \leq 5 \ 000 \ 000.
  • 1AiBiN1 \leq A_i \leq B_i \leq N.
  • 1CiDiN1 \leq C_i \leq D_i \leq N.
  • 0LiRi<N0 \leq L_i \leq R_i < N.
  • Solving requirement 11 is worth 70%70\% of the test's score.
# Score Constraints
1 4 1N,Q10 0001 \leq N, Q \leq 10 \ 000
2 7 Ai=Bi,Ci=Di, 0i<NA_i = B_i, C_i = D_i, \forall \ 0 \le i < N and N,Q200 000N, Q \leq 200 \ 000
3 13 LiLi+1,RiRi+1, 0i<Q1L_i \leq L_{i+ 1}, R_i \leq R_{i + 1}, \forall \ 0 \le i < Q - 1 and N,Q200 000N, Q \leq 200 \ 000
4 11 N,Q200 000N, Q \leq 200 \ 000
5 14 Ai=BiA_i = B_i and N,Q200 000, 0i<NN, Q \leq 200 \ 000, \forall \ 0 \le i < N
6 17 N100 000N \leq 100 \ 000
7 34 No additional restrictions.

Example 1

input

10 3
1 3 1 2 1 1 1 1 2 1
3 3 3 2 2 1 2 2 3 3
1 1 2 1 1 1 2 1 2 1
1 3 2 2 1 3 2 1 2 2
2 4
5 7
7 9

output

query 0: 1
query 1: 0
query 2: 1

Explanation

The chefs in the subsequence [2,4][2, 4] can together prepare the dishes {1,2,3}\{1, 2, 3\}, therefore they can be part of the same team.

The chefs in the subsequence [5,7][5, 7] cannot together prepare the dishes {1,2}\{1, 2\}, which do not fully cover the interval [C5,D5][C_5, D_5]

Log in or sign up to be able to send submissions!