#P7843. 「C.E.L.U-03」布尔
「C.E.L.U-03」布尔
Problem Description
You are given Boolean variables and constraints. Let be the value of variable . The -th constraint is of the form: if is , then must be ; at the same time, if is , then must be .
There are queries in total. Each query gives an interval . Find the minimum number of continuous segments to partition into, such that the constraints within each segment have at least one legal solution. If no legal solution can be obtained no matter what, output -1.
Input Format
The first line contains three integers .
The next lines each contain four integers, representing .
The next lines each contain two integers, representing .
Output Format
For each query, output one integer as the answer. If it is impossible to get an answer, output -1.
3 4 2
1 0 2 0
1 1 3 0
3 0 2 0
1 1 2 1
1 3
3 4
2
1
4 5 3
1 1 2 1
2 0 3 0
4 1 1 0
2 1 4 0
4 0 3 0
1 4
2 5
3 5
1
2
1
Hint
Sample Explanation 1
For the first query, it can be split into two segments: and .
For the second query, it is one segment: .
Sample Explanation 2
For the first query, it is one segment: .
For the second query, it can be split into two segments: and .
For the third query, it is one segment: .
| Data ID | |||
|---|---|---|---|
For of the testdata, $1\le n\le10^5,1\le m\le6\times10^5,1\le q\le10^6,1\le u,v\le n,1\le l\le r\le m,x,y\in \{0,1\}$.
Translated by ChatGPT 5