Problem-Setting Report for “Magical Girl Lya”
Originally, I wanted to imitate the format of the “Problem-Setting Report for <World’s Sleeping Fairytale>” from the ioi2024 National Training Team papers, but I realized this crappy problem has no depth at all and can’t imitate it in the slightest, so I’ll just write it like this.
This problem was partly inspired by , and by the way, I temporarily made it harder on the afternoon before the contest.
Problem
Given a 01 sequence, with range flip and range assignment operations, query the longest 01 alternating substring within a given range. .
O(mlogn) Approach
Obviously, range flip and range assignment are standard segment tree template operations. The key to this problem lies in merging the nodes in the segment tree.
My way of writing it is to maintain, for the interval represented by a node, the lengths of the longest intervals starting from the left/right that begin with 0/1, and the lengths of the longest intervals overall that begin with 0/1. During pull (or pushup), taking the length of the interval starting from the far left that begins with 0 as an example: if its length equals the total length of the left child, we directly append the corresponding length of the interval starting from the far left of the right child that begins with 0/1 based on the parity of the left child’s length—whether it’s 0 or 1 follows the “odd changes, even stays the same” rule; otherwise, we just inherit it directly. The other three are the same. As for the length of the longest interval beginning with 0/1, we just need to take a max of the left and right children, and then take a max with the middle part. The middle part is formed by choosing the corresponding left value of the right child based on the right value of the left child so that they can be connected, and then we’re done.
It is indeed a bit of a heavy implementation, and I spent quite a long time writing and debugging it too.
Code
|
Old Version Problem
Given a 01 sequence, with range flip and range assignment operations, query whether the numbers within a given range are all 01 alternating. .
Old Version Problem O(mlogn) Approach
The range operations remain unchanged, but what we maintain only needs to be the node’s interval length and the lengths of the 0/1 strings starting from the left. Finally, we just need to check whether the string length equals the interval length.
Old Version Problem Code
|
Postscript
Originally, I was also thinking maybe there are some cheese approaches? For example, using bitset, which might achieve O(mn/w), so I specifically uploaded the first three new test cases with nm maxed out, and even raised the limit to 5e5, but up until now I haven’t implemented it, and no one else wrote it like that either. Though nine times out of ten it probably wouldn’t pass anyway, right? Even at the 2e5 level?
Honestly, I was super happy when zhw got AC during the contest. At least it proved that the very first problem I set myself for the very first contest I organized didn’t have any flaws. When he first got wa, I couldn’t help but start checking his code and my brute-force code during class, but thankfully he got AC in the end. By the way, the code he wrote was twice as fast as mine; I don’t know if it was because of fast I/O or something else, didn’t look closely.
Having said that, maybe it would be better to write the problem into the problem description?
And maybe adding a prefix to the test data points so they are tested in order would be good too?
As for this contest, I don’t know if it was because the problems were in random order, but the number of solves and the objective problem difficulty actually ended up being completely inverted.
Moreover, it was truly a pity that tiome and rainydyas passed the problem right at 22 seconds and 1 minute 35 seconds after the contest ended, respectively.
As for changing the problem title to “Bright Moon Shines O’er the Drifted Snow”, that was even a last-minute whim on the day of the contest (x. That works out nicely though, next time it will be “Fierce and Mournful Blows the Boreal Wind”, maybe next time I’ll have to write an announcement to remind everyone that the difficulties are in random order…
2024/9/29 23:25
