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 chefs numbered from to (sorted by how rare they like their meat cooked). For each such chef, intervals are known, chef being represented by the intervals and , respectively. These intervals are represented on the culinary axis with values from to , where each element represents a type of dish. For each chef , it is known that he can prepare any dish in the interval , 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 (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 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 can team up with the chef with index only if chefs and also join the team. Not for any other reason, but because chef , who cooks his meat rarer, won't team up with just any old-fashioned chef with index 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 can form a team if, for every chef in the team and for every dish in the interval , there exists at least one chef in the team ( can be equal to ) who can cook dish .
Requirement
You are given queries, each query consisting of two indices and . For each query, you must determine whether the subsequence of chefs can form a team or not.
Depending on how skilled you feel, you may choose to answer these queries offline (requirement ) or online (requirement ), 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:
- , the total number of chefs
- , the number of queries
- and , vectors with the meaning given in the statement
The precompute function must process the received data and then return a value from the set 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 containing the queries; - returns a vector of length where position holds the answer to the -th query, for .
bool cerinta_2(std::pair<int, int> query)
which:
- receives as a parameter
query, a pair representing a single query; - returns
trueif the answer to the query is positive andfalseotherwise.
For a test in which the precompute function returned the value:
- the
cerinta_1function will be called exactly once; - the
cerinta_2function will be called 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
- .
- .
- .
- .
- .
- Solving requirement is worth of the test's score.
| # | Score | Constraints |
|---|---|---|
| 1 | 4 | |
| 2 | 7 | and |
| 3 | 13 | and |
| 4 | 11 | |
| 5 | 14 | and |
| 6 | 17 | |
| 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 can together prepare the dishes , therefore they can be part of the same team.
The chefs in the subsequence cannot together prepare the dishes , which do not fully cover the interval