码迷,mamicode.com
首页 > 其他好文 > 详细

UESTC 2016 Summer Training #1 Div.2 F - Mission in Amman (A) 动态维护(刷新:--、++)

时间:2016-07-13 17:12:38      阅读:210      评论:0      收藏:0      [点我收藏+]

标签:

F - Mission in Amman (A)
Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

standard input/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.

Sample Input

Input
4 5 4
1 2 1 2
1 3
2 4
4 5
3 5
Output
2
1
1
2

Source

http://acm.hust.edu.cn/vjudge/contest/view.action?cid=121539#problem/F


My Solution

先整体的处理一遍,然后边输入操作, 边维护, 什么时候++, 什么时候--

这样直接边跑边维护, 挺常见的, Codeforces上见过好几次^_^



  Thank you!

                                                                                                                                               ------from ProLights

UESTC 2016 Summer Training #1 Div.2 F - Mission in Amman (A) 动态维护(刷新:--、++)

标签:

原文地址:http://blog.csdn.net/prolightsfxjh/article/details/51892609

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!