Strange observation with accumulate() function in STL

Revision en1, by Letscode_sundar, 2021-08-27 13:47:12

I was doing <a href='/contest/1512/problem/D' title='Codeforces Round 713 (Div. 3)'>1512D - Испорченный массив problem and i noticed a strange thing.

In order to calculate sum of the vector elements , I used the accumulate function available in STL

typedef long long ll;
#define int ll
//the sum variable and elements in vector becomes long long type
int sum=0;
sum=accumulate(v.begin(),v.end(),0);

127183042

This basically gives the wrong answer .

But

#define int ll
int sum=0;
sum=accumulate(v.begin(),v.end(),sum);
or
sum=accumulate(v.begin(),v.end(),0LL);

127184393

127184828

gets accepted.

Why is this happening ?

All these days, I thought it is just an initial value that we give to the accumulate function (the last argument), but it is not just an initial value and plays a big role in the outcome of the sum.

I am telling it isn't just a value because

ll sum=10;
sum+=20;

Now it wouldn't matter if 20 is given in LL or not , but here 0 gives WA but 0LL is accepted.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English Letscode_sundar 2021-08-27 13:48:31 45 Tiny change: 'problem/D)and i noti' -> 'problem/D) and i noti'
en1 English Letscode_sundar 2021-08-27 13:47:12 1130 Initial revision (published)