PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000293. Đi bộ trên vòng tròn nhiều vòng (Multiple Laps on a Weighted Cycle)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đi bộ trên vòng tròn nhiều vòng (Multiple Laps on a Weighted Cycle)
Multiple Laps on a Weighted Cycle
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
A directed cycle has vertices numbered 1 through , and edge leads from vertex to the next vertex with weight (wrapping from to 1). For query , sum the weights of exactly successive edges starting at vertex . Repeated traversals count separately; zero edges give 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
3 5
2 0
1 3
Output
9
0
3
Explanation
Five edges from 3 give 4+2-3+4+2=9. Zero edges give 0; one lap gives 3.
Example 2
Input
1 1
-9
1 10
Output
-90
Explanation
The sole edge is traversed 10 times.