当前位置:网站首页>[exercise -10] unread messages
[exercise -10] unread messages
2022-07-06 15:57:00 【Flame car】
Title Description
There is a group of people in an internet email message group. Messages are sent to all members of the group, and no two messages are sent at the same time.
Immediately before a person sends a message, they read all their unread messages up to that point.
Each sender also reads their own message the moment it is sent. Therefore, a person’s unread messages are exactly the set of messages sent after that person’s last message.
Each time a message is sent, compute the total number of unread messages over all group members.
Input
The first line of input contains two integers n (1 ≤ n ≤ 109 ) and m (1 ≤ m ≤ 1,000), where n is the number of people in the group, and m is the number of messages sent. The group members are
identified by number, 1 through n.
Each of the next m lines contains a single integer s (1 ≤ s ≤ n), which is the sender of that message. These lines are in chronological order.
Output
Output m lines, each with a single integer, indicating the total number of unread messages over all group members, immediately after each message is sent.
The sample input
【 Examples 1】
2 4
1
2
1
2
【 Examples 2】
3 9
1
2
3
2
1
3
3
2
1
Sample output
【 Examples 1】
1
1
1
1
【 Examples 2】
2
3
3
4
3
3
5
4
3
The main idea of the topic :
Yes n Personal hair m The second news ( Only one person at a time ), Next m Line no line input is sent by the first person .
When a person sends a message , Everyone else will have an unread message , When a person sends a message , His unread news will be cleared 0.
AC Code :
#include<bits/stdc++.h>
using namespace std;
#define CLEAR(a) memset(a,0,sizeof a);
typedef long long ll;
const int N = 1e5+5;
const ll mod = 1e9+7;
map<ll,ll> mp;
int main()
{
ll n,m,x,res=0;
cin>>n>>m;
for(int i=1;i<=m;i++)
{
cin>>x;
res+=(n-(i-mp[x]));
mp[x]=i;
cout<<res<<endl;
}
return 0;
}
Ideas :
Because when sending a message , Everyone's unread messages except myself will +1. Let's assume that everyone will +1, That is, the total number of unread messages +n.
Then we subtract the message that the sender has read , use map Record the last time you read the message , use i-mp[x] It's the news that I've read ( No extra -1, because A When sending messages A also +1 了 ).
Then just add n-(i-mp[x]) Is the amount of unread messages .
边栏推荐
- Matlab comprehensive exercise: application in signal and system
- 【高老师UML软件建模基础】20级云班课习题答案合集
- Information security - security professional name | CVE | rce | POC | Vul | 0day
- Cost accounting [14]
- Cost accounting [22]
- 0-1背包問題(一)
- STM32 how to use stlink download program: light LED running light (Library version)
- 动态规划前路径问题
- 程序员的你,有哪些炫技的代码写法?
- 0-1 knapsack problem (I)
猜你喜欢
C语言必背代码大全
1010 things that college students majoring in it must do before graduation
STM32如何使用STLINK下载程序:点亮LED跑马灯(库版本)
Gartner: five suggestions on best practices for zero trust network access
7-1 懂的都懂 (20 分)
信息安全-威胁检测-NAT日志接入威胁检测平台详细设计
mysql导入数据库报错 [Err] 1273 – Unknown collation: ‘utf8mb4_0900_ai_ci’
Ball Dropping
Learning record: how to perform PWM output
渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
随机推荐
渗透测试 ( 4 ) --- Meterpreter 命令详解
Penetration testing (5) -- a collection of practical skills of scanning King nmap and penetration testing tools
[exercise-4] (UVA 11988) broken keyboard = = (linked list)
Web based photo digital printing website
Penetration test (1) -- necessary tools, navigation
Information security - Analysis of security orchestration automation and response (soar) technology
CEP used by Flink
渗透测试 ( 1 ) --- 必备 工具、导航
编程到底难在哪里?
Opencv learning log 13 corrosion, expansion, opening and closing operations
Learning record: Tim - Basic timer
C语言必背代码大全
[exercise-7] crossover answers
Indonesian medical sensor Industry Research Report - market status analysis and development prospect forecast
Cost accounting [15]
【练习-5】(Uva 839)Not so Mobile(天平)
渗透测试 ( 5 ) --- 扫描之王 nmap、渗透测试工具实战技巧合集
Gartner: five suggestions on best practices for zero trust network access
【练习4-1】Cake Distribution(分配蛋糕)
China's salt water membrane market trend report, technological innovation and market forecast