Today in topcoder single round match 649, I did a small mistake on 550.
One of my test was failing for this mistake and couldn't figure out what was wrong during the contest.
long res = 0;
FenwickTree tree = new FenwickTree(sz);
for (int i = 0; i < sz; ++i) {
res += tree.read((int)a[i] - 1);
tree.update((int)a[i], 1);
}
return res;
Here I used a instead of b. I normalized int[] a into int[] b to use that with FenwickTree but at the end I ended up using the original array a. Replacing a with b makes the code pass all test.
If anyone has suggestion about how to overcome this kind of mistake and how to concentrate more, please let me know.