bzoj 4419: [Shoi2013]发微博 (STL)
来源:互联网 发布:跑车手机主题软件 编辑:程序博客网 时间:2024/05/14 22:18
4419: [Shoi2013]发微博
Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 431 Solved: 239
[Submit][Status][Discuss]
Description
刚开通的SH微博共有n个用户(1..n标号),在短短一个月的时间内,用户们活动频繁,共有m条按时间顺序的记录:
! x 表示用户x发了一条微博;
+ x y 表示用户x和用户y成为了好友
- x y 表示用户x和用户y解除了好友关系
当一个用户发微博的时候,所有他的好友(直接关系)都会看到他的消息。
假设最开始所有人之间都不是好友关系,记录也都是合法的(即+ x y时x和y一定不是好友,而- x y时x和y一定是好友)。
问这m条记录发生之后,每个用户分别看到了多少条消息。
Input
第1行2个整数n,m。
接下来m行,按时间顺序读入m条记录,每条记录的格式如题目所述,用空格隔开。
Output
输出一行n个用空格隔开的数(行末无空格),第i个数表示用户i最后看到了几条消息。
Sample Input
2 8
! 1
! 2
+ 1 2
! 1
! 2
- 1 2
! 1
! 2
! 1
! 2
+ 1 2
! 1
! 2
- 1 2
! 1
! 2
Sample Output
1 1
只有第4和第5条记录对应的消息被看到过。其他消息发送时,1和2不是好友。
对100%的数据,N<=200000,M<=500000
只有第4和第5条记录对应的消息被看到过。其他消息发送时,1和2不是好友。
对100%的数据,N<=200000,M<=500000
HINT
Source
题解:STL
用STL强行水过,貌似set,map都可以
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<map>#define N 200003using namespace std;map<int,int> mp[N];int n,m,cnt[N],ans[N];int main(){freopen("a.in","r",stdin);scanf("%d%d",&n,&m);for (int i=1;i<=m;i++) {char opt[10];int x,y;scanf("%s",opt+1);if (opt[1]=='!') {scanf("%d",&x);cnt[x]++;} if (opt[1]=='+'){scanf("%d%d",&x,&y); mp[x][y]=cnt[y]; mp[y][x]=cnt[x];}if (opt[1]=='-') {scanf("%d%d",&x,&y);ans[x]+=cnt[y]-mp[x][y]; mp[x].erase(y);ans[y]+=cnt[x]-mp[y][x]; mp[y].erase(x);}}for (int i=1;i<=n;i++) {map<int,int>::iterator it;for (it=mp[i].begin();it!=mp[i].end();++it) { ans[i]+=cnt[it->first]-(it->second); } printf("%d%c",ans[i]," \n"[i==n]);}}
0 0
- bzoj 4419: [Shoi2013]发微博 (STL)
- 【BZOJ】4419: [Shoi2013]发微博
- bzoj 4419: [Shoi2013]发微博
- BZOJ 4419 [Shoi2013]发微博
- BZOJ 4419: [Shoi2013]发微博
- bzoj 4419: [Shoi2013]发微博 乱搞
- [bzoj4419][Shoi2013]发微博(STL)
- 【BZOJ 4419】[Shoi2013]发微博 单纯暴力
- [BZOJ]4419: [Shoi2013]发微博 set暴力
- BZOJ_P4419 [SHOI2013]发微博(STL+Set)
- 4419: [Shoi2013]发微博 set
- 4419: [Shoi2013]发微博
- 4419: [Shoi2013]发微博|暴力|set
- [BZOJ4419][Shoi2013]发微博(map)
- bzoj 4415: [Shoi2013]发牌
- bzoj 4415: [Shoi2013]发牌
- bzoj 4415: [Shoi2013]发牌
- bzoj 4417: [Shoi2013]超级跳马(矩阵合并+快速幂)
- Linux 下编译FFmpeg 支持x264, x265
- 服务器与主机之间的文件传输SCP
- Java基础---深入浅出多线程
- (转)Winton:如何在100多个期货市场交易
- java多线程之Runnable
- bzoj 4419: [Shoi2013]发微博 (STL)
- Mybatis在oracle数据库中插入数据后返回自增ID值
- 初学myeclipse 遇到的问题
- Ajax访问Servlet的跨域请求问题—Access-Control-Allow-Origin
- HDU2553
- 消息队列应用场景
- 位移动画。txt
- html5新增的语义标签和表单验证功能
- 开源库xUtils3使用详解