A13039 | Berstagram
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarp recently signed up to a new social network Berstagram. He immediately published $n$ posts there. He assigned numbers from $1$ to $n$ to all posts and published them one by one. So, just after publishing Polycarp's news feed contained posts from $1$ to $n$ — the highest post had number $1$ , the next one had number $2$ , ..., the lowest post had number $n$ .
After that he wrote down all likes from his friends. Likes were coming consecutively from the $1$ -st one till the $m$ -th one. You are given a sequence $a_1, a_2, \dots, a_m$ ( $1 \le a_j \le n$ ), where $a_j$ is the post that received the $j$ -th like.
News feed in Berstagram works in the following manner. Let's assume the $j$ -th like was given to post $a_j$ . If this post is not the highest (first) one then it changes its position with the one above. If $a_j$ is the highest post nothing changes.
For example, if $n=3$ , $m=5$ and $a=[3,2,1,3,3]$ , then Polycarp's news feed had the following states:
- before the first like: $[1, 2, 3]$ ;
- after the first like: $[1, 3, 2]$ ;
- after the second like: $[1, 2, 3]$ ;
- after the third like: $[1, 2, 3]$ ;
- after the fourth like: $[1, 3, 2]$ ;
- after the fifth like: $[3, 1, 2]$ .
Polycarp wants to know the highest (minimum) and the lowest (maximum) positions for each post. Polycarp considers all moments of time, including the moment "before all likes".
After that he wrote down all likes from his friends. Likes were coming consecutively from the $1$ -st one till the $m$ -th one. You are given a sequence $a_1, a_2, \dots, a_m$ ( $1 \le a_j \le n$ ), where $a_j$ is the post that received the $j$ -th like.
News feed in Berstagram works in the following manner. Let's assume the $j$ -th like was given to post $a_j$ . If this post is not the highest (first) one then it changes its position with the one above. If $a_j$ is the highest post nothing changes.
For example, if $n=3$ , $m=5$ and $a=[3,2,1,3,3]$ , then Polycarp's news feed had the following states:
- before the first like: $[1, 2, 3]$ ;
- after the first like: $[1, 3, 2]$ ;
- after the second like: $[1, 2, 3]$ ;
- after the third like: $[1, 2, 3]$ ;
- after the fourth like: $[1, 3, 2]$ ;
- after the fifth like: $[3, 1, 2]$ .
Polycarp wants to know the highest (minimum) and the lowest (maximum) positions for each post. Polycarp considers all moments of time, including the moment "before all likes".
输入格式
The first line contains two integer numbers $n$ and $m$ ( $1 \le n \le 10^5$ , $1 \le m \le 4 \cdot10^5$ ) — number of posts and number of likes.
The second line contains integers $a_1, a_2, \dots, a_m$ ( $1 \le a_j \le n$ ), where $a_j$ is the post that received the $j$ -th like.
The second line contains integers $a_1, a_2, \dots, a_m$ ( $1 \le a_j \le n$ ), where $a_j$ is the post that received the $j$ -th like.
输出格式
Print $n$ pairs of integer numbers. The $i$ -th line should contain the highest (minimum) and the lowest (maximum) positions of the $i$ -th post. You should take into account positions at all moments of time: before all likes, after each like and after all likes. Positions are numbered from $1$ (highest) to $n$ (lowest).
输入输出样例
输入 #1
3 5 3 2 1 3 3
输出 #1
1 2 2 3 1 3
输入 #2
10 6 7 3 5 7 3 6
输出 #2
1 2 2 3 1 3 4 7 4 5 6 7 5 7 8 8 9 9 10 10
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted