Codeforces 890 C. Petya and Catacombs (贪心)

网友投稿 894 2022-08-26

Codeforces 890 C. Petya and Catacombs (贪心)

Codeforces 890 C. Petya and Catacombs (贪心)

Description

A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs.Catacombs consist of several rooms and bidirectional passages between some pairs of them. Some passages can connect a room to itself and since the passages are built on different depths they do not intersect each other. Every minute Petya arbitrary chooses a passage from the room he is currently in and then reaches the room on the other end of the passage in exactly one minute. When he enters a room at minute i, he makes a note in his logbook with number ti:If Petya has visited this room before, he writes down the minute he was in this room last time;Otherwise, Petya writes down an arbitrary non-negative integer strictly less than current minute i.Initially, Petya was in one of the rooms at minute 0, he didn’t write down number t0.At some point during his wandering Petya got tired, threw out his logbook and went home. Vasya found his logbook and now he is curious: what is the minimum possible number of rooms in Paris catacombs according to Petya’s logbook?

Input

The first line contains a single integer n (1 ≤ n ≤ 2·10^5) — then number of notes in Petya’s logbook.The second line contains n non-negative integers t1, t2, …, tn (0 ≤ ti < i) — notes in the logbook.

Output

In the only line print a single integer — the minimum possible number of rooms in Paris catacombs.

Examples input

20 0

Examples output

2

题意

每到达一个房间,有两种标号的记法:

记录上一次到达该房间的时间随机一个小于当前时间的数字

问最少有几个房间。

思路

显然房间数目越少要求我们经过同一个房间的次数尽可能的多,于是对于每一个编号,我们假设它记录的是上一次到达该房间的时间,判断假设是否成立,若成立,更新该房间的最后抵达时间,否则房间数加一。

AC 代码

#include#define IO ios::sync_with_stdio(false);\ cin.tie(0);\ cout.tie(0);typedef long long LL;using namespace std;const int maxn = 2e6+10;int last[maxn];int a[maxn];int num[maxn];int n;void solve(){ int ans = 1; for(int i=1; i<=n; i++) { int now = a[i]; if(last[num[now]]==a[i]) { last[num[now]]=i; num[i] = num[now]; } else { num[i]=++ans; last[num[i]]=i; } } cout<>n; for(int i=1; i<=n; i++) cin>>a[i]; solve(); return 0;}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:YTU 2425: C语言习题 输出月份
下一篇:Codeforces 892 D. Gluttony (思维)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~