CF398D.Instant Messanger

普及/提高-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

User ainta decided to make a new instant messenger called "aintalk". With aintalk, each user can chat with other people. User ainta made the prototype of some functions to implement this thing.

  1. login(u): User u logins into aintalk and becomes online.
  2. logout(u): User u logouts and becomes offline.
  3. add_friend(u, v): User u and user v become friends. It means, u and v can talk with each other. The friendship is bidirectional.
  4. del_friend(u, v): Unfriend user u and user v. It means, u and v cannot talk with each other from then.
  5. count_online_friends(u): The function returns the number of friends of user u who are online at the moment.

Because the messenger is being tested by some users numbered from 1 to n, there is no register method. This means, at the beginning, some users may be online, and some users may have friends.

User ainta is going to make these functions, but before making the messenger public, he wants to know whether he is correct. Help ainta verify his code.

用户 ainta 决定开发一款名为 “aintalk” 的新型即时通讯软件。借助 aintalk,每位用户均可与其他用户进行聊天。ainta 实现了部分功能的原型,以支持该软件。

  1. login(u):用户 uu 登录 aintalk 并变为在线状态。
  2. logout(u):用户 uu 注销并变为离线状态。
  3. add_friend(u, v):用户 uu 与用户 vv 成为好友。这意味着 uu 和 vv 可以相互聊天。好友关系是双向的。
  4. del_friend(u, v):解除用户 uu 与用户 vv 的好友关系。这意味着从该时刻起,uu 和 vv 将无法相互聊天。
  5. count_online_friends(u):该函数返回当前在线的好友数量(即用户 uu 的所有好友中处于在线状态的人数)。

由于该通讯软件正由编号为 11 至 nn 的若干用户进行测试,因此未设置注册功能。这意味着:初始状态下,部分用户可能已在线,且部分用户可能已拥有好友。

ainta 计划实现上述功能,但在将该通讯软件公开发布之前,他希望验证自己代码的正确性。请帮助 ainta 验证其实现。

输入格式

The first line contains three space-separated integers n, m and q (1 ≤ n ≤ 50000; 1 ≤ m ≤ 150000; 1 ≤ q ≤ 250000) — the number of users, the number of pairs of friends, and the number of queries.

The second line contains an integer o (1 ≤ o ≤ n) — the number of online users at the beginning. The third line contains o space-separated integers _x_1, _x_2, ..., x__o (1 ≤ x__i ≤ n) — the ids of the online users. It is guaranteed that these values are distinct.

Each of the next m lines contains two space-separated integers a__i and b__i (1 ≤ a__i, b__i ≤ n; a__i ≠ b__i) — the ids of two users who are friends at the beginning. It is guaranteed there are no multiple friendship given in the input. Note that the friendship is bidirectional.

Next q lines describe the q queries in the format:

  • "O u" (1 ≤ u ≤ n) : Call online(u). It is guaranteed that user u was offline just before the function call.
  • "F u" (1 ≤ u ≤ n) : Call offline(u). It is guaranteed that user u was online just before the function call.
  • "A u v" (1 ≤ u, v ≤ n; u ≠ v) : Call add_friend(u, v). It is guaranteed that these two users weren't friends just before the function call.
  • "D u v" (1 ≤ u, v ≤ n; u ≠ v) : Call del_friend(u, v). It is guaranteed that these two users were friends just before the function call.
  • "C u" (1 ≤ u ≤ n) : Call count_online_friends(u) and print the result in a single line.

第一行包含三个以空格分隔的整数 nn、mm 和 qq(1 ≤ n ≤ 500001 ≤ n ≤ 50000;1 ≤ m ≤ 1500001 ≤ m ≤ 150000;1 ≤ q ≤ 2500001 ≤ q ≤ 250000)——分别表示用户数量、朋友对数量以及查询数量。

第二行包含一个整数 oo(1 ≤ o ≤ n1 ≤ o ≤ n)——表示初始在线用户数量。第三行包含 oo 个以空格分隔的整数 x1, x2, ..., xox_1,\,x_2,\,...,\,x_o(1 ≤ xi ≤ n1 ≤ x_i ≤ n)——表示初始在线用户的编号。保证这些编号互不相同。

接下来的 mm 行,每行包含两个以空格分隔的整数 aia_i 和 bib_i(1 ≤ ai, bi ≤ n1 ≤ a_i,\,b_i ≤ n;ai ≠ bia_i ≠ b_i)——表示初始时互为朋友的两名用户的编号。保证输入中不会出现重复的朋友关系。注意:朋友关系是双向的。

接下来的 qq 行描述 qq 个查询,格式如下:

  • “O uu”(1 ≤ u ≤ n1 ≤ u ≤ n):调用 online(u)。保证在调用前用户 uu 处于离线状态。
  • “F uu”(1 ≤ u ≤ n1 ≤ u ≤ n):调用 offline(u)。保证在调用前用户 uu 处于在线状态。
  • “A uu vv”(1 ≤ u, v ≤ n1 ≤ u,\,v ≤ n;u ≠ vu ≠ v):调用 add_friend(u, v)。保证在调用前用户 uu 与 vv 并非朋友。
  • “D uu vv”(1 ≤ u, v ≤ n1 ≤ u,\,v ≤ n;u ≠ vu ≠ v):调用 del_friend(u, v)。保证在调用前用户 uu 与 vv 是朋友。
  • “C uu”(1 ≤ u ≤ n1 ≤ u ≤ n):调用 count_online_friends(u),并将结果单独输出在一行中。

输出格式

For each count_online_friends(u) query, print the required answer in a single line.

对于每个 count_online_friends(u) 查询,在单独一行中输出所需答案。

输入输出样例

  • 输入#1

    5 2 9
    1
    4
    1 3
    3 4
    C 3
    A 2 5
    O 1
    D 1 3
    A 1 2
    A 4 2
    C 2
    F 4
    C 2

    输出#1

    1
    2
    1

输入解题思路,AI测评打分。不知道怎么写?

首页