當(dāng)前位置:首頁(yè) > 芯聞號(hào) > 充電吧
[導(dǎo)讀]【CF簡(jiǎn)介】題目鏈接:CF 704A題面:A. Thor time limit per test 2 seconds memory limit per test 256 megabytes in

【CF簡(jiǎn)介】


題目鏈接:CF 704A


題面:


A. Thor time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There aren applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those applications (maybe Loki put a curse on it so he can't).

q events are about to happen (in chronological order). They are of three types:

Application x generates a notification (this new notification is unread). Thor reads all notifications generated so far by application x (he may re-read some notifications). Thor reads the first t notifications generated by phone applications (notifications generated in firstt events of the first type). It's guaranteed that there were at leastt events of the first type before this event. Please note that he doesn't read firstt unread notifications, he just reads the very firstt notifications generated on his phone and he may re-read some of them in this operation.

Please help Thor and tell him the number of unread notifications after each event. You may assume that initially there are no notifications in the phone.

Input

The first line of input contains two integers n andq (1?≤?n,?q?≤?300?000)?— the number of applications and the number of events to happen.

The next q lines contain the events. Thei-th of these lines starts with an integertypei?— type of thei-th event. If typei?=?1 ortypei?=?2 then it is followed by an integerxi. Otherwise it is followed by an integerti (1?≤?typei?≤?3,?1?≤?xi?≤?n,?1?≤?ti?≤?q).

Output

Print the number of unread notifications after each event.

Examples Input

3?4
1?3
1?1
1?2
2?3

Output

1
2
3
2

Input

4?6
1?2
1?4
1?2
3?3
1?3
1?3

Output

1
2
3
0
1
2

Note

In the first sample:

Application 3 generates a notification (there is 1 unread notification). Application 1 generates a notification (there are 2 unread notifications). Application 2 generates a notification (there are 3 unread notifications). Thor reads the notification generated by application 3, there are 2 unread notifications left.

In the second sample test:

Application 2 generates a notification (there is 1 unread notification). Application 4 generates a notification (there are 2 unread notifications). Application 2 generates a notification (there are 3 unread notifications). Thor reads first three notifications and since there are only three of them so far, there will be no unread notification left. Application 3 generates a notification (there is 1 unread notification). Application 3 generates a notification (there are 2 unread notifications).


題意:

??? 此題背景是手機(jī)app產(chǎn)生未讀消息,有n款app,對(duì)應(yīng)三種事件,事件一,x號(hào)app產(chǎn)生一條新的未讀消息。事件二,雷神讀了x號(hào)app的所有未讀信息。事件三,雷神讀了最開(kāi)始的t條消息,(這些就是按順序產(chǎn)生的app消息,不管讀沒(méi)讀)。每次事件后,都要輸出當(dāng)前的未讀消息數(shù)。


解題:

?? 解法中,數(shù)據(jù)結(jié)構(gòu)采用一個(gè)消息列表,記錄消息,一個(gè)數(shù)量數(shù)組,對(duì)應(yīng)每個(gè)app未讀消息數(shù),一個(gè)消息向量數(shù)組,對(duì)應(yīng)每個(gè)app產(chǎn)生的消息記錄的下標(biāo),一個(gè)pos數(shù)組,記錄每個(gè)app當(dāng)前已經(jīng)處理過(guò)最后一條信息的后一個(gè)位置,一個(gè)sum值記錄總未讀消息數(shù),一個(gè)p值記錄時(shí)間順序上通過(guò)操作三當(dāng)前處理過(guò)的最后一條消息位置。

??? 對(duì)應(yīng)操作一,可以設(shè)計(jì)一個(gè)消息列表,每產(chǎn)生一條新的消息,記錄該消息的產(chǎn)生app編號(hào),以及一個(gè)標(biāo)志代表該條消息是否已讀,同時(shí)給該app對(duì)應(yīng)的數(shù)量數(shù)組數(shù)量加一,該款app的向量數(shù)組記錄該條消息下標(biāo),未讀消息總數(shù)加一。

??? 對(duì)應(yīng)操作二,可以從該款app的pos數(shù)組中獲取到該款app最后處理的一條未讀信息的后一個(gè)位置,并開(kāi)始往后掃描讀,標(biāo)記該條消息為已讀。同時(shí),總未讀消息數(shù)減去該app對(duì)應(yīng)未讀消息數(shù),并將該app未讀消息數(shù)清零,更新最后處理未讀消息的后一個(gè)位置信息。

??? 對(duì)應(yīng)操作三,只要從p(當(dāng)前處理過(guò)最后一個(gè)位置開(kāi)始處理即可),這個(gè)過(guò)程中會(huì)遇到未讀和已讀消息,已讀的直接跳過(guò),未讀的需要標(biāo)記已讀,同時(shí)總sum值(未讀消息數(shù))減一,對(duì)應(yīng)的該消息產(chǎn)生app的未讀數(shù)量數(shù)組的值也要減一。

?? 總的復(fù)雜度是O(n),因?yàn)槊織l消息最多只會(huì)產(chǎn)生一遍,讀一遍。


代碼:


