#CT00000053. Dãy đèn trang trí (Decorative Lights)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Dãy đèn trang trí (Decorative Lights)
Decorative Lights
Version: Phuoc Hung OJ Extended
Problem Statement
A street has consecutive lamps numbered from to . Initially, all lamps are off.
Each control command specifies two positions and toggles every lamp numbered from through , 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 commands have been executed in order, answer queries. Each query specifies an interval 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 : the number of lamps, the number of control commands, and the number of queries.
- Each of the next lines contains two integers describing an interval to toggle, in execution order. If , there are no command lines.
- Each of the final lines contains two integers specifying the interval to query.
Output
Print exactly lines in query order. Line is the number of lit lamps in the interval of query , measured after all commands.
Subtasks
The following general constraints apply to all subtasks: ; ; ; every interval satisfies .
- Subtask 1 (30%): .
- Subtask 2 (30%): .
- 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 lamps are off. After toggling , lamps are on. After toggling , the lit lamps are . After toggling , the final lit lamps are .
Therefore contains lit lamps; contains lamps ; contains lamps ; and contains lamps . The four answers are .
Example 2
Input
5 0 2
1 5
2 3
Output
0
0
Explanation
Since , no lamp changes state and all lamps stay off. The intervals and each contain 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 . The second command toggles the same interval, turning all six lamps off again. Consequently, both and contain lit lamps.
Liên quan
Trong các cuộc thi sau: