日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 705C】Thor(模拟,STLset优化链表)

發布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 705C】Thor(模拟,STLset优化链表) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are?n?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 first?t?events of the first type). It's guaranteed that there were at least?t?events of the first type before this event. Please note that he doesn't read first?t?unread notifications, he just reads the very first?t?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?and?q?(1?≤?n,?q?≤?300?000)?— the number of applications and the number of events to happen.

    The next?q?lines contain the events. The?i-th of these lines starts with an integer?typei?— type of the?i-th event. If?typei?=?1?or?typei?=?2?then it is followed by an integer?xi. Otherwise it is followed by an integer?ti?(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).
  • 題目大意:

    第一行兩個整數n,m,代表n個軟件,m次操作。(1?≤?n,?q?≤?300?000)?

    接下來m行:
    1 x :軟件 x 產生了一條未讀信息。
    2 x: 軟件 x 的所有信息都被讀了。
    3? t:?前 t 條產生的信息都被讀了。注意是前t條,不是未讀的前t條,已讀的也算在t條中。

    解題報告:

    ? 本來想用個雙向鏈表來啊維護出現過的所有信息,但是發現它可以支持快速的刪除一個元素,但是對于查找前t條信息比較雞肋,甚至還要拿個并查集去搞,比較麻煩,于是換了各項性能都還說的過去的set,直接二分找前t條信息就可以了,這樣最后的答案就是set的大小。

    ?注意不能讓標號直接等于i,因為第i個操作不一定是產生一天新的信息。

    AC代碼:

    #include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 5e5 + 5; int n,m,last,id; set<int> ss[MAX],q;//存鏈表,因為值直接就是索引就可以了,不需要單獨弄鏈表了int main() {cin>>n>>m;for(int op,x,i = 1; i<=m; i++) {scanf("%d%d",&op,&x);if(op == 1) {id++;ss[x].insert(id);q.insert(id);}if(op == 2) {for(auto idx : ss[x]) {if(q.find(idx) != q.end())q.erase(idx);}ss[x].clear();}if(op == 3) {auto upp = q.upper_bound(x),down = q.begin();q.erase(down,upp);last = max(last,x);}printf("%d\n",q.size());}return 0 ; }

    ?

    總結

    以上是生活随笔為你收集整理的【CodeForces - 705C】Thor(模拟,STLset优化链表)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 国产免费av片在线 | 涩涩国产 | 日本不卡一二三区 | 日韩黄色精品视频 | 亚洲成人1区| 操操操日日日 | 激情啪啪网 | 色噜噜狠狠成人中文 | 夜夜嗨老熟女av一区二区三区 | 国产一区二区三区在线视频 | 亚洲一区二区美女 | 免费黄色一级 | 亚洲三级电影网站 | 免费播放毛片精品视频 | 91麻豆国产精品 | 欧洲成人在线观看 | 制服 丝袜 综合 日韩 欧美 | 国产高清视频免费观看 | 婷婷.com| 波多野结衣欧美 | 97超碰人人网 | 亚洲欧美日韩在线 | 国产成人综合av | 久久中文字幕电影 | 91精品久久久久久久 | 2018天天干天天操 | 久久久久久亚洲中文字幕无码 | 国产亚洲在线观看 | 免费黄av | 臭脚猛1s民工调教奴粗口视频 | 99精彩视频 | 伊人草草| 99激情视频| 亚洲乱码国产乱码精品 | 国产尤物在线观看 | 成人图片小说 | 欧美大片免费看 | 最近免费中文字幕 | 91网站在线观看视频 | 高清一区二区在线 | 国产精品免费在线播放 | 丰满人妻一区二区三区在线 | 五月婷六月| 性高跟丝袜xxxxhd | 激情小说中文字幕 | 亚洲综合图色 | 中文字幕观看在线 | 精品成人无码久久久久久 | 欧美性久久 | 香港三日本8a三级少妇三级99 | 精品少妇av | 色婷婷www | 草视频在线 | av先锋资源网 | 伊人影院在线视频 | 日韩欧美一区二区三区久久婷婷 | 亚洲精品免费在线 | 日韩精品久久一区 | 污污的网站在线观看 | 好看的毛片 | 性做久久久久久免费观看 | 在线观看亚洲精品视频 | 中文字幕免费 | 色视频在线观看 | 久久久77 | 国产精品资源 | 日本黄色三级 | 亚洲综合情 | 天天射天天| 古装做爰无遮挡三级视频 | 91国内在线 | 91蜜臀精品国产自偷在线 | 美女久久久久 | 六月丁香婷婷激情 | 精品自拍第一页 | 久久久久网站 | 嫩草在线观看 | 伊人9 | 性饥渴的农村熟妇 | 国产伦精品一区二区三区视频痴汉 | 青青青在线免费观看 | 婷婷五综合| 久久综合久色欧美综合狠狠 | av色播 | sm乳奴虐乳调教bdsm | 91吃瓜在线| 波多野结衣在线一区 | 中文字幕第80页 | 91精品在线免费观看 | 亚洲综合第一页 | 成人一二三四区 | 一区二区免费av | 中文字幕成人 | 久久久久久黄色片 | 色午夜av| 国产一二区在线观看 | 少妇系列在线观看 | 亚洲成人一区二区 | 性欧美free |