zoukankan      html  css  js  c++  java
  • 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

     
    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个人给定初始位置 ,每次变化后输出没有被覆盖的位置的个数

    题解:强行stl
     1 #include<bits/stdc++.h>
     2 #define ll __int64
     3 using namespace std;
     4 int n,m,q;
     5 vector<int> ve[100005];
     6 int gg[100005];
     7 int exm;
     8 int a,b;
     9 int main()
    10 {
    11     scanf("%d %d %d",&n,&m,&q);
    12     int flag=0;
    13     for(int i=1;i<=n;i++)
    14     {
    15         scanf("%d",&exm);
    16         if(ve[exm].size()==0)
    17             flag++;
    18         gg[i]=exm;
    19         ve[exm].push_back(i);
    20     }
    21     for(int i=1;i<=q;i++)
    22     {
    23         scanf("%d %d",&a,&b);
    24         if(ve[gg[a]].size()==1)
    25         {
    26             flag--;
    27         }ve[gg[a]].pop_back();
    28         if(ve[b].size()==0)
    29             flag++;
    30         ve[b].push_back(a);
    31         gg[a]=b;
    32         cout<<m-flag<<endl;
    33     }
    34 
    35     return 0;
    36 }
  • 相关阅读:
    爬虫入门系列(一):快速理解HTTP协议
    python爬虫如何入门
    利用python基于微博数据打造一颗“心”
    Python 爬虫:把廖雪峰教程转换成 PDF 电子书
    用python爬取微博数据并生成词云
    4本相见恨晚的Linux入门书籍
    程序员薪酬大调查:学哪种语言最赚钱?
    无人车时代:用深度学习辅助行人检测
    老大哥在看着你!我国部署超2000万个AI监控系统
    以彼之道,还施彼身——使用机器学习来揪出作弊的玩家
  • 原文地址:https://www.cnblogs.com/hsd-/p/5662093.html
Copyright © 2011-2022 走看看