首页 技术 正文
技术 2022年11月18日
0 收藏 303 点赞 3,935 浏览 2047 个字

You must have heard about Agent Mahone! Dr. Ibrahim hired him to catch the cheaters in the Algorithms course. N students cheated and failed this semester and they all want to know who Mahone is in order to take revenge!

Agent Mahone is planning to visit Amman this weekend. During his visit, there are M places where he might appear. The N students are trying to cover these places with their leader Hammouri, who has been looking for Mahone since two semesters already!

Hammouri will be commanding students to change their places according to the intel he receives. Each time he commands a student to change his position, he wants to know the number of places that are not covered by anyone.

Can you help these desperate students and their leader Hammouri by writing an efficient program that does the job?

Input

The first line of input contains three integers N, M and Q (2 ≤ N, M, Q ≤ 105), the number of students, the number of places, and the number of commands by Hammouri, respectively.

Students are numbered from 1 to N. Places are numbered from 1 to M.

The second line contains N integers, where the ith integer represents the location covered by the ith student initially.

Each of the following Q lines represents a command and contains two integers, A and B, where A (1 ≤ A ≤ N) is the number of a student and B (1 ≤ B ≤ M) is the number of a place. The command means student number A should go and cover place number B. It is guaranteed that B is different from the place currently covered by student A.

Changes are given in chronological order.

Output

After each command, print the number of uncovered places.

Example

Input

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

Output

2
1
1
2
题意:第一行输入三个数,N、M、Q,N代表有N个人,M代表M个地方,Q代表Q个地方,第二个行输入N个整数,第一个数表示第一个人去的地方,第二个数表示第二个人去的地方,以此类推。接下来的Q行代表Q个指令,每行两个数u和v,表示第u个人去第v个地方,每执行完一个指令输出没有任何人的地方个数。
题解:用两个数组,第一个数组a[i]表示第i个人所去的地方,b[j]表示第j个地方的人数,定义一个ans变量对没人的地方进行计数,每执行一次指令,对a[i],b[j],ans进行更新即可。
具体分析详见代码:
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#define ll long long
using namespace std;
int main(){
ll n,m,q;
int u,v;
cin>>n>>m>>q;
int ans=m;
ll a[n+];
memset(a,,sizeof(a));
ll b[m+];
memset(b,,sizeof(b));
for(int i=;i<=n;i++){
cin>>a[i];
b[a[i]]++;
if(b[a[i]]==)
ans--;
}
while(q--){
cin>>u>>v;
b[a[u]]--;
if(b[a[u]]==) ans++;
a[u]=v;
b[v]++;
if(b[v]==) ans--;
cout<<ans<<endl;
}
return ;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,077
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,552
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,400
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,176
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,812
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,894