Codechef problem

#include
using namespace std;

int main() {
// your code goes here
long long int n,q,l,r,sum,diff;
cin >> n;
long long int a[n];
for(int i=0;i<n;i++ ){
cin >> a[i];
}

cin >> q;

int d;
for(int i=0;i<q;i++) {
cin >> l >> r >> d;
sum=0;
diff=0;
for(int j=0;j<n;j++) {

    diff=r-j*d;
    if(diff >=l) {
        sum=sum+a[diff-1];
    }
}

cout << sum << endl;

}

return 0;
}

how to reduce its time complexity?? please anyone fast

@Sahilgohrisg you can use this approach
Initialize two vectors v1 and v2 which stores decreasing and increasing numbers.
Use hashing to know the occurrence of the number in the array.
If the number appears to come for the first time, then store it in v1.
If the number appears to come for the second time, then store it in v2.
If the number appears for more than 2 times, then it is not possible to store to create a strictly decreasing and strictly increasing array.
At last, sort the first vector in decreasing order and the second vector in increasing order and print them.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.