Gym 100989F STL

http://codeforces.com/gym/100989/problem/F

F. Mission in Amman (A)
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

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 NM 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


#include <iostream>
#include <map>
#include <cstring>
#include <set>
#include <cstdio>
using namespace std;

int main()
{
    int n,m,q;
    while(cin>>n>>m>>q){
        map <int,int> a;
        set <int> radix;
        map <int,int> num;
        for(int i=1;i<=n;i++){
            int x;
            scanf("%d",&x);
            a[i]=x;
            radix.insert(x);
            num[x]++;
        }
        for(int i=1;i<=q;i++){
            int x,y;
            scanf("%d%d",&x,&y);
            num[a[x]]--;
            if(num[a[x]]==0) radix.erase(radix.find(a[x]));
            a[x]=y;
            num[a[x]]++;
            radix.insert(y);
            cout<<m-radix.size()<<endl;
        }
    }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值