#SRD0000153. Thành lập các đội (Teams)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Thành lập các đội (Teams)
Teams
Source: IOI
Version: Phuoc Hung OJ Extended
Problem Statement
There are students numbered through . Student agrees to join a team only if its size lies within the inclusive integer interval .
On a given day, there are projects. Project requires one team of exactly students. Each student can belong to at most one team during that day. On subsequent days, students are available again.
For each day, determine whether all projects can be assigned disjoint teams of their required sizes, with every participating student accepting the size of their team. Unused students are allowed.
PHOJ adaptation: The original IOI grader calls init(N,A,B) once and then calls can(M,K) for each query. The following standard-I/O form preserves the exact mathematical task and responses.
Input
- The first line contains integer .
- The next lines each contain two integers and for student .
- The next line contains integer , the number of days.
- Each of the next lines begins with integer , followed by integers .
Output
For each day print 1 if all required disjoint teams can be formed and 0 otherwise. Print the answers in query order, one per line.
Subtasks
- Subtask 1 (21 points): ; ; ; ; ; .
- Subtask 2 (13 points): ; ; ; ; ; .
- Subtask 3 (43 points): ; ; ; ; ; .
- Subtask 4 (23 points): ; ; ; ; ; .
Examples
Input
4
2 4
1 2
2 3
2 3
2
2 1 3
2 1 1
Output
1
0
Explanation
The four students accept team sizes , , , $[2,3]. The first query asks for teams of sizes $1$ and $3$: the second student fills the one-person team, and the three others form the second, giving 1. The second query asks for two one-person teams. Only the second student can join either, so the answer is 0`.