Https://hack.codingblocks.com/app/dcb/725

#include
#include
using namespace std;
int query1(int no,int i,int n)
{
int mask=1<<(n-i-1);
no=(no||mask);
return no;

}
int query0(int no,int i,int n)
{
int mask=(~1<<(n-i-1));
no=no&(mask);
return no;
}
int query2(int no,int l,int r,int n)
{
int arr[n];
int digit;
for(int i=0;i<n;i++)
{
digit=no&1;
arr[i]=digit;
no=no>>1;

}
int temp;
for(int i=0;i<n/2;i++)
{
	temp=arr[i];
	arr[i]=arr[n-i-1];
	arr[n-i-1]=temp;


}
int answer;
for(int i=l;i<=r;i++)
{
   answer+=(arr[i]*(pow(2,n-i-1)));
}
return answer;

}

int main()
{
int n;
cin>>n;
int k;
cin>>k;
int answer=0;

for(int i=0;i<k;i++)
{
	int q;
	cin>>q;
	int l;
	cin>>l;
	int r;
	cin>>r;
	if(q==0)
	{
		for(int l=l;l<=r;l++)
		{
		answer=query0(answer,l,n);
		}
	}
	else if(q==1)
	{
		for(int l=l;l<=r;l++)
		{
			answer=query1(answer,l,n);
		}

	}
	else
	{
		cout<<query2(answer,l,r,n)<<endl;
	}
}

}

@Bhavit_Singla the question you have asked has simple brute force approach. As the problem says stop processing input after cumulative sum of all the input becomes negative, So there is no need to store the input in an array. Take a variable sum and write a while loop with condition while(sum>=0) take the input number and add it to the variable sum… by this whenever your cumulative sum will become smaller than 0 or negative loop will automatically break.
I am not getting what code you have write ,try above approach it will be submitted.
Happy coding :slight_smile:

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.