PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#SRD0000068. Ann và những cuốn sách (Ann and Books)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Ann và những cuốn sách (Ann and Books)
Ann and Books
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are books, with type (math) or (economics) and exercises. For each range , count nonempty subarrays whose total math exercises minus total economics exercises equals ; can be negative or zero.
Input
First , then all book types, all exercise counts, the number , and inclusive ranges.
Output
Print one 64-bit count per query.
Subtasks
- Subtask 1 (10 points): , . ; ; ; .
- Subtask 2 (20 points): , . ; ; ; .
- Subtask 3 (30 points): , . ; ; ; .
- Subtask 4 (40 points): , . ; ; ; .
Examples
Input
4 1
1 1 1 2
1 1 1 1
4
1 2
1 3
1 4
3 4
Output
2
3
4
1
Explanation
The signed sequence is . Within , the four subarrays of sum 1 are , , , and ; the other queries yield 2, 3, and 1.