PUSSY_LICKING_LOLI_69's blog

By PUSSY_LICKING_LOLI_69, history, 4 hours ago, In English

I recently came across this problem while solving E1 of Codeforces Round 967 (Div. 2)

My original code used (a+=b)%p; and it worked perfectly with small test cases, but it gave WA when the test cases get larger. After i changed it to a =(a+b)%p; the code got accepted.

I'm a bit frustrated because it took me until after the contest was finished that i found the dumb mistake that probably stopped me from getting the Candidate Master title, so I made this post to discuss the differences between those 2 syntax to help people avoid the same mistake as me (and mostly just for me to vent T^T )

Here's my original code (Please don't pay attention to the dumb variable names hehe)

My Code

It only worked on test 1, and failed test 2. However, when i changed this line, it worked perfectly

//for(int j = 2;j<=k;j++) (dp2[i][j]+=dp2[i][j-1])%p;
for(int j = 2;j<=k;j++) dp2[i][j]=(dp2[i][j]+dp2[i][j-1])%p;

Can anyone explain why this single line broke my code? :(

Full text and comments »

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

By PUSSY_LICKING_LOLI_69, history, 8 months ago, In English

Given an array A of size n (n<=150000) and a permutation P. You must do q queries(q<=150000) of 4 types:

1 l r v: A[p[i]]+=v with all l<=i<=r

2 l r: calculate sum of all A[i] with all l<=i<=r

3 x y: swap P[x] and P[y]

4 k: roll back A and P to right before the kth query

Here's the link the the original problem(Vietnamese) if you're interested: https://oj.vnoi.info/problem/olp_sc23_pquery

I'll be looking forward to your answers. Thank you :D

Edit: Apparently someone's accepted solution has square root decomposion as a part of it but I don't have access to their code and any detail on how it works. Can someone expand on this approach?

Full text and comments »