[题目链接]

https://www.lydsy.com/JudgeOnline/problem.php?id=4419

[算法]

用std :: set维护每个人的好友集合

当两人成为好友时将每人接收到的消息减去另一个人之前发的消息 , 当两人解除好友时 , 将每人接受到的消息加上另一个人发的消息 , 这是一个类似于差分前缀和的过程 , 不再赘述 , 详见代码

时间复杂度 : O(MlogN)

[代码]

#include<bits/stdc++.h>
using namespace std;
#define MAXN 500010 int n , m;
int cnt[MAXN] , ans[MAXN];
set< int > S[MAXN]; int main()
{ scanf("%d%d" , &n , &m);
for (int i = ; i <= m; i++)
{
char op[];
scanf("%s" , &op);
if (op[] == '!')
{
int x;
scanf("%d" , &x);
cnt[x]++;
} else if (op[] == '+')
{
int x , y;
scanf("%d%d" , &x , &y);
S[x].insert(y);
S[y].insert(x);
ans[x] -= cnt[y];
ans[y] -= cnt[x];
} else
{
int x , y;
scanf("%d%d" , &x , &y);
ans[x] += cnt[y];
ans[y] += cnt[x];
S[x].erase(S[x].find(y));
S[y].erase(S[y].find(x));
}
}
for (int i = ; i <= n; i++)
{
for (set< int > :: iterator it = S[i].begin(); it != S[i].end(); it++)
ans[i] += cnt[*it];
}
for (int i = ; i < n; i++) printf("%d " , ans[i]);
printf("%d\n" , ans[n]); return ;
}

最新文章

  1. MySQL for mac使用记录
  2. C# property简介
  3. openldap主机访问控制(基于hostname)
  4. 进程控制之fork函数
  5. OSUnMapTbl[]的原理
  6. 柔性数组-读《深度探索C++对象模型》有感
  7. Restful 和 Jersey介绍(Web Service )
  8. 包图Package
  9. Problem : 1022 ( Train Problem I )
  10. [转]gitlab cicd (二)系列之安装git-runner rpm安装方式
  11. jenkins疑惑
  12. centos cron 自动执行脚本异常 命令不生效的解决办法
  13. 【原】The Linux Command Line - Manipulation Files And Directories
  14. 分布式文件系统---GlusterFS
  15. Atitit 手机图片备份解决方案attilax总结
  16. TFS2018环境搭建一硬件要求
  17. 97.394570112228 - Query OK, 1 row affected (43.05 sec) - the overhead of parsing and network communication
  18. MOTT介绍(2)window安装MQTT服务器和client
  19. Elasticsearch技术解析与实战(二)文档的CRUD操作
  20. mybatis 控制台打印sql脚本

热门文章

  1. Codeforces 86D Powerful array (莫队算法)
  2. Python3:urllib模块的使用
  3. ExtNet配置webconfig
  4. foobar2000设置关闭按钮最小化到系统托盘
  5. 10分钟学会前端工程化(webpack4.0)
  6. iOS Application Security
  7. 通过BSSID和无线流量传输后门Payload
  8. BUPT复试专题—内存分配(2014-2)
  9. [WASM Rust] Use the js-sys Crate to Invoke Global APIs Available in Any JavaScript Environment
  10. HTML5面试题-b