PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#CT00000053. Dãy đèn trang trí (Decorative Lights)

Bài tập này chưa được xếp vào lộ trình.

Dãy đèn trang trí (Decorative Lights)

Decorative Lights

Version: Phuoc Hung OJ Extended

Problem Statement

A street has NN consecutive lamps numbered from 11 to NN. Initially, all lamps are off.

Each control command specifies two positions L,RL,R and toggles every lamp numbered from LL through RR, including both endpoints: an off lamp becomes on, and an on lamp becomes off. A lamp included in several commands is toggled once for each such command.

After all MM commands have been executed in order, answer QQ queries. Each query specifies an interval [L,R][L,R] and asks how many lamps are on within it. Every query refers to the same final state, after all commands have finished. Answering queries does not change any lamp.

Input

  • The first line contains three integers N,M,QN,M,Q: the number of lamps, the number of control commands, and the number of queries.
  • Each of the next MM lines contains two integers L,RL,R describing an interval [L,R][L,R] to toggle, in execution order. If M=0M=0, there are no command lines.
  • Each of the final QQ lines contains two integers L,RL,R specifying the interval to query.

Output

Print exactly QQ lines in query order. Line ii is the number of lit lamps in the interval [L,R][L,R] of query ii, measured after all MM commands.

Subtasks

The following general constraints apply to all subtasks: 1≤N≤1091\le N\le 10^9; 0≤M≤2⋅1050\le M\le 2\cdot 10^5; 1≤Q≤2⋅1051\le Q\le 2\cdot 10^5; every interval satisfies 1≤L≤R≤N1\le L\le R\le N.

  • Subtask 1 (30%): N,M,Q≤103N,M,Q\le 10^3.
  • Subtask 2 (30%): M,Q≤104M,Q\le 10^4.
  • Subtask 3 (40%): No additional restrictions beyond the general constraints.

Examples

Example 1

Input

10 3 4
2 5
4 8
8 10
1 10
4 8
2 5
8 10

Output

6
2
2
2

Explanation

Initially all 1010 lamps are off. After toggling [2,5][2,5], lamps 2,3,4,52,3,4,5 are on. After toggling [4,8][4,8], the lit lamps are 2,3,6,7,82,3,6,7,8. After toggling [8,10][8,10], the final lit lamps are 2,3,6,7,9,102,3,6,7,9,10.

Therefore [1,10][1,10] contains 66 lit lamps; [4,8][4,8] contains lamps 6,76,7; [2,5][2,5] contains lamps 2,32,3; and [8,10][8,10] contains lamps 9,109,10. The four answers are 6,2,2,26,2,2,2.

Example 2

Input

5 0 2
1 5
2 3

Output

0
0

Explanation

Since M=0M=0, no lamp changes state and all 55 lamps stay off. The intervals [1,5][1,5] and [2,3][2,3] each contain 00 lit lamps, so the program prints two zeroes.

Example 3

Input

6 2 2
1 6
1 6
1 6
3 3

Output

0
0

Explanation

The first command turns on all six lamps in [1,6][1,6]. The second command toggles the same interval, turning all six lamps off again. Consequently, both [1,6][1,6] and [3,3][3,3] contain 00 lit lamps.