#P13508. [OOI 2024] Burenka and Pether
[OOI 2024] Burenka and Pether
题目描述
Once upon a time, the princess of Burlyandia, Burenka, decided to please her friend ReLu. Knowing that ReLu shares her interest in cryptocurrency, Burenka decided to create her own blockchain cryptocurrency called .
After taking courses and training from an expert coach in personal growth in cybersecurity, Burenka decided that the currency should be protected in the best possible way. As a result, due to incredibly complex and convoluted restrictions, not all users can exchange with each other.
The structure of the blockchain currency is indeed complex and convoluted. All users are numbered with integers from to . Each user is assigned a identifier . Also, the currency has a security parameter .
User can directly transfer currency to user only if and . But that's not enough! Direct currency transfer between users occurs through a chain of transactions involving some number of intermediate users. During each transaction, the number of each subsequent intermediate user (including the last user ) must increase, but not by more than . Also, all intermediate users except and must have an identifier strictly less than .
More formally, user can directly transfer cryptocurrency to user if the following conditions are met:
- It is satisfied that
- It is satisfied that
- There exists a sequence of intermediate users of length such that:
- For all , it is true that
- For all , it is true that
Burenka asks you, her acquaintance programmer, to understand this system and find out for some pairs of users how to transfer to each other.
You need to answer queries. In each query, you need to determine whether there is a sequence of direct currency transfers (possibly through intermediate users) that allows transferring from user to user . In some queries, it is also necessary to minimize the number of direct currency transfers in the process of sending currency from to . Please note that it is not necessary to minimize the number of transactions during each direct transfer.
输入格式
The first line contains three integers , , and --- the number of users, the security parameter, and the test group number.
The second line contains integers --- user identifiers. It is guaranteed that all numbers are .
The third line contains a single integer --- the number of queries.
The next lines contain three integers each , where is the user who should transfer the currency, and is the user who should receive the currency. If , then it is necessary to determine whether it is possible to transfer the currency, and if , then it is also necessary to minimize the number of direct currency transfers.
输出格式
Output lines, where the -th line should contain the answer to the -th query.
If it is not possible to transfer the currency from user to user , then output 0 as the answer to the -th query. Otherwise, if , output 1, and if , output the minimum number of direct currency transfers required to transfer from to .
6 1 0
2 1 3 4 5 6
6
2 1 3
2 1 2
1 1 4
2 1 5
2 1 6
1 2 6
1
0
1
3
4
1
6 2 0
1 2 3 4 5 6
6
2 1 5
2 2 5
2 1 6
2 2 6
2 1 4
2 2 4
2
2
3
2
2
1
10 2 0
2 1 4 3 5 6 8 7 10 9
10
2 1 5
1 2 5
2 3 5
2 1 9
2 5 8
2 3 9
2 1 8
1 1 2
2 3 8
2 1 9
2
1
1
4
2
3
3
0
2
4
提示
Note
In the first example, the following direct transfers between users are possible:
In the first query, user with index can directly transfer to user with index , making 2 transactions through intermediate user 2.
In the second query, a direct transfer between users with indices and is not possible, as .
In the third query, it is possible to transfer the currency from user to user with two direct transfers, first transferring the currency from user to user , and then from to . Since , it is only necessary to determine the possibility of transferring the currency, so the answer to the query is 1.
In the fourth query, it is possible to manage with three direct transfers: from to , from to , and from to .
In the second example, the following direct transfers between users are possible:
In the third example, the following direct transfers between users are possible:
Scoring
The tests for this problem consist of twelve groups. Points for each group are given only if all tests of the group and all tests of the required groups are passed. Please note that passing the example tests is not required for some groups. means that the results of testing your solution on this group will only be available after the end of the competition.
Group | Points | Additional constraints | < | Required groups | Comment | |
---|---|---|---|---|---|---|
0 | -- | -- | -- | Examples. | ||
1 | 10 | |||||
2 | 7 | -- | 1 | |||
3 | 14 | -- | -- | |||
4 | 10 | |||||
5 | 9 | -- | 3, 4 | |||
6 | 7 | -- | The answer does not exceed | |||
7 | 1, 6 | The answer does not exceed | ||||
8 | 13 | -- | ||||
9 | 10 | -- | 1 | |||
10 | 4 | 1, 9 | ||||
11 | 1, 9, 10 | |||||
12 | 5 | -- | 0--11 | Offline-evaluation. |