A12860 | Culture Code
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
There are famous Russian nesting dolls named matryoshkas sold in one of the souvenir stores nearby, and you'd like to buy several of them. The store has $n$ different matryoshkas. Any matryoshka is a figure of volume $out_i$ with an empty space inside of volume $in_i$ (of course, $out_i > in_i$ ).
You don't have much free space inside your bag, but, fortunately, you know that matryoshkas can be nested one inside another. Formally, let's call a set of matryoshkas nested if we can rearrange dolls in such a way, that the first doll can be nested inside the second one, the second doll — inside the third one and so on. Matryoshka $i$ can be nested inside matryoshka $j$ if $out_i \le in_j$ . So only the last doll will take space inside your bag.
Let's call extra space of a nested set of dolls as a total volume of empty space inside this structure. Obviously, it's equal to $in_{i_1} + (in_{i_2} - out_{i_1}) + (in_{i_3} - out_{i_2}) + \dots + (in_{i_k} - out_{i_{k-1}})$ , where $i_1$ , $i_2$ , ..., $i_k$ are the indices of the chosen dolls in the order they are nested in each other.
Finally, let's call a nested subset of the given sequence as big enough if there isn't any doll from the sequence that can be added to the nested subset without breaking its nested property.
You want to buy many matryoshkas, so you should choose a big enough nested subset to buy it. But you will be disappointed if too much space in your bag will be wasted, so you want to choose a big enough subset so that its extra space is minimum possible among all big enough subsets. Now you wonder, how many different nested subsets meet these conditions (they are big enough, and there is no big enough subset such that its extra space is less than the extra space of the chosen subset). Two subsets are considered different if there exists at least one index $i$ such that one of the subsets contains the $i$ -th doll, and another subset doesn't.
Since the answer can be large, print it modulo $10^9 + 7$ .
You don't have much free space inside your bag, but, fortunately, you know that matryoshkas can be nested one inside another. Formally, let's call a set of matryoshkas nested if we can rearrange dolls in such a way, that the first doll can be nested inside the second one, the second doll — inside the third one and so on. Matryoshka $i$ can be nested inside matryoshka $j$ if $out_i \le in_j$ . So only the last doll will take space inside your bag.
Let's call extra space of a nested set of dolls as a total volume of empty space inside this structure. Obviously, it's equal to $in_{i_1} + (in_{i_2} - out_{i_1}) + (in_{i_3} - out_{i_2}) + \dots + (in_{i_k} - out_{i_{k-1}})$ , where $i_1$ , $i_2$ , ..., $i_k$ are the indices of the chosen dolls in the order they are nested in each other.
Finally, let's call a nested subset of the given sequence as big enough if there isn't any doll from the sequence that can be added to the nested subset without breaking its nested property.
You want to buy many matryoshkas, so you should choose a big enough nested subset to buy it. But you will be disappointed if too much space in your bag will be wasted, so you want to choose a big enough subset so that its extra space is minimum possible among all big enough subsets. Now you wonder, how many different nested subsets meet these conditions (they are big enough, and there is no big enough subset such that its extra space is less than the extra space of the chosen subset). Two subsets are considered different if there exists at least one index $i$ such that one of the subsets contains the $i$ -th doll, and another subset doesn't.
Since the answer can be large, print it modulo $10^9 + 7$ .
输入格式
The first line contains a single integer $n$ ( $1 \le n \le 2 \cdot 10^5$ ) — the number of matryoshkas.
The next $n$ lines contain a description of each doll: two integers $out_i$ and $in_i$ ( $1 \le in_i < out_i \le 10^9$ ) — the outer and inners volumes of the $i$ -th matryoshka.
The next $n$ lines contain a description of each doll: two integers $out_i$ and $in_i$ ( $1 \le in_i < out_i \le 10^9$ ) — the outer and inners volumes of the $i$ -th matryoshka.
输出格式
Print one integer — the number of big enough nested subsets such that extra space of each of these subsets is minimum possible. Since the answer can be large, print it modulo $10^9 + 7$ .
输入输出样例
输入 #1
7 4 1 4 2 4 2 2 1 5 4 6 4 3 2
输出 #1
6
There are $6$ big enough nested subsets with minimum possible extra space in the example:
- $\{1, 5\}$ : we can't add any other matryoshka and keep it nested; it's extra space is $1$ ;
- $\{1, 6\}$ ;
- $\{2, 4, 5\}$ ;
- $\{2, 4, 6\}$ ;
- $\{3, 4, 5\}$ ;
- $\{3, 4, 6\}$ .
There are no more "good" subsets because, for example, subset $\{6, 7\}$ is not big enough (we can add the $4$ -th matryoshka to it) or subset $\{4, 6, 7\}$ has extra space equal to $2$ .
- $\{1, 5\}$ : we can't add any other matryoshka and keep it nested; it's extra space is $1$ ;
- $\{1, 6\}$ ;
- $\{2, 4, 5\}$ ;
- $\{2, 4, 6\}$ ;
- $\{3, 4, 5\}$ ;
- $\{3, 4, 6\}$ .
There are no more "good" subsets because, for example, subset $\{6, 7\}$ is not big enough (we can add the $4$ -th matryoshka to it) or subset $\{4, 6, 7\}$ has extra space equal to $2$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted