What happens to this overflow?

Revision en2, by Night_L, 2021-03-04 23:13:39

In this 109101215, I got WrongAnswer because of an overflow. The overflow comes from

long long a[N], x[N], ans, spin;
int n;
vector<long long> sum;
...
ans = spin*n + lower_bound(sum.begin(),sum.end(),x[i] - spin*a[n-1]) - sum.begin();

I manage to fix it by adding parenthesis to lower_bound(..)-sum.begin().

This is learned from other guys' code. But I have no idea what I am doing and what has been corrected. Can someone explain what happens?

Tags overflow, bug

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Night_L 2021-03-04 23:13:39 12 Tiny change: 'ong a[N], ans;\nint n;\' -> 'ong a[N], x[N], ans, spin;\nint n;\'
en1 English Night_L 2021-03-04 23:11:44 515 Initial revision (published)