PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000164. Đếm đoạn tổng K có độ dài lẻ (Count Odd-Length Subarrays With Sum K)
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 đoạn tổng K có độ dài lẻ (Count Odd-Length Subarrays With Sum K)
Count Odd-Length Subarrays With Sum K
Source: Phước Hưng OJ
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array of integers , numbered from 1. A nonempty contiguous interval contains all elements from through and has length . Count intervals whose sum is exactly and whose length is odd. Intervals with different endpoints are counted separately.
Input
The first line contains two integers . The second line contains integers .
Output
Print one integer: the number of qualifying intervals.
Subtasks
- Subtask 1 (30 points): ; for all ; .
- Subtask 2 (30 points): ; for all ; .
- Subtask 3 (40 points): ; for all ; .
Example 1
Input
3 1
1 -1 1
Output
3
Explanation
Intervals [1,1], [3,3], [1,3] sum to 1 and have lengths 1,1,3.
Example 2
Input
4 0
0 0 0 0
Output
6
Explanation
Four intervals of length 1 and two of length 3 sum to zero; even lengths are excluded.