#P7843. 「C.E.L.U-03」布尔

    ID: 8397 远端评测题 2500ms 256MiB 尝试: 0 已通过: 0 难度: 9 上传者: 标签>倍增O2优化2-SAT动态树 LCT整体二分

「C.E.L.U-03」布尔

Problem Description

You are given nn Boolean variables and mm constraints. Let sis_i be the value of variable ii. The ii-th constraint is of the form: if suis_{u_i} is xix_i, then svis_{v_i} must be yiy_i; at the same time, if svis_{v_i} is yiy_i, then suis_{u_i} must be xix_i.

There are qq queries in total. Each query gives an interval l,rl,r. Find the minimum number of continuous segments to partition [l,r][l,r] 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 n,m,qn,m,q.
The next mm lines each contain four integers, representing ui,xi,vi,yiu_i,x_i,v_i,y_i.
The next qq lines each contain two integers, representing li,ril_i,r_i.

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: [1,2][1,2] and 33.
For the second query, it is one segment: [3,4][3,4].

Sample Explanation 2
For the first query, it is one segment: [1,4][1,4].
For the second query, it can be split into two segments: [2,3][2,3] and [4,5][4,5].
For the third query, it is one segment: [3,5][3,5].

Data ID nn\leq mm\leq qq\leq
11 3030 100100 300300
242\sim 4 300300 10310^3
575\sim 7 10410^4 5×1045\times10^4 10610^6
8108\sim 10 10510^5 6×1056\times10^5

For 100%100\% 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