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

Автор icode_247, история, 6 лет назад, По-английски

Hi, So i tried to solve this problem . And i did understand the first part of the tutorialbut got a little confused at the end. It says that I have to add everything from cnt[0] to cnt[n-1] to get my answer. But to get a faster result they did a different workaround. They created sums[] and worked on it. This is the c++ solution. Now, why would they do this?:

 for(int i = n-2 ; i >= 0 ; --i)
            cnt[i] += cnt[i+1];

and in this :

        for(int i = 0 ; i+2 < n ; ++i) {
            ss += a[i];
            if (ss == s)
                ans += cnt[i+2];
        }

Why i+2?.

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