Why is my code showing runtime error when i am submitting it in question QUERIES https://www.codechef.com/problems/ARHN09
#include <bits/stdc++.h>
using namespace std;
int n,q;
int main()
{
ios::sync_with_stdio(false);
cin >> n >> q;
int a[2*n];
memset(a,0,sizeof(a));
for (int i = n; i < 2*n; i++)
{
cin >> a[i];
}
for (int i = n-1; i > 0; i--)
{
a[i] = a[i*2]+a[i*2+1];
}
while (q --)
{
int l,r;
cin >> l >> r;
--l;--r;
r ++;
l += n;
r += n;
int s=0;
while (l < r)
{
if (l%2==1)
{
s+=a[l];
l ++;
}
if (r%2==1)
{
r --;
s+=a[r];
}
l /= 2;
r /= 2;
}
cout << s << endl;
}
}