A16354 | Doremy's Drying Plan (Hard Version)
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The only differences between the two versions of this problem are the constraint on $k$ , the time limit and the memory limit. You can make hacks only if all versions of the problem are solved.
Doremy lives in a rainy country consisting of $n$ cities numbered from $1$ to $n$ .
The weather broadcast predicted the distribution of rain in the next $m$ days. In the $i$ -th day, it will rain in the cities in the interval $[l_i, r_i]$ . A city is called dry if it will never rain in that city in the next $m$ days.
It turns out that Doremy has a special power. She can choose $k$ days, and during these days it will not rain. Doremy wants to calculate the maximum number of dry cities after using the special power.
Doremy lives in a rainy country consisting of $n$ cities numbered from $1$ to $n$ .
The weather broadcast predicted the distribution of rain in the next $m$ days. In the $i$ -th day, it will rain in the cities in the interval $[l_i, r_i]$ . A city is called dry if it will never rain in that city in the next $m$ days.
It turns out that Doremy has a special power. She can choose $k$ days, and during these days it will not rain. Doremy wants to calculate the maximum number of dry cities after using the special power.
输入格式
The input consists of multiple test cases. The first line contains a single integer $t$ ( $1\le t\le 10^4$ ) — the number of test cases. The description of the test cases follows.
The first line contains three integers $n$ , $m$ and $k$ ( $1\le n\le 2\cdot 10^5$ , $2 \le m \le 2\cdot 10^5$ , $2 \le k \le \min(10, m)$ ) — the number of cities, the number of days, and the number of days of rain that Doremy can prevent.
Then, $m$ lines follow. The $i$ -th line contains two integers $l_i$ , $r_i$ ( $1\le l_i\le r_i\le n$ ) — the rain coverage on day $i$ .
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2\cdot 10^5$ .
The first line contains three integers $n$ , $m$ and $k$ ( $1\le n\le 2\cdot 10^5$ , $2 \le m \le 2\cdot 10^5$ , $2 \le k \le \min(10, m)$ ) — the number of cities, the number of days, and the number of days of rain that Doremy can prevent.
Then, $m$ lines follow. The $i$ -th line contains two integers $l_i$ , $r_i$ ( $1\le l_i\le r_i\le n$ ) — the rain coverage on day $i$ .
It is guaranteed that the sum of $n$ and the sum of $m$ over all test cases do not exceed $2\cdot 10^5$ .
输出格式
For each test case, output one integer — the maximum number of dry cities.
输入输出样例
输入 #1
6 2 3 2 1 2 1 2 1 1 5 3 2 1 3 2 4 3 5 10 6 4 1 5 6 10 2 2 3 7 5 8 1 4 100 6 5 1 100 1 100 1 100 1 100 1 100 1 100 1000 2 2 1 1 1 1 20 5 3 9 20 3 3 10 11 11 13 6 18
输出 #1
1 2 6 0 1000 17
In the first test case, if Doremy prevents
- rain $1,2$ , then city $2$ will be dry;
- rain $2,3$ , then no city will be dry;
- rain $1,3$ , then no city will be dry;
So there is at most $1$ dry city.
In the second test case, if Doremy prevents
- rain $1,2$ , then city $1,2$ will be dry;
- rain $2,3$ , then city $4,5$ will be dry;
- rain $1,3$ , then city $1,5$ will be dry.
So there are at most $2$ dry cities.
In the third test case, it is optimal to prevent rain $1,2,4,5$ .
In the forth test case, there is always a day of rain that wets all the cities and cannot be prevented.
- rain $1,2$ , then city $2$ will be dry;
- rain $2,3$ , then no city will be dry;
- rain $1,3$ , then no city will be dry;
So there is at most $1$ dry city.
In the second test case, if Doremy prevents
- rain $1,2$ , then city $1,2$ will be dry;
- rain $2,3$ , then city $4,5$ will be dry;
- rain $1,3$ , then city $1,5$ will be dry.
So there are at most $2$ dry cities.
In the third test case, it is optimal to prevent rain $1,2,4,5$ .
In the forth test case, there is always a day of rain that wets all the cities and cannot be prevented.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted