I cant find the error here... its giving 0 0 as output for all input cases. plz help.

#include<stdio.h>
#define max(a,b) a>b?a:b
void build(int ai,int l,int r);
int query(int ai,int l,int r,int i,int j,int count);
void update(int ai,int l,int r,int i,int j);
int aa,b,m;
int inp[6];

struct arr
{
int val;
int ct;
}a[15];
int main()
{
int i,nn;
int ai;
inp[0]=-1;
for(i=1;i<6;i++)
scanf("%d",&inp[i]);

for(ai=0;ai<15;ai++)
{

a[ai].val=0;
a[ai].ct=0;
}
build(1,1,5);
printf("biuld done   ");
nn=query(1,1,5,1,2,0);
printf("query done");
printf("%d   ",nn);
update(1,1,5,1,3);
printf("%d",nn);
return 0;
}
void build(int ai,int l,int r){
if(l==r){
a[ai].val=inp[l];
return;
}printf("in b  ");
build(2*ai,l,(l+r)/2);
build(2*ai+1,(l+r)/2+1,r);
a[ai].val=max(a[2*ai].val,a[2*ai+1].val);
}
int query(int ai,int l,int r,int i,int j,int count){
if(i<=l&&r<=j){
if(l==r){
return a[ai].val+count;
}
else
return m+count;
}
if(r<i||j<l)
return -1;
aa=query(2*ai,l,(l+r)/2,i,j,count+a[ai].ct);
b=query(2*ai+1,(l+r)/2+1,r,i,j,count+a[ai].ct);
m=max(aa,b);
}
void update(int ai,int l,int r,int i,int j){
if(i<=l&&r<=j){
a[ai].ct++;
a[ai].val++;
return;
}
if(r<i||j<l)
return;
update(2*ai,l,(l+r)/2,i,j);
update(2*ai+1,(l+r)/2+1,r,i,j);
a[ai].val=max(a[2*ai].val,a[2*ai+1].val)+a[ai].ct;
}

What compiler and operating system are you using? The code's formatting is the most horrible that I've seen posted here in the past 10 years! Format it properly and someone might actually try to help you.

This article has been dead for over six months. Start a new discussion instead.