zoukankan      html  css  js  c++  java
  • Codeforces Gym 100989F(STL: map)

    F. Mission in Amman (A)

    time limit per test

    1.0 s

    memory limit per test

    256 MB

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

    Example

    input

    Copy

    4 5 4
    1 2 1 2
    1 3
    2 4
    4 5
    3 5

    output

    Copy

    2
    1
    1
    2

    代码如下:

    #include <iostream>
    #include <cstdio>
    #include <map>
    #include <set>
    #include <cstring>
    using namespace std;
    int main(){
        int m, n, p;
        while (cin >> m >> n >> p){
            map<int, int> a;
            set<int> index;
            map<int, int> num;
            for (int i = 1; i <= m; i++){
                int x;
                scanf("%d", &x);
                a[i] = x;
                index.insert(x);
                num[a[i]]++;
            }
            for (int j = 1; j <= p; j++){
                int x, y;
                scanf("%d %d", &x, &y);
                num[a[x]]--;
                if (num[a[x]] == 0) index.erase(index.find(a[x]));
                a[x] = y;
                num[a[x]]++;
                index.insert(y);
                cout << n - index.size() << endl;
            }
        }
    }
    天晴了,起飞吧
  • 相关阅读:
    如何控制Yahoo! Slurp蜘蛛的抓取频度_国外博客资源站_百度空间
    PHP学习之十:foreach
    asp.net 上传控件
    程序员转型不得不说的事 成为管理者
    博客无法使用外站图片,暂停更新一段时间
    C#控制光驱开关
    通过输入方式在Android上进行微博OAuth登录
    .Net 绑定Dropdownlist的时自定义组合字段后显示
    XNA那些事(四) 3D知识初步
    jQuery实现图片延迟加载
  • 原文地址:https://www.cnblogs.com/jianqiao123/p/11218823.html
Copyright © 2011-2022 走看看