AtCoder Grand Contest 017 C - Snuke and Spells

Problem Statement

There are N balls in a row. Initially, the i-th ball from the left has the integer Ai written on it.

When Snuke cast a spell, the following happens:

  • Let the current number of balls be k. All the balls with k written on them disappear at the same time.

Snuke's objective is to vanish all the balls by casting the spell some number of times. This may not be possible as it is. If that is the case, he would like to modify the integers on the minimum number of balls to make his objective achievable.

By the way, the integers on these balls sometimes change by themselves. There will be M such changes. In the j-th change, the integer on the Xj-th ball from the left will change into Yj.

After each change, find the minimum number of modifications of integers on the balls Snuke needs to make if he wishes to achieve his objective before the next change occurs. We will assume that he is quick enough in modifying integers. Here, note that he does not actually perform those necessary modifications and leaves them as they are.

Constraints

  • 1N200000
  • 1M200000
  • 1AiN
  • 1XjN
  • 1YjN

Subscore

  • In the test set worth 500 points, N200 and M200.

Input

Input is given from Standard Input in the following format:

N M
A1 A2 ... AN
X1 Y1
X2 Y2
:
XM YM

Output

Print M lines. The j-th line should contain the minimum necessary number of modifications of integers on the balls to make Snuke's objective achievable.


Sample Input 1

Copy
5 3
1 1 3 4 5
1 2
2 5
5 4

Sample Output 1

Copy
0
1
1
  • After the first change, the integers on the balls become 21345, from left to right. Here, all the balls can be vanished by casting the spell five times. Thus, no modification is necessary.
  • After the second change, the integers on the balls become 25345, from left to right. In this case, at least one modification must be made. One optimal solution is to modify the integer on the fifth ball from the left to 2, and cast the spell four times.
  • After the third change, the integers on the balls become 25344, from left to right. Also in this case, at least one modification must be made. One optimal solution is to modify the integer on the third ball from the left to 2, and cast the spell three times.

Sample Input 2

Copy
4 4
4 4 4 4
4 1
3 1
1 1
2 1

Sample Output 2

Copy
0
1
2
3

Sample Input 3

Copy
10 10
8 7 2 9 10 6 6 5 5 4
8 1
6 3
6 2
7 10
9 7
9 9
2 4
8 1
1 8
7 7

Sample Output 3

Copy
1
0
1
2
2
3
3
3
3
2

题意:一个人在玩卡片游戏,每张卡片上有一个数,每一轮删去写着当前卡片数目的卡片,问最少修改多少张使得最后所有卡片都被删完,带修改。

题解:

智商题

对于一种权值x,记cnt[x]表示x的出现次数,我们把[x - cnt[x], x]这条线段画出来,最后就是没被任何线段覆盖的长度

正确性还是很显然的...想到就好了

#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define mset(x, y) memset(x, y, sizeof x)
#define mcpy(x, y) memcpy(x, y, sizeof x)
using namespace std;
 
typedef long long LL;
typedef pair < int, int > pii;
 
inline int Read()
{
	int x = 0, f = 1, c = getchar();
	for (; !isdigit(c); c = getchar())
		if (c == '-')
			f = -1;
	for (;  isdigit(c); c = getchar())
		x = x * 10 + c - '0';
	return x * f;
}
 
const int MAXN = 200005;
 
int n, m, ret, a[MAXN], b[MAXN], c[MAXN];
 
int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	ret = n = Read(), m = Read();
	for (int i = 1; i <= n; i ++)
	{
		a[i] = Read(), c[a[i]] ++;
		if (a[i] - c[a[i]] >= 0 && ++ b[a[i] - c[a[i]]] == 1)
			ret --;
	}
	while (m --)
	{
		int x = Read(), y = Read();
		if (a[x] - c[a[x]] >= 0 && !-- b[a[x] - c[a[x]]])
			ret ++;
		c[a[x]] --;
		a[x] = y;
		c[a[x]] ++;
		if (a[x] - c[a[x]] >= 0 && ++ b[a[x] - c[a[x]]] == 1)
			ret --;
		printf("%d\n", ret);
	}
}


AtCoder Practice Contest #B - インタラクティブ練習 (Interactive Sorting) 是一道比较有趣的题目。它是一道交互式的排序题目,需要你与一个神秘程序进行交互,以便将一串无序的数字序列排序。 具体来说,这个神秘程序会给你一个长度为 $N$ 的数字序列,然后你需要通过询问它两个数字的大小关系,来逐步确定这个序列的排序顺序。每次询问之后,神秘程序都会告诉你两个数字的大小关系,比如第一个数字比第二个数字小,或者第二个数字比第一个数字小。你需要根据这个信息,来调整这个数字序列的顺序,然后再向神秘程序询问下一对数字的大小关系,以此类推,直到这个数字序列被完全排序为止。 在这个过程中,你需要注意以下几点: 1. 你最多只能向神秘程序询问 $Q$ 次。如果超过了这个次数,那么你的程序会被判定为错误。 2. 在每次询问之后,你需要及时更新数字序列的顺序。具体来说,如果神秘程序告诉你第 $i$ 个数字比第 $j$ 个数字小,那么你需要将这两个数字交换位置,以确保数字序列的顺序是正确的。如果你没有及时更新数字序列的顺序,那么你的程序也会被判定为错误。 3. 在询问的过程中,你需要注意避免重复询问。具体来说,如果你已经询问过第 $i$ 个数字和第 $j$ 个数字的大小关系了,那么你就不需要再次询问第 $j$ 个数字和第 $i$ 个数字的大小关系,因为它们的大小关系已经被确定了。 4. 在排序完成之后,你需要将排序结果按照从小到大的顺序输出。如果你输出的结果不正确,那么你的程序也会被判定为错误。 总的来说,这道题目需要你熟练掌握交互式程序设计的技巧,以及排序算法的实现方法。如果你能够熟练掌握这些技巧,那么就可以顺利地完成这道非传统题了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值