We will hold AtCoder Beginner Contest 423.
- Contest URL: https://atcoder.jp/contests/abc423
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20250914T2100&p1=248
- Duration: 100 minutes
- Writer: cn449, sheyasutaka
- Tester: physics0523, Nyaan
- Rated range: ~ 1999
- The point values: 150-200-300-400-475-525-600
We are looking forward to your participation!








Hope to have good grades and quality.(qp)
Notice that the point of problem A is abnormal, so I hope that this contest will not be a bad one. GL & HF!
all the best everyone! excited for this
祝大家取得好成绩
Do not post Chinese in Codeforces.
why?
祝大家取得好成绩
Do not post Chinese in Codeforces. You may post Russian or English
Why Sunday again?
Because AHC was held yesterday.
But I checked, there is only AHC yesterday.
Why sunday again?(qp)
good luck everyone!
これわ食蜂操祈でつの!
RP++
I hope I can solve ABC D.
Good Luck!
Wish the E problem can get accepted.
Good luck and have fun
Hope E is easy for me and for everyone!
gl guys!
E is so easy(Yes.)
Missing one testcase in ABC C
I messed up, could not get one test case in C. could implement E but suprise suprise, no time left as I invested all of it in C
How to solve F?
typical inclusion-exclusion
Could you talk about it more detailed?
consider a subset $$$s$$$ of $$$A$$$, which contains exactly $$$M+k$$$ elements.
let $$$\text{lcm}(s)$$$ means the least common multiple of these elements in $$$s$$$.
if $$$k$$$ is odd, it gives $$$-\binom{M+k}{M}\times \lfloor\frac{Y}{\text{lcm}(s)}\rfloor$$$ contribution to the answer;
otherwise, it gives $$$\binom{M+k}{M}\times \lfloor\frac{Y}{\text{lcm}(s)}\rfloor$$$ contribution to the answer.
Wow! It's so concise! Thanks for your help!
Compute the subset's LCM (prune early if LCM > Y) using bitmask and maintain the sum of multiples <= Y by size of subset.
Then; you can use inclusion-exclusion principle and counting to get the integers <= Y exactly having M elements in the subset (we already have sum of multiples by size).
I hope this helps or you can also refer editorial.
In problem E, there is a solution with asymptotics O(q * max(a)) , where I just count for each segment with what coefficient the number ai will enter
can you explain it properly ?
really annoyed with problem C
11 Wrong attempts for me. Really annoying question.
True. I got 6 WAs on it :(
The way you apply your solution really infect the time you need to solve it.
Some problems are too template based and not flexible enough!
Especially the Problem D and E. I'm angry with them!
exquisite beyond compare
I got 1525 points.
I think E<D
Problem C is too hard!I used about 35 minutes to solve A,B,D,E,F.But more than 40 to solve C...
I made an observation for C:
let's say you start at room 5, and
Urepresents unlocked doors andLrepresents locked doors. In order to ensure that all the doors are locked, an optimal strategy would be toRand lock all doors as you go.Using
Xto denote the current position,we performed the switching operation twice, before locking the last unlocked door,
and locking all doors back to R
If I lock any door before returning to
R, then I will incur an additional cost of returning toR.So if we let
The minimum number of operations for doors $$$[0, R-1]$$$ would be $$$2x + y$$$.
We can obtain the full count if we repeat this algorithm iterating from the right.
AC Link: https://atcoder.jp/contests/abc423/submissions/69316804
I know how to solve it,just complained it,but thank you
What's the expected TC in E? I did a $$$O(Q*100*log(N))$$$ solution but got TLE
The $$$100$$$ thing is only to ensure that the sum won't exceed
long long.There exists a O(100*(n + q))solution using the observation that contribution of an element X would be summation of X*(i-l+1)*(r-i+1), over all index i of X in [l,r]
You can try $$$O(N+Q)$$$.
Problem C
My code is failing only for a single testcase can anyone help me find the error in my code.
why do you use the
? I think you should add 2 to ans regardless of the condition. as long as it is in between f and l and is a locked door, you need to unlock it and lock it again
Actually, the condition is not the cause.
I think the question says the starting room is R, and you can only access the R-1 and Rth door at first. However your for loop is trying to access the R and R+1th door first
it is very subtle to realize this, but the problem statement is intentionally designed to trick you into think you can access the R and R+1 door first, but according to the statement, the distribution of room and door is like this:
R0 D1 R1 D2 R2 D3 R3 D4...
if you start with the 1st room R1, then you can access the 1st and 2nd door, but the index of the door accessing is actually 0 and 1.
Thank You!
Thank You!
[hack input] 6 6 1 0 0 0 0 1 [hack answer] 6 [your output] 4
you should wrote
if(i!=0)instead ofif(i!=0 && i!=n)because there's no door at 0 but there IS a door at n.Yes you are correct, i totally missed that point.
for C, go to either direction from R if there is at least one 0 in that direction, all the obstructing (locked) doors in the way need to be unlocked before you get to the farthest 0. Once you get to that 0, greedily lock all the doors.
Why there is no editorial in English ?
there never is, sometimes you can scroll down in japanese editorial to find english one
My previous contest was ABC258. There was an editorial in English.
https://atcoder.jp/contests/abc358/editorial
I like the quality of the problem, but without editorial in English, i will leave the platform.
The previous contest ABC422, there was an editorial in English
https://atcoder.jp/contests/abc422/editorial
when would result come out
Sadly, I have a E's solution with Mo's in last 20min, but I have no time to finish it :(
Questions E and F remain highly formulaic, with the sole merit being that Question G offers some insight.
a great contest! but maybe the problem F can be a little more difficult. (upd: I apologize for my previous awkward English expression. It was not my intention to offend anyone. In my previous statement, ABC only stands for Atcoder Beginner's Contest and has no other meanings.)
Hey why cant I submit my code?
There is no submit button and if you type the submit link, it will return 404
can anyone share the concept for solving E?
I used mo's algorithm.
Replace array $$$a$$$ with prefix sum array $$$p$$$ of length $$$n + 1$$$, $$$p_i$$$ = sum of $$$i$$$ first elements.
Then we want to calculate the sum $$$p_{r+1} - p_l$$$ for all pairs $$$(l, r)$$$ such that $$$L \le l \le r \e R$$$. Let's replace $$$r$$$ with $$$r+1$$$ and get $$$p_r - p_l$$$ for $$$L \le l \lt r \le R + 1$$$.
Let's look at contribution of the term $$$p_i$$$. There are $$$i - L$$$ elements to the left of $$$i$$$, so that will add $$$p_i (i - L)$$$. Also there are $$$R + 1 - i$$$ elements to the right of $$$i$$$, that will subtract $$$(R - i + 1) p_i$$$. So, we want to find the sum of $$$p_i (i - L - R - 1 + i) = p_i (2i - L - R - 1)$$$ for all $$$L \le i \le R + 1$$$.
By calculating prefix sums of $$$p_i$$$ and $$$p_i \times i$$$ we can find the answer in $$$O(1)$$$.
P. S.: somewhere in the calculations I messed up with +- 1, because on the contest I just tried some variations until it worked out
I got tripped over by not considering the prefix sums of pi and i*pi as N+2 vectors... rather just as N+1 but really nice technique.
Nice solution for E using the contribution technique.
For a fixed value $$$v$$$, suppose an occurrence of $$$v$$$ is at position $$$k$$$ and we consider subarray $$$[L, R]$$$.
The number of subarrays $$$[L', R']$$$ with $$$L \leq L' \leq k \leq R' \leq R$$$ that include this occurrence equals
Expanding and simplifying gives
So for all occurrences $$$k$$$ of value $$$v$$$ inside $$$[L, R]$$$, the total contribution (multiplied by $$$v$$$) is
where
Then each query $$$[L, R]$$$ uses $$$O(100)$$$ work (iterate over values).
beautifull technique ,thanks for sharing
Can someone help me in question E? I know it's purely about mathematical manipulation and simplifying the expression. I did the same and the final expression I got is:
For any query (l, r): sum form l to r of : [ A_i * (i+1-l) * (r+1-i)] = -(S2) + (r+l)*S1 + (r+1)*(1-l)*S0
where S0 = sum form l to r of : A_i S1 = sum form l to r of : i*A_i S2 = sum form l to r of : i^2*A_i
Here's my code:
(r+1)*(1-l)is out of int, but you didn't transform to long long.please give why this solution to question c fails - i have tried my best after 15+ wrong submission please anybody clarify me what is wrong with my solution
ONNLY 2 test cases getting WAYou have made two mistakes.
if (v[i] == 0) cost++;, or you will fail on [hack input][hack output]
doorsandrooms. Yourleftandrightare id of doors whilestartis the id of room. Your for loop in the casestart < leftshould start withi = start + 1, representing the door to the right of room start. Here's the hack for the second mistake[hack input]
[hack output]
Generally, you should reduce classifications. You can view my code. I merged the three classes into one. That makes it less possible to make mistakes.
A solution for Problem E using SegmentTree.
It's easy for me to come up with this method so I use SegmentTree. The only thing you need to do is merging nodes on SegmentTree.Then you will get AC:)
It's not the best way, but an easy way to solve Problem E. Hope this could help you.
AC link
Why problem D needs long long ?