日韩性视频-久久久蜜桃-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优化链表)的全部內容,希望文章能夠幫你解決所遇到的問題。

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