Gym 100989F 水&愚&vector
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 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.
Sample Input
4 5 4
1 2 1 2
1 3
2 4
4 5
3 5
2
1
1
2 题意:n个人 m个位置 q次变化 n个人给定初始位置 ,每次变化后输出没有被覆盖的位置的个数 题解:强行stl
#include<bits/stdc++.h>
#define ll __int64
using namespace std;
int n,m,q;
vector<int> ve[];
int gg[];
int exm;
int a,b;
int main()
{
scanf("%d %d %d",&n,&m,&q);
int flag=;
for(int i=;i<=n;i++)
{
scanf("%d",&exm);
if(ve[exm].size()==)
flag++;
gg[i]=exm;
ve[exm].push_back(i);
}
for(int i=;i<=q;i++)
{
scanf("%d %d",&a,&b);
if(ve[gg[a]].size()==)
{
flag--;
}ve[gg[a]].pop_back();
if(ve[b].size()==)
flag++;
ve[b].push_back(a);
gg[a]=b;
cout<<m-flag<<endl;
} return ;
}
Gym 100989F 水&愚&vector的更多相关文章
- Gym 100971C 水&愚&三角形
Description standard input/output Announcement Statements There is a set of n segments with the le ...
- Gym 100971B 水&愚
Description standard input/output Announcement Statements A permutation of n numbers is a sequence ...
- Gym - 100989F
You must have heard about Agent Mahone! Dr. Ibrahim hired him to catch the cheaters in the Algorithm ...
- UESTC 2016 Summer Training #1 Div.2
最近意志力好飘摇..不知道坚不坚持得下去.. 这么弱还瞎纠结...可以滚了.. 水题都不会做.. LCS (A) 水 LCS (B) 没有看题 Gym 100989C 水 1D Cafeteria ( ...
- Codeforces 757C. Felicity is Coming!
C. Felicity is Coming! time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- poj1330+hdu2586 LCA离线算法
整整花了一天学习了LCA,tarjan的离线算法,就切了2个题. 第一题,给一棵树,一次查询,求LCA.2DFS+并查集,利用深度优先的特点,回溯的时候U和U的子孙的LCA是U,U和U的兄弟结点的子孙 ...
- LeetCode--第180场周赛
LeetCode--第180场周赛 1380. 矩阵中的幸运数 class Solution { public: vector<int> luckyNumbers (vector<v ...
- codeforces Gym 100187L L. Ministry of Truth 水题
L. Ministry of Truth Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100187/p ...
- Codeforces gym 100685 C. Cinderella 水题
C. CinderellaTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100685/problem/C ...
随机推荐
- 有关a++,++a的基础问题
今天跟朋友讨论java的赋值与自增问题 @Test public void test2() { int a = 5; int b = a++; System.out.println("a = ...
- js实现全选,反选,全不选
思路:1.获取元素.2.用for循环历遍数组,把checkbox的checked设置为true即实现全选,把checkbox的checked设置为false即实现不选.3.通过if判断,如果check ...
- Java基础面试操作题:读取该文件内容,并按照自然顺序排序后输出到 另一个文件中
package com.swift; import java.io.FileInputStream; import java.io.FileNotFoundException; import java ...
- js动态刷新时间
<script type="text/javascript"> //取得系统当前时间 function getTime(){ var myDate = new Date ...
- 第二篇:ssh.invoke_shell() 切换root出现的新问题
接上一篇:按照上一篇的方式,在没有对ssh.invoke_shell()执行后的登录提示符进行判断的话,那边有部分机器就回因为返回为空导致程序卡死. 正常机器 ssh.recv(9999) 命令返 ...
- tp3.2读取time()格式遇到的的问题(尚未解决)
在用tp3.2框架做一个讲座模块.最近又遇到了一个问题 如上图所示,我把日期和讲座开始时间结束时间分来放了.(这里的Jdate2和jdate3本来存放为time(7)类型的,后发现在原来这个7是可以改 ...
- 用dump为什么总会在前面出现/path/debug.php:193
解决方案,在php.ini中的xdebug中加一行代码:xdebug.overload_var_dump=1
- 20.VUE学习之-变异方法push的留言版实例讲解
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 初学js之qq聊天实例
实现的功能为上图所示,但是每新发送的消息必须显示在最上面. 我实现了两版,样式有是一样的.我们直接看代码. 版本一: <!DOCTYPE html> <html lang=" ...
- BFS:Open and Lock(一个数的逐位变化问题的搜索)
解体心得: 1.关于定义四维数组的问题,在起初使用时,总是在运行时出错,找了很多方法,最后全部将BFS()部分函数写在主函数中,将四维数组定义在主函数中才解决了问题.运行成功后再次将四维数组定义为全局 ...