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 ;
}

Gym - 100989F的更多相关文章

  1. Gym 100989F 水&愚&vector

    standard input/output You must have heard about Agent Mahone! Dr. Ibrahim hired him to catch the che ...

  2. UESTC 2016 Summer Training #1 Div.2

    最近意志力好飘摇..不知道坚不坚持得下去.. 这么弱还瞎纠结...可以滚了.. 水题都不会做.. LCS (A) 水 LCS (B) 没有看题 Gym 100989C 水 1D Cafeteria ( ...

  3. ACM: Gym 101047M Removing coins in Kem Kadrãn - 暴力

     Gym 101047M Removing coins in Kem Kadrãn Time Limit:2000MS     Memory Limit:65536KB     64bit IO Fo ...

  4. ACM: Gym 101047K Training with Phuket's larvae - 思维题

     Gym 101047K Training with Phuket's larvae Time Limit:2000MS     Memory Limit:65536KB     64bit IO F ...

  5. ACM: Gym 101047E Escape from Ayutthaya - BFS

    Gym 101047E Escape from Ayutthaya Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I6 ...

  6. ACM: Gym 101047B Renzo and the palindromic decoration - 手速题

     Gym 101047B  Renzo and the palindromic decoration Time Limit:2000MS     Memory Limit:65536KB     64 ...

  7. Gym 101102J---Divisible Numbers(反推技巧题)

    题目链接 http://codeforces.com/gym/101102/problem/J Description standard input/output You are given an a ...

  8. Gym 100917J---Judgement(01背包+bitset)

    题目链接 http://codeforces.com/gym/100917/problem/J Description standard input/outputStatements The jury ...

  9. Gym 100917J---dir -C(RMQ--ST)

    题目链接 http://codeforces.com/gym/100917/problem/D problem description Famous Berland coder and IT mana ...

随机推荐

  1. HTTL之初印象

    概述 HTTL (Hyper-Text Template Language) 是一个高性能的开源JAVA模板引擎, 适用于动态HTML页面输出, 可替代JSP页面, 指令和Velocity相似. 简洁 ...

  2. Java 获取当前日期的四种方法

    //1 通过Date类来获取当前时间,通过SimpleDateFormat来设置时间格式 SimpleDateFormat dateFormat = new SimpleDateFormat(&quo ...

  3. 查看端口占用cmd命令

    查看端口被占用的进程: 在任务管理器中结束进程:

  4. spring IOC源码分析(ApplicationContext)

    在上一篇文章中,我们以BeanFactory这条主线进行IOC的源码解析的,这里,将以ApplicationContext这条线进行分析.先看使用方法: @Test public void testA ...

  5. java随笔3 spring 的注入执行逻辑顺序

  6. rbac组件引用

    一. 批量操作思路 # 待新增 路由系统中有,但是数据库中还没有 路由系统的集合 - 数据库中权限集合 # 待更新 路由系统中有,数据库中也有, 只是更改了一些信息 路由系统的集合 & 数据库 ...

  7. 设计模式笔记:简单工厂模式(Simple Factory)

    1. 简单工厂模式简介 1.1 定义 简单工厂模式:定义一个Factory类,可以根据参数的不同返回不同类的实例,被创建的实例通常有共同的父类. 简单工厂模式:只需要一个Factory类. 简单工厂模 ...

  8. adoquery怎样判断数据在缓存中有修改啊

    ADOQry.Filtered:=false;       ADOQry.Filtered:=true;       ADOQry.FilterGroup:=fgPendingRecords ;Fil ...

  9. Vue之动态绑定CSS样式

    demo.html <!DOCTYPE html> <html lang="en" xmlns:v-bind="http://www.w3.org/19 ...

  10. Vue之computed计算属性

    demo.html <!DOCTYPE html> <html lang="en" xmlns:v-bind="http://www.w3.org/19 ...