Question : “https://www.spoj.com/problems/RACETIME/”

My solution 1 : “https://ideone.com/eFcDMq” (Accepted 2.22 sec)

My solution2 : “https://ideone.com/Vor1sH” (WA)

My solution3 : “https://ideone.com/O9qkXU” [1.49 sec , just edit solution 2 with <= condition in BS , AC]

My solution 4 : “https://ideone.com/GoBA9s” [1.45 sec , using lower_bound ±3 , AC]

```
// Update function in solution 1
// just clear block and fill again whole gives me AC
void update(lli ind , lli val)
{
lli block_number = ind / blk_sz;
lli start = block_number*blk_sz;
lli endi = (block_number+1)*blk_sz;
a[ind] = val;
block[block_number].clear();
for(lli i=start;i<endi;i++)
block[block_number].pb(a[i]);
sort(all(block[block_number]));
}
```

```
// Update function in solution 2
// just find block number and for that block number find index too using binary search after that
// change it and sort again gives me WA why ?
void change_val_binary_search(vi &vc, lli crval , lli val)
{
lli l=0;
lli r = sz(vc)-1;
while(l<r)
{
lli mid = (l+r)/2;
if(vc[mid] == crval)
{
vc[mid] = val;
return ;
}
else if(vc[mid]>crval)
{
r = mid-1;
}
else
l = mid+1;
}
}
void update(lli ind , lli val)
{
lli block_number = ind / blk_sz;
lli start = block_number*blk_sz;
lli endi = (block_number+1)*blk_sz;
change_val_binary_search(block[block_number] , a[ind] , val);
a[ind] = val;
sort(all(block[block_number]));
}
```