Help me in solving SPC2025Q5 problem

My issue

how to optimise this

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
	// your code goes here
	int t,i;
	cin>>t;
	for (i=0; i< t; i++)
	{
	    long long  n,l,r;
	    cin>>n>>l>>r;
	    vector<long long > arr(n);
	    long long   j,k;
	    for (j=0; j< n ; j++)
	    {
	        cin>>arr[j];
	    }
	    long long prod;
	    sort (arr.begin(), arr.end());
	    if (check(arr))
	    {
	        prod=0;
	    }
	    else
	    
	    prod=1;
	    int flag=0;
	    for (j=0; j< n-1; j++)
	    {
	        for (k=j+1; k< n; k++)
	        {
	            if (arr[j]==arr[k])
	            {
	                prod=0;
	                break;
	            }
	            prod*=(arr[j]^ arr[k]);
	            
	        }
	    }

	    if (prod>=l and prod<=r)
	    {
	        cout << "YES\n";
	    }
	    else
	    {
	        cout << "NO\n";
	    }
	}

}

Problem Link: Halloween Array Practice Coding Problem

if prod at any time become greater than r you can break the loop
this will happen for all n>10 other than the case where prod becomes 0
and for n<=10 you can solve it using O(n^2)