9719: Interval LRU

内存限制:512 MB 时间限制:2 S
题面:传统 评测方式:文本比较 上传者:
提交:1 通过:1

题目描述

Little Q is learning about a page replacement algorithm in operating systems memory management~-- the LRU (Least Recently Used) algorithm.

To help Little Q understand this algorithm, you need to answer some questions regarding LRU in this problem. First, we briefly introduce the principle of this algorithm:
  • Set up a cache container of capacity kkk to store loaded pages and related information. Initially, no pages are in the container.
  • The system will sequentially process requests to access pages, handling one request at a time.
  • For accessing a page that is already in the cache (i.e., a cache hit), use the cache directly as the data source and update the page's most recent access time.
  • For accessing a page that is not in the cache (i.e., a cache miss), if the number of pages in the cache has reached kkk, first evict a page from the cache to ensure the number of pages in the cache is less than kkk, and then load the accessed page from its real address into the cache, using the cache as the data source and updating the page's most recent access time.
  • Whenever a page needs to be evicted, choose the one with the earliest most recent access time to release from the cache.

Next, we use pages numbered from 111 to nnn and provide an array of length nnn, [a1,a2,…,an][a_1, a_2, \ldots, a_n][a1,a2,,an], along with qqq queries, and you are asked to answer these queries. Each query is one of the following two types:
  • 1 l r k1\ l\ r\ k1 l r k: Access the pages numbered al,al+1,…,ara_l, a_{l + 1}, \ldots, a_ral,al+1,,ar in order, using an LRU cache with a maximum capacity of kkk, and report the number of cache hits.
  • 2 l r k2\ l\ r\ k2 l r k: Access the pages numbered al,al+1,…,ara_l, a_{l + 1}, \ldots, a_ral,al+1,,ar in order, using an LRU cache, requiring that the number of cache hits is at least kkk, and report the minimum required LRU capacity. If the goal of cache hits cannot be achieved, regard the capacity as −1-11.

输入格式

The first line contains an integer TTT (1<=T<=105), indicating the number of test cases.
Then follow TTT test cases. For each test case:
The first line contains two integers nnn and qqq (1<=n,q<=105).
The second line contains nnn integers a1,a2,…,ana_1, a_2, \ldots, a_na1,a2,,an (1≤ai≤n1 \leq a_i \leq n1ain).
The next qqq lines describe the queries, each line of which contains four integers t,l,r,kt, l, r, kt,l,r,k (t∈{1,2},1≤l≤r≤n,1≤k≤r−l+1t \in \{1, 2\}, 1 \leq l \leq r \leq n, 1 \leq k \leq r - l + 1t{1,2},1lrn,1krl+1), representing a query of the ttt-th type (parameters' meaning are described above).
It is guaranteed that the sum of nnn and the sum of qqq over TTT test cases do not exceed 2*105 and 2*105 respectively.

输出格式

For each test case, output qqq lines, the iii-th line of which contains an integer, representing the answer to the iii-th query.

输入样例 复制

1
8 8
1 2 1 3 2 4 2 1
1 1 8 1
1 1 8 2
1 1 8 3
1 1 8 4
2 2 7 1
2 2 7 2
2 3 8 2
2 1 8 3

输出样例 复制

0
2
3
4
2
3
4
3

数据范围与提示