Given an array, A=[a0,a1,a2...an], perform queries in the form left right x y. For each query, print the number of elements satisfying the following criteria:
- left < i < right
- a[i] = y(mod x)
Note: We can write a[i] = y(mod x) as a[i] % x == y in most popular programming languages.
Input Format
The first line contains two space-separated integers describing the respective values of (the size of ) and (the number of queries). The second line has space-separated integers describing the respective values of . Each of the subsequent lines describes a query in the form left right x y.
Output Format
For each query, print an integer denoting the number of array elements satisfying the given criteria on a new line.
Sample Input 0
5 3 250 501 5000 5 4 0 4 5 0 0 4 10 0 0 4 3 2
Sample Output 0
3 2 2
Can this code be optimized in any way?
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
int n,q;
cin>>n>>q;
int A[n];
for(int i=0;i<n;i++)
cin>>A[i];
while(q--)
{
int a,b,x,y,c=0;
cin>>a>>b>>x>>y;
for(int i=a;i<=b;i++)
{
int t=A[i];
if(t%x==y)
c++;
}
cout<<c<<endl;
}
return 0;
}