Блог пользователя Letscode_sundar

Автор Letscode_sundar, история, 3 года назад, По-английски

I was doing this 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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • -26
  • Проголосовать: не нравится