#include#include#include#include#define?LL?long?long
#define?sz?300010
using?namespace?std;
struct?info
{
	int?id;
	bool?vis;
}store[sz];
int?amount[sz];
int?pos[sz];
vectorv[sz];
int?main()
{
????int?sum=0,n,q,a,b,p=0,cnt=0;
????scanf("%d%d",&n,&q);
????for(int?i=0;i<q;i++)
????{
????	scanf("%d%d",&a,&b);
????	if(a==1)
????	{
	????	v[b].push_back(cnt);
	????	amount[b]++;
	????	sum++;
	????	store[cnt].vis=0;
	????	store[cnt].id=b;
	????	cnt++;
	????}
	????if(a==2)
	????{
????		sum-=amount[b];
????		amount[b]=0;
????		for(int?j=pos[b];j<v[b].size();j++)
????		{
		????	store[v[b][j]].vis=1;
		????}
		????pos[b]=v[b].size();
????	}
????	if(a==3)
????	{
	????	for(int?j=p;j<b;j++)
	????	{
	????		if(!store[j].vis)
	????		{
		????		store[j].vis=1;
		????		sum--;
		????		amount[store[j].id]--;
		????	}
	????	}
	????	p=max(p,b);
	????}
	????printf("%dn",sum);
????}
	return?0;
}



本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除。
換一批
延伸閱讀

9月2日消息,不造車的華為或?qū)⒋呱龈蟮莫?dú)角獸公司,隨著阿維塔和賽力斯的入局,華為引望愈發(fā)顯得引人矚目。

關(guān)鍵字: 阿維塔 塞力斯 華為

倫敦2024年8月29日 /美通社/ -- 英國(guó)汽車技術(shù)公司SODA.Auto推出其旗艦產(chǎn)品SODA V,這是全球首款涵蓋汽車工程師從創(chuàng)意到認(rèn)證的所有需求的工具,可用于創(chuàng)建軟件定義汽車。 SODA V工具的開(kāi)發(fā)耗時(shí)1.5...

關(guān)鍵字: 汽車 人工智能 智能驅(qū)動(dòng) BSP

北京2024年8月28日 /美通社/ -- 越來(lái)越多用戶希望企業(yè)業(yè)務(wù)能7×24不間斷運(yùn)行,同時(shí)企業(yè)卻面臨越來(lái)越多業(yè)務(wù)中斷的風(fēng)險(xiǎn),如企業(yè)系統(tǒng)復(fù)雜性的增加,頻繁的功能更新和發(fā)布等。如何確保業(yè)務(wù)連續(xù)性,提升韌性,成...

關(guān)鍵字: 亞馬遜 解密 控制平面 BSP

8月30日消息,據(jù)媒體報(bào)道,騰訊和網(wǎng)易近期正在縮減他們對(duì)日本游戲市場(chǎng)的投資。

關(guān)鍵字: 騰訊 編碼器 CPU

8月28日消息,今天上午,2024中國(guó)國(guó)際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)開(kāi)幕式在貴陽(yáng)舉行,華為董事、質(zhì)量流程IT總裁陶景文發(fā)表了演講。

關(guān)鍵字: 華為 12nm EDA 半導(dǎo)體

8月28日消息,在2024中國(guó)國(guó)際大數(shù)據(jù)產(chǎn)業(yè)博覽會(huì)上,華為常務(wù)董事、華為云CEO張平安發(fā)表演講稱,數(shù)字世界的話語(yǔ)權(quán)最終是由生態(tài)的繁榮決定的。

關(guān)鍵字: 華為 12nm 手機(jī) 衛(wèi)星通信

要點(diǎn): 有效應(yīng)對(duì)環(huán)境變化,經(jīng)營(yíng)業(yè)績(jī)穩(wěn)中有升 落實(shí)提質(zhì)增效舉措,毛利潤(rùn)率延續(xù)升勢(shì) 戰(zhàn)略布局成效顯著,戰(zhàn)新業(yè)務(wù)引領(lǐng)增長(zhǎng) 以科技創(chuàng)新為引領(lǐng),提升企業(yè)核心競(jìng)爭(zhēng)力 堅(jiān)持高質(zhì)量發(fā)展策略,塑強(qiáng)核心競(jìng)爭(zhēng)優(yōu)勢(shì)...

關(guān)鍵字: 通信 BSP 電信運(yùn)營(yíng)商 數(shù)字經(jīng)濟(jì)

北京2024年8月27日 /美通社/ -- 8月21日,由中央廣播電視總臺(tái)與中國(guó)電影電視技術(shù)學(xué)會(huì)聯(lián)合牽頭組建的NVI技術(shù)創(chuàng)新聯(lián)盟在BIRTV2024超高清全產(chǎn)業(yè)鏈發(fā)展研討會(huì)上宣布正式成立。 活動(dòng)現(xiàn)場(chǎng) NVI技術(shù)創(chuàng)新聯(lián)...

關(guān)鍵字: VI 傳輸協(xié)議 音頻 BSP

北京2024年8月27日 /美通社/ -- 在8月23日舉辦的2024年長(zhǎng)三角生態(tài)綠色一體化發(fā)展示范區(qū)聯(lián)合招商會(huì)上,軟通動(dòng)力信息技術(shù)(集團(tuán))股份有限公司(以下簡(jiǎn)稱"軟通動(dòng)力")與長(zhǎng)三角投資(上海)有限...

關(guān)鍵字: BSP 信息技術(shù)
關(guān)閉
關(guān)閉