This is the link for my code.
Could you help me with this problem cause I am unable to figure what might be wrong with this code
This is the link for my code.
Could you help me with this problem cause I am unable to figure what might be wrong with this code
hey @sankalp.sharma99
u had a lil error in your update and query for +/-
void update(ll n,ll ind,ll val) { while(ind<=n) { BIT[ind]+=val; //ind+=(ind&(-ind)); ind -= (ind & (-ind) ); } } ll query(ll ind) { ll res=0; while(ind>0) { res+=BIT[ind]; //ind-=(ind&(-ind)); ind+=(ind&(-ind)); } return res; }
after this u r getting tle,try to use fast i/o
I will need to change the conditions in the while loop too otherwise it will run in an infinite loop.
Could you explain why you have switched the direction in which update and query propagate in the BIT.
I was recording the prices of the items entered and keeping count of the total number of items in the basket.
And when needing the number of items with pricing greater than a given Y.I would query for the number of items prices Y and below and then subtract it from the total number of items.
Shouldn’t this logically give me the no. of items with price greater than Y.
I even tried the changes you mentioned and mad my I/O faster using ios_base::sync_with_stdio(false);
cin.tie(NULL);
but still I am getting TLE.
@sankalp.sharma99 yeah,u r right your approach works too .refer to this code for modifications to solve tle