Omega1's blog

By Omega1, history, 9 years ago, In English

Hello to all,today I solve problem A. Greg and Array and I have and misunderstanding: I have two submission,one get accepted and another get wrong answer on test 11.

Accepted

Wrong answer

the difference between this both submission is the line below:

for (i=1;i<=n;i++) dp[i]=dp[i]+dp[i-1];

if I change n with m I get Accepted,Can someone explain me why,I didn't use element on position bigger than m and I didn't exceed the limits of the array dp???

I'm very interesting why this happens,because during the contest this mistake can cost me one problem.

  • Vote: I like it
  • +5
  • Vote: I do not like it

| Write comment?
»
9 years ago, # |
  Vote: I like it +13 Vote: I do not like it

You use dp for values up to m right in the next loop:

for (i=1;i<=n;i++) dp[i]=dp[i]+dp[i-1];
for (i=1;i<=m;i++)
    b[t[i].x]=b[t[i].x]+1LL*t[i].val*dp[i],
    b[t[i].y+1]=b[t[i].y+1]-1LL*t[i].val*dp[i];