PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#CT0000057. Cùng nhịp (Same Rhythm)
Bài tập này chưa được xếp vào lộ trình.
Mục lục đề ⌄
Đang đọc
Cùng nhịp (Same Rhythm)
Same Rhythm
Version: Phuoc Hung OJ Extended
Problem Statement
Given an integer sequence and an integer .
For two positions , the pair is called a same-rhythm pair if
Count the number of same-rhythm pairs.
Input
The first line contains and .
The second line contains .
Output
Print one integer: the number of valid pairs .
Subtasks
- Subtask 1 (30%): , , .
- Subtask 2 (30%): , , .
- Subtask 3 (40%): , , .
Examples
Example 1
Input
5 2
3 5 8 9 11
Output
6
Explanation
The valid pairs are .
Example 2
Input
4 0
7 7 8 7
Output
3
Explanation
When , both endpoints must have equal values. The three positions containing form pairs.
Example 3
Input
4 -1
5 4 3 10
Output
3
Explanation
Pairs all have average change .
Liên quan
Trong các cuộc thi sau: