Sequence and Queries 7
Time limit4sMemory limit512 MB
For each query range, find the longest subarray whose sum is divisible by K.
- Level
Hard8 of 10
- Topics
- Prefix sum, Divide and conquer, Hash map
- Solved
- No attempts yet
Problem
You are given a sequence of length and an integer . Write a program that answers the following query.
l r: print the length of the longest contiguous subsequence with and . If no subsequence satisfies the condition, the length is 0.
Input
The first line contains the size of the sequence () and ().
The second line contains . ()
The third line contains the number of queries ().
Each of the next lines contains one query , . ()
Output
Print the answer to each query on its own line.