PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000031. Đếm bước tăng phần dư (Modularness)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Đếm bước tăng phần dư (Modularness)
Modularness
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given a nonnegative sequence , each query defines and for . Count positions where . All queries share the same step sequence.
Input
First line: . Second line: numbers . Then lines with .
Output
Print lines, one answer for each query.
Subtasks
- Subtask 1 (20 points): ; ; ; ;
- Subtask 2 (30 points): ; ; ; ;
- Subtask 3 (50 points): ; ; ; ;
Examples
Input
3 1
3 1 4
5 3 2
Output
1
Explanation
The sequence is , giving remainders modulo . Exactly one adjacent pair is increasing.