PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000292. Tổng đoạn cực dài trên dãy tuần hoàn (Very Long Periodic Range Sum)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng đoạn cực dài trên dãy tuần hoàn (Very Long Periodic Range Sum)
Very Long Periodic Range Sum
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
The infinite sequence is defined by for . For each half-open range , sum its elements. An empty range has sum zero.
Input
First line: . Second line: array elements. Each of the next lines contains .
Output
Print each answer on its own line.
Subtasks
- Subtask 1 (20 points): , , . Additionally: , .
- Subtask 2 (30 points): , , . Additionally: all queries satisfy .
- Subtask 3 (50 points): , , .
Example 1
Input
3 3
2 -3 4
0 8
2 5
4 4
Output
5
3
0
Explanation
Two complete periods give 6 and the remaining 2,-3 give 5. The second range gives 4+2-3=3; the empty range gives 0.
Example 2
Input
1 1
9
0 10
Output
90
Explanation
There are exactly 10 copies of 9.