Length of arithmetic progressions
Practice
3.6 (25 votes)
Advanced data structures
Data structures
Segment trees
Problem
43% Success 10493 Attempts 30 Points 5s Time Limit 256MB Memory 1024 KB Max Code
You are given an integer array \(A\) of size \(N \). You are also given \(Q \) queries. In each query, you are given three integers \(L\), \(R\), and \(D\) respectively.
You are required to determine the length of the largest contiguous segment in the indices range \([L,R]\) of \(A \) that forms an arithmetic progression with a common difference of \(D\).
Note: The segment whose length is \(1\) always forms an arithmetic progression of a common difference \(D\).
Input format
- First line: Two space-separated integers \(N\) and \(Q \) respectively
- Second line: \(N\) space-separated integers denoting elements of \(A \)
- Next \(Q \) lines: Three space-separated integers \(L\), \(R\), and \(D\) \((1 \le L \le R \le N)\) respectively
Output format
Print \(Q \) lines representing the answer such as the \(i^{th} \) line denotes the answer for the \(i^{th} \) query.
Constraints
\(1 \le N \le 200000\)
\(1 \le A_i \le 200000\)
\(-200000 \le D \le 200000\)
Submissions
Please login to view your submissions
Similar Problems
Points:30
6 votes
Tags:
Binary SearchMediumRange QueriesSegment TreesSets
Points:30
6 votes
Tags:
Advanced Data StructuresData StructuresMediumSegment Trees
Points:30
330 votes
Tags:
AlgorithmsApprovedFenwick TreeMediumOpen
Editorial