Exists or Not Exists

You will be given some numbers. Then there will contain some queries. In every query there will be g…

Click here to read the complete problem statement.


If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.

Please help me with my code, I don’t understand what’s going wrong.

#include<iostream>

int main()
{
    int n,q,l,r,x;
    std::cin >> n >> q;
    int a[n];
    for(int i=0;i<n;i++){
        std::cin>> a[i];
    }
    for(int i=0;i<q;i++){
        std::cin >> l >> r >> x;
        bool c = false;
        for(int j=l-1;j<r;j++){
            if(x==a[j]){
                c = true;
                break;
            }
        }

        if(c){
            std::cout << "YES\n" ;
        }
        else{
            std::cout << "NO\n";
        }
    }

}