日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當前位置:首頁 > 芯聞號 > 充電吧
[導讀]【CF簡介】題目鏈接:CF 704A題面:A. Thor time limit per test 2 seconds memory limit per test 256 megabytes in

【CF簡介】


題目鏈接: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).


題意:

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


解題:

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

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

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

??? 對應操作三,只要從p(當前處理過最后一個位置開始處理即可),這個過程中會遇到未讀和已讀消息,已讀的直接跳過,未讀的需要標記已讀,同時總sum值(未讀消息數(shù))減一,對應的該消息產(chǎn)生app的未讀數(shù)量數(shù)組的值也要減一。

?? 總的復雜度是O(n),因為每條消息最多只會產(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)機構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點,本站亦不保證或承諾內(nèi)容真實性等。需要轉(zhuǎn)載請聯(lián)系該專欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請及時聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀

公司憑借其面向地面與非地面網(wǎng)絡的 AI 驅(qū)動、云原生移動解決方案的杰出創(chuàng)新斬獲殊榮華盛頓和得克薩斯州理查森, March 31, 2026 (GLOBE NEWSWIRE) -- 致力于構(gòu)建 AI 原生設(shè)計移動網(wǎng)絡的軟...

關(guān)鍵字: 衛(wèi)星 移動 創(chuàng)新獎 NI

前 Amazon Robotics 高管出任全球生產(chǎn)戰(zhàn)略部負責人,助力公司擴張 休斯敦, April 01, 2026 (GLOBE NEWSWIRE) -- 具身 AI 領(lǐng)域新一代領(lǐng)軍企業(yè)?Persona AI 今...

關(guān)鍵字: VI RS AN AI

可持續(xù)發(fā)展與企業(yè)責任實踐再獲國際資本市場認可 香港2026年3月31日 /美通社/ -- 全球領(lǐng)先的互聯(lián)網(wǎng)社區(qū)創(chuàng)建者 - 網(wǎng)龍網(wǎng)絡控股有限公司 ("網(wǎng)龍"...

關(guān)鍵字: MSC AI 可持續(xù)發(fā)展 網(wǎng)絡游戲

當前,全球半導體競爭日益激烈,作為芯片薄膜沉積工藝的核心耗材,高純度靶材的制造水平直接關(guān)系芯片良率,其技術(shù)攻堅與產(chǎn)能提升面臨嚴峻挑戰(zhàn)。近日,江豐電子在年報中指出,黃湖靶材工廠的建設(shè)穩(wěn)步推進,成為其高標準產(chǎn)能布局的重要一環(huán)...

關(guān)鍵字: 半導體

2026 年 3 月 31 日,華為投資控股有限公司正式發(fā)布 2025 年年度報告。

關(guān)鍵字: 華為 2025年年報 AI 云計算

當?shù)貢r間 3 月 31 日,亞馬遜低軌衛(wèi)星項目Amazon Leo宣布再獲重要突破,正式與美國達美航空達成合作,將為其提供機上高速互聯(lián)網(wǎng)連接服務,標志著亞馬遜正式切入航空互聯(lián)賽道。

關(guān)鍵字: 亞馬遜 Leo 達美航空 Wi-Fi

都柏林, March 30, 2026 (GLOBE NEWSWIRE) -- 隨著企業(yè)在投資者、監(jiān)管機構(gòu)以及 ESG 承諾方面面臨的碳足跡減排壓力日益加大,企業(yè)差旅正成為一個通過微小運營調(diào)整即可產(chǎn)生顯著成效的領(lǐng)域。...

關(guān)鍵字: FOR 數(shù)字化 SI ESIM

當?shù)貢r間 3 月 30 日,專注在軌 AI 數(shù)據(jù)中心建設(shè)的美國初創(chuàng)企業(yè) Starcloud 宣布完成 1.7 億美元融資,投后估值 11 億美元,正式躋身獨角獸行列。

關(guān)鍵字: 太空數(shù)據(jù)中心 Starcloud AI 數(shù)據(jù)中心

March 30, 2026 ---- 根據(jù)TrendForce集邦咨詢最新筆電產(chǎn)業(yè)調(diào)查,近期全球筆電出貨量進一步出現(xiàn)轉(zhuǎn)弱的跡象,TrendForce集邦咨詢在預期終端消費動能趨緩、供應鏈成本持續(xù)墊高的雙重影響下,正式更...

關(guān)鍵字: 筆電 供應鏈 半導體
關(guān)閉