【USACO2021 Convoluted Intervals 】题解
本文搬运自本人初中博客园博客,若图片加载不出来,可到原文查看:https://www.cnblogs.com/zhangtingxi/p/15716558.html
题目
The cows are hard at work trying to invent interesting new games to play. One of
their current endeavors involves a set of intervals
(), where the th interval starts at position on
the number line and ends at position . Both and are
integers in the range , where .
To play the game, Bessie chooses some interval (say, the th interval) and her
cousin Elsie chooses some interval (say, the th interval, possibly the same
as Bessie’s interval). Given some value , they win if
.
For every value of in the range , please count the number of
ordered pairs for which Bessie and Elsie can win the game.
奶牛们正在努力尝试发明有趣的新游戏来玩。他们目前的工作之一与一组 个区间()有关,其中第 个区间从数轴上的 位置开始,并在位置 结束。 和 均为 范围内的整数,其中 。
这个游戏的玩法是,Bessie 选择某个区间(假设是第 个区间),而她的表妹 Elsie 选择某个区间(假设是第 个区间,可能与 Bessie 所选的的区间相同)。给定某个值 ,如果 ,则她们获胜。
对范围 内的每个值 ,请计算使得 Bessie 和 Elsie 可以赢得游戏的有序对 的数量。
思路
用差分思想考虑,所有 的地方+1,所以 的地方减1。
然而这是 ,但我们发现 的值域很小,所以我们可以用桶存起来,然后按值域遍历即可,就变成 。
总结
对于一些过于重复的计算,如果值域很小,我们可以尝试用桶存起来,减去很多过于重复的计算。
Code
1 |
|



