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. h5小功能_classList和自定义属性data

    ###1.classList返回一个对象集 通过obj.classList.add()或obj.classList.remove()可操作对象的class属性值 classList.toggle( ) ...

  2. vue组件star开发基于vue-cli

    <template> <div class="stars"> <div v-for="(item,ind) in num" :ke ...

  3. JSON for-in 遍历

    (代码均以js代码示例) 1.可以使用 for-in 来循环对象的属性,使用中括号([])来访问属性的值: 这中方法便于一些在不确定有属性的情况下使用. var myObj = { "nam ...

  4. [转帖]CentOS 6 服务器安全配置指南(通用)

    CentOS 6 服务器安全配置指南(通用) http://seanlook.com/2014/09/07/linux-security-general-settings/  发表于 2014-09- ...

  5. AngularJS基于MVC的复杂操作案例

    AngularJS基于MVC的复杂操作案例 <!DOCTYPE html> <html> <head> <meta charset="UTF-8&q ...

  6. day 7-13 数据库的数据类型

    一. 数据类型 存储引擎决定了表的类型,而表内存放的数据也要有不同的类型,每种数据类型都有自己的宽度,但宽度是可选的 注意:int类型的宽度是显示宽度,并非是数据的存储宽度 详细的介绍:http:// ...

  7. MHA高可用及读写分离

    一.MHA简介 二.工作流程 三.MHA架构图 四.MHA工具介绍 五.基于GTID的主从复制 六.部署MHA 七.配置VIP漂移 八.配置binlog-server 九.MySQL中间件Atlas

  8. kibana——es的批量操作

    一·_mget: 1.创建的索引如下: 2.批量查询: #查询两个 GET _mget { "docs":[ { "_index":"testdb&q ...

  9. orcale增加列脚本

    --编号declare v_cnt number; V_SQL VARCHAR2 (500) := '';begin select count(*) into v_cnt from dual wher ...

  10. Redux学习(3) ----- 结合React使用

    Redux 和React 进行结合, 就是用React 做UI, 因为Redux中定义了state,并且定义了改变或获取state的方法,完全可以用来进行状态管理,React中就不用保存状态了,它只要 ...