PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CC0000031. Gom các số thành đoạn liên tiếp (Data Stream as Disjoint Intervals)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Gom các số thành đoạn liên tiếp (Data Stream as Disjoint Intervals)
Data Stream as Disjoint Intervals
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
Initially no non-negative integer has been observed. The operation A x records integer ; recording the same value again changes nothing. The operation G` reports the set of observed integers as the maximal disjoint consecutive integer intervals , inclusive at both endpoints. Output intervals in increasing order of their left endpoint.
Input
The first line contains . The next lines each contain either A x or just G.
Output
For each G, first print the number of intervals, followed by lines each containing the endpoints . If none exist, print 0.
Subtasks
- Subtask 1 (20 points): ; ; at most operations
G. - Subtask 2 (30 points): ; ; at most operations
G. - Subtask 3 (50 points): ; ; at most operations
G.
Examples
Input
7
A 1
A 3
G
A 2
G
A 7
G
Output
2
1 1
3 3
1
1 3
2
1 3
7 7
Explanation
Values 1 and 3 form separate intervals. Adding 2 merges them, and adding 7 creates another interval.