欢迎来到起遇信息学
起遇信息学正处于上线筹建阶段,以下功能已全部开放免费体验: ✅ 完整题库浏览与代码提交评测(C / C++ / Python / Java 等) ✅ 入门到进阶的系列课程试读、作业与考试 ✅ AI 提示、AI 作业分析等智能助教功能 ✅ 赛事模拟与个人能力报告 ✅ 邮箱注册开放 ⏳ 付费课程订阅与微信/支付宝支付通道 ⏳ 手机号登录,微信扫码登录、微信公众号绑定 使用中如遇任何问题,欢迎通过页面底部 **"联系我们"** 与我们沟通。
CF1714B.Remove Prefix
Remove Prefix
Polycarp was presented with some sequence of integers of length (). A sequence can make Polycarp happy only if it consists of different numbers (i.e. distinct numbers).
In order to make his sequence like this, Polycarp is going to make some (possibly zero) number of moves.
In one move, he can:
- remove the first (leftmost) element of the sequence.
For example, in one move, the sequence will produce the sequence , which consists of different numbers.
Determine the minimum number of moves he needs to make so that in the remaining sequence all elements are different. In other words, find the length of the smallest prefix of the given sequence , after removing which all values in the sequence will be unique.
Input
The first line of the input contains a single integer () — the number of test cases.
Each test case consists of two lines.
The first line contains an integer () — the length of the given sequence .
The second line contains integers () — elements of the given sequence .
It is guaranteed that the sum of values over all test cases does not exceed .
Output
For each test case print your answer on a separate line — the minimum number of elements that must be removed from the beginning of the sequence so that all remaining elements are different.
Note
The following are the sequences that will remain after the removal of prefixes:
- ;
- ;
- ;
- ;
- .
It is easy to see that all the remaining sequences contain only distinct elements. In each test case, the shortest matching prefix was removed.
Samples
5
4
3 1 4 3
5
1 1 1 1 1
1
1
6
6 5 4 3 2 1
7
1 2 1 7 1 2 1
1
4
0
0
5
在线编程 IDE
建议全屏模式获得最佳体验
| 进入全屏编程 | Alt+E |
| 递交评测 | Ctrl+Enter |
| 注释/取消注释 | Ctrl+/ |
| 缩放字体 | Ctrl+滚轮 |