Could not verify the problem in logic of the present at location https://ide.codingblocks.com/s/157893. Getting wrong answer for both of the test cases.
Buy And Sell BIT code Problem Wrong Answer
Why are you doing so much? Its a simple problem. Hereβs what needed to be done.
- When you have β+β , just update quantitiy in map and update BIT with 1.
2.When you have β-β , just decrease quantitiy and update BIT with -1.
3.When you have β?β , just call your query function. Thats it!
if(c==β+β)
{
string s;
cin>>s;
quant[s]++;
update(price[s],1);
}
else if(c=='-')
{
string s;
cin>>s;
if(quant[s]>0)
{
update(price[s],-1);
quant[s]--;
}
}
else if(c=='?')
{
int i;
cin>>i;
cout<<query(i+1)<<endl;
}
Please have a look here to see sample implementation.