I am neither using pointer nor using freed memory but i do not understand what is causing sigsegv error. For some test cases the algorithm is working without any error while for other test case it is showing SIGSEGV.
#include<iostream>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,m;
cin>>n>>m;
int arr[n],arrh[m];
for(int i=0;i<n;i++)
{
cin>>arr[i];
}
for(int i=0;i<m;i++)
{
cin>>arrh[i];
}
int arrcc[m][n]={0}; //Precomputation Cumulative
int val;
for(int j=0;j<m;j++)
{
val=0;
for(int i=0;i<n;i++)
{
if(arr[i]==(j+1))
{
val++;
}
arrcc[j][i]=val;
}
}
int q,l,r;
cin>>q;
int k;
int arrc[m];
while(q--)
{
k=0;
for(int i=0;i<m;i++)
{
arrc[i]=0;
}
cin>>l>>r;
// for(int j=0;j<m;j++) //Time limit exceed need precomputation
// {
// for(int i=(l-1);i<r;i++)
// {
// if(arr[i]==(j+1))
// {
// arrc[j]++;
// }
// }
// }
for(int j=0;j<m;j++) //Calculating from cumulative
{
if(l!=1)
arrc[j]=(arrcc[j][r-1]-arrcc[j][l-2]);
else
arrc[j]=(arrcc[j][r-1]-0);
}
for(int i=0;i<m;i++)
{
if(arrc[i]!=0)
{
if(arrc[i]!=arrh[i])
{
cout<<"0"<<"\n";
k++;
break;
}
}
}
if(k==0)
{
cout<<"1"<<"\n";
}
}
}
link to problem the problem-
https://drive.google.com/open?id=1sYEbtdFTT9ZE67y4Wygvv_AKJWGWgXiI
https://www.hackerearth.com/challenges/competitive/april-circuits-20/algorithm/happy-segments-e290faa6/