PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000284. Theo dõi các đoạn đẹp (Tracking Segments)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Theo dõi các đoạn đẹp (Tracking Segments)
Tracking Segments
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
An array of zeros has monitored intervals , which may repeat. An interval is beautiful when its ones strictly outnumber its zeros. Change j sets , with all positions distinct. Find the first change after which any monitored interval is beautiful, or if none ever is.
Input
First line: . The next m lines contain . The next line contains , followed by q lines with one each.
Output
Print the first change number (1-based), or .
Subtasks
- Subtask 1 (20 points): ; ; ; ; are pairwise distinct.
- Subtask 2 (30 points): ; ; ; ; are pairwise distinct.
- Subtask 3 (50 points): ; ; ; ; are pairwise distinct.
Examples
Input 1
5 2
1 5
2 4
4
1
5
3
2
Output 1
3
Explanation
After two changes [1,5] has two ones; after the third it has three ones and two zeros.
Input 2
4 2
1 1
4 4
2
2
3
Output 2
-1
Explanation
Neither monitored position changes.