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

F - Mission in Amman (A)

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d
& %I64u

Submit Status Practice Gym
100989F

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

时间: 2024-12-14 19:48:40

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

UESTC 2016 Summer Training #1 Div.2

最近意志力好飘摇..不知道坚不坚持得下去.. 这么弱还瞎纠结...可以滚了.. 水题都不会做.. LCS (A) 水 LCS (B) 没有看题 Gym 100989C 水 1D Cafeteria (B) 不会捉 Gym 100989E 水 Gym 100989F 水 Mission in Amman (B) 没看题 Queue (A) 感觉题意理解得有问题啊 1 #include <iostream> 2 #include <cstdio> 3 #include <cstr

UESTC 2016 Summer Training #5 Div.2(未完待续)

A #include <cstdio> #include <cstring> #include <vector> #define MAXN 100005 #define mem(a) memset(a, 0, sizeof(a)) using namespace std; int TreeArray[MAXN], Left[MAXN], Right[MAXN], Fork[MAXN]; typedef vector<int> Ve; vector<Ve

UESTC 2016 Summer Training #2 Div.2 A dp、递推、多阶段问题

A - A Time Limit:336MS     Memory Limit:1572864KB     64bit IO Format:%lld & %llu Submit Status Practice SPOJ AMR11A Description Thanks a lot for helping Harry Potter in finding the Sorcerer's Stone of Immortality in October. Did we not tell you that

UESTC 2016 Summer Training #1 Div.2 E - Accepted Passwords 讨论

E - Accepted Passwords Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100989E Description standard input/output Islam is usually in a hurry. He often types his passwords incorrectly. He hates

UESTC 2016 Summer Training #1 Div.2 L - Plus or Minus (A) dfs

L - Plus or Minus (A) Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100989L Description standard input/output AbdelKader enjoys math. He feels very frustrated whenever he sees an incorrect eq

UESTC 2016 Summer Training #1 Div.2 H - Queue (A) 贪心

H - Queue (A) Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice Gym 100989H Description standard input/output After the data structures exam, students lined up in the cafeteria to have a drink and ch

UESTC 2016 Summer Training #2 Div.2 E 分解质因素(除了以后剩下的可能也是个素数)

E - E Time Limit:3000MS     Memory Limit:1572864KB     64bit IO Format:%lld & %llu Submit Status Practice SPOJ AMR11E Description Arithmancy is Draco Malfoy's favorite subject, but what spoils it for him is that Hermione Granger is in his class, and

UESTC 2014 Summer Training #16 Div.2

虽然被刷了还是要继续战斗下去嗯...就是基础不好,难度相对较大 A.SPOJ AMR10A 点是顺时针给出的,可以在图上画画(脑补也行),连线x-a,x-b(x为选定的一个点,比如第一个点),就把所求面积分成了四部分,a-b左边部分是较容易求出来的, 三角形面积是直接可求,另外两个多边形面积是可以预处理出来的(多个三角形面积和) 反正我是沒想出來...看題解也理解半天,多邊形面積转化为三角形面积和 嗯嗯 #include <iostream> #include <cstdio> #

UESTC 2014 Summer Training #7 Div.2

DAY7一开始状态还行,最高纪录rank7,然后没力气了,一直跌到rank24,问题还是很多呐.昨天总结的问题依然很大. Problem A UVA 12377 就一开始还是慌了,没审清楚题意就去WA了一发. 大意是给你一个数字表示的字符串,最高20位,第一表示有N个质数,后面是其幂的非降序排列,所求能表示的数个数. 简单的排列组合题,不过需要处理出2~END的不同划分,并且满足非降序,用dfs处理即可. 具体就是dfs过程中记录下每一个数字出现的次数,因为相同的次数是不计顺序的,需要在统计时除