PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GL0000030. Phần dư của tổng bằng độ dài (Rem of Sum is Num)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Phần dư của tổng bằng độ dài (Rem of Sum is Num)
Rem of Sum is Num
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given positive integers and modulus , count nonempty contiguous subarrays whose sum modulo equals their length . Different locations count separately.
Input
First line: . Second line: integers .
Output
Print the number of qualifying subarrays.
Subtasks
- Subtask 1 (20 points): ; ;
- Subtask 2 (30 points): ; ;
- Subtask 3 (50 points): ; ;
Examples
Input
5 4
1 4 2 3 5
Output
4
Explanation
The four valid subarrays are , , and . A qualifying length must be smaller than .