A9251 | Jeff and Removing Periods
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Cosider a sequence, consisting of $n$ integers: $a_{1}$ , $a_{2}$ , $...$ , $a_{n}$ . Jeff can perform the following operation on sequence $a$ :
- take three integers $v$ , $t$ , $k$ $(1<=v,t<=n; 0<=k; v+tk<=n)$ , such that $a_{v}$ = $a_{v+t}$ , $a_{v+t}$ = $a_{v+2t}$ , $...$ , $a_{v+t(k-1)}$ = $a_{v+tk}$ ;
- remove elements $a_{v}$ , $a_{v+t}$ , $...$ , $a_{v+t·k}$ from the sequence $a$ , the remaining elements should be reindexed $a_{1},a_{2},...,a_{n-k-1}$ .
- permute in some order the remaining elements of sequence $a$ .
A beauty of a sequence $a$ is the minimum number of operations that is needed to delete all elements from sequence $a$ .
Jeff's written down a sequence of $m$ integers $b_{1}$ , $b_{2}$ , $...$ , $b_{m}$ . Now he wants to ask $q$ questions. Each question can be described with two integers $l_{i},r_{i}$ . The answer to the question is the beauty of sequence $b_{li}$ , $b_{li}+1$ , $...$ , $b_{ri}$ . You are given the sequence $b$ and all questions. Help Jeff, answer all his questions.
- take three integers $v$ , $t$ , $k$ $(1<=v,t<=n; 0<=k; v+tk<=n)$ , such that $a_{v}$ = $a_{v+t}$ , $a_{v+t}$ = $a_{v+2t}$ , $...$ , $a_{v+t(k-1)}$ = $a_{v+tk}$ ;
- remove elements $a_{v}$ , $a_{v+t}$ , $...$ , $a_{v+t·k}$ from the sequence $a$ , the remaining elements should be reindexed $a_{1},a_{2},...,a_{n-k-1}$ .
- permute in some order the remaining elements of sequence $a$ .
A beauty of a sequence $a$ is the minimum number of operations that is needed to delete all elements from sequence $a$ .
Jeff's written down a sequence of $m$ integers $b_{1}$ , $b_{2}$ , $...$ , $b_{m}$ . Now he wants to ask $q$ questions. Each question can be described with two integers $l_{i},r_{i}$ . The answer to the question is the beauty of sequence $b_{li}$ , $b_{li}+1$ , $...$ , $b_{ri}$ . You are given the sequence $b$ and all questions. Help Jeff, answer all his questions.
输入格式
The first line contains integer $m$ $(1<=m<=10^{5})$ . The next line contains $m$ integers $b_{1}$ , $b_{2}$ , $...$ , $b_{m}$ $(1<=b_{i}<=10^{5})$ .
The third line contains integer $q$ $(1<=q<=10^{5})$ — the number of questions. The next $q$ lines contain pairs of integers, $i$ -th of them contains a pair of integers $l_{i}$ , $r_{i}$ $(1<=l_{i}<=r_{i}<=m)$ — the description of $i$ -th question.
The third line contains integer $q$ $(1<=q<=10^{5})$ — the number of questions. The next $q$ lines contain pairs of integers, $i$ -th of them contains a pair of integers $l_{i}$ , $r_{i}$ $(1<=l_{i}<=r_{i}<=m)$ — the description of $i$ -th question.
输出格式
In $q$ lines print the answers to Jeff's queries. Print the answers according to the order of questions in input.
输入输出样例
输入 #1
5 2 2 1 1 2 5 1 5 1 1 2 2 1 3 2 3
输出 #1
2 1 1 2 2
输入 #2
10 2 1 3 3 3 3 1 3 1 1 10 4 8 2 10 1 10 4 4 1 3 2 4 6 7 1 9 2 5 1 1
输出 #2
2 3 3 1 3 2 2 3 2 1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted