第十八篇英语翻译
出处:https://acs.jxnu.edu.cn/problem/ICPCJX2021J
重点单词:
index n.指数,幂,指针,索引 v.编入索引;
storage n.存储,存放,保存;
cache n.储存器,秘密处v.隐藏
LRU
3000ms 262144K
描述:
It costs a long time for CPUs to access data from memory, so most of CPUs have caches where requests for data can be served faster. To be cost-effective and to enable efficient use of data, caches must be relatively small. Therefore, we must use some policies to choose some data wisely and storage them in the cache. We divide the memory into many blocks which have the same size and index them from 11 to 109109, and every block has an unique index. A cache will have a capacity for KK blocks, which means it can storage at most KK blocks simultaneously. A cache hit occurs when the requested block is available in the cache, or we say a cache miss occurs. Now we introduce a LRU (Least Recently Used) placement policy on a fully associative cache.
CPU从内存访问数据需要很长时间,因此大多数CPU都有缓存,可以更快地处理数据请求。为了经济高效并实现数据的高效使用,缓存必须相对较小。因此,我们必须使用一些策略来明智地选择一些数据并将其存储在缓存中。我们将内存分成许多大小相同的块,并将它们从1索引到109,每个块都有一个唯一的索引。一个缓存将有K个块的容量,这意味着它最多可以同时存储K个块。当请求的块在缓存中可用时,即发生缓存命中,或者我们说发生缓存未命中。现在我们在全关联缓存上引入一个LRU(最近使用最少的)放置策略。
- If the requested block is available in the cache, a cache hit occurs.
- If not, CPU can only access the block from the memory and write the block into the cache. If cache is not full, append the block into the cache.
- If the cache is full, cache is full, the block which haven't been visited for the longest time in the cache will be replaced by the new block.
An example for cache with capacity of 333 blocks is shown below.
如果请求的块在缓存中可用,则会发生缓存命中。
否则,CPU只能从内存中访问该块并将其写入缓存。如果缓存未满,请将块附加到缓存中。
如果缓存已满,则缓存已满,缓存中最长时间未访问的块将被新块替换。
下面显示了容量为333个块的缓存示例。
The 8th8th, 4th4th and 3rd3rd are in the cache when the 6th6th block is requested, so a cache miss occurs. At that time, the cache is full, and we must decide the block to be replaced. The most recent request of 8th8th block is the 13th13threquest, the most recent request of 4th4th block is the 14th14th request and the most recent request of 3rd3rdblock is the 11th11th request. The 3rd3rd block will be replaced by the 6th6th block because the 3rd3rd block hasn't been visited for longest time.
当请求第6个块时,第8、第4和第3个块在缓存中,因此缓存未命中。此时,缓存已满,我们必须决定要替换的块。第8块最近的请求是第13个请求,第4块最近的请求是第14个请求,第3块最近的请求是第11个请求。第三个街区将被第六个街区取代,因为第三个街区已经有很长时间没有人参观了。
Now the sequence of requested blocks and the capacity of the cache are given, please determine the minimum capacity for the cache in order to ensure at least KK requests to hit the cache.
现在给出了请求块的顺序和缓存的容量,请确定缓存的最小容量,以确保至少有K个请求命中缓存。
输入:
The first line contains two numbers NN and K(1≤K≤N≤105)K(1≤K≤N≤105), denoting the length of sequence and the number of requests required to be hit.
The second line contains NN integers and the ithith number ai(1≤ai≤109)ai(1≤ai≤109) denoting the index of block requested by the ithith request.
输出:
The output contains only one line.
If it is possible to enable at least KK requests to be hit by the cache, then output a single integer denoting the smallest capacity in blocks, or output "cbddl" (without quotes).
样例输入:
15 6 3 4 2 6 4 3 7 4 3 6 3 4 8 4 6
样例输出:
3
样例输入:
15 5 3 4 2 6 4 3 7 4 3 6 3 4 8 4 6
样例输出:
3
样例输入:
15 10 3 4 2 6 4 3 7 4 3 6 3 4 8 4 6
样例输出:
cbddl