IN ARRAY INITIALIZATION, IF WE USE int arr[10]={};
THEN ALL THE MEMBERS OF ARRAY ARE ASSIGNED TO VALUE ‘0’.
In this code
If I use ll b[100001]={}, then this code is not working.
When I’m using memset (b,0,sizeof(b)), this code is working.
My Working Code
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define f(i,n) for(int i=0;i<n;i++)
using namespace std;
ll b[100001];
ll find(ll a[],ll i,ll n)
{
if(i==n-1)
return b[i]=1;
if(b[i]!=0)
return b[i];
if(a[i]*a[i+1]<=0)
return b[i]=1+find(a,i+1,n);
else
return b[i]=1+(find(a,i+1,n))*0;
}
void solve()
{
ll n;
memset(b,0,sizeof(b));
cin>>n;
ll a[n];
f(i,n)
{
cin>>a[i];
}
find(a,0,n);
f(i,n)
cout<<b[i]<<’ ‘;
cout<<’\n’;
}
int main() {
speed
int test;
cin>>test;
while(test--)
{
solve();
}
return 0;
}