【CFを打ち、アルゴリズムを学ぶ――三つ星】Codeforces 704 A Thor(シミュレーション)


【CFプロファイル】
テーマリンク:CF 704 A
タイトル:
A.Thor
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
out put
スタンダードアウト
Thor is getting used to t he Earth.As a gift Loki gave him a smart phone.The are e e appication on on on.Thor is fascinated by this phone.He has only one minor issue:he't counit the number of unefitent
q events are about to happen.They are of three types:
  • Appleication x generates a notification(this new notification is unread)
  • Thor reads all notifications generanted so far by appication x(he may re-read some notifications)
  • Thor read s t he first t notifications generant by phone aplications(notifications generst in first t of the first type).It's Garanted that the werst reasthe just reads the very first t notifications generanted on his phone and he may read-read some of the m in this operation
  • Please help Thor and tell him the number of unread notifitications after each event.You may asume that initially there 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 appications and the number of events to happen.
    The next q lineas contain the events.The i-th of these line s starts with an integer typei — type of the i-th event.If typei?=?1or typei?=?2the n it isfollwed byn integaxi. Otherwise it is followwed byn integer ti(1?≦≦_)≦tyi pei____;__;_?_≦̵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
    
    ノート
    In the first sample:
  • Apple 3 generators a notification(there is 1 unread notification)
  • Appleication 1 generates a notification(there re re 2 unread notifications)
  • Apple 2 generators a notification(there re re 3 unread notifications)
  • Thor reads the notification generated by appration 3、there re re re 2 unread notifications left
  • In the second sample test:
  • Appleication 2 generates a notification(there is 1 unread notification)
  • Apple 4 generators a notification(there re re 2 unread notifications)
  • Apple 2 generators a notification(there re re 3 unread notifications)
  • Thor reads first three notifications and since there re only three of them so far、there will beのunread notification left
  • Apple 3 generators a notification(there is 1 unread notification)
  • Apple 3 generators a notification(there re re 2 unread notifications)
  • 件名:
        この問題の背景は携帯アプリで未読メッセージが発生しました.n件のアプリがあります.3つのイベントに対応しています.一、x番のアプリで新しい未読メッセージが発生しました.事件二、雷神はx号アプリの未読情報を全部読みました.事件三、雷神は最初のt条メッセージを読みました.イベントのたびに、現在の未読メッセージ数を出力します.
    問題を解く:
       解法では、データ構造はメッセージリストを使用して、メッセージを記録します.個数配列は、各app未読メッセージ数に対応して、一つのメッセージベクトル配列は、各appが生成したメッセージ記録の下付き、一つのpos配列に対応して、各appが現在最後の情報を処理した後の位置を記録します.一つのsum値は、全未読メッセージ数を記録します.1つのp値は、現在処理されている最後のメッセージ位置を操作することによって記録される.
        1つの動作に対応して、新しいメッセージを生成するごとに、このメッセージの生成app番号を記録するメッセージリストを設計することができ、1つのフラグは、このメッセージがすでに読まれているかどうかを表し、同時に、appに対応する数の配列の数を1つ追加して、このappのベクトル配列は、メッセージの下付きを記録し、未読メッセージの総数に1つを加算する.
        対応する動作2は、このappのpos配列から、このappの最後に処理された未読情報の後の位置を取得し、その後のスキャンを開始し、このメッセージを既読としてマークすることができる.同時に、総未読メッセージ数から減算されたappは未読メッセージ数に対応し、このapp未読メッセージ数をクリアし、最後に未読メッセージを処理した後の位置情報を更新する.
        対応するオペレーション3は、p(現在処理されている最後の位置から処理すれば良い)を開始すると、このプロセスにおいて未読と既読メッセージが発生し、既読のままスキップし、未読の場合は既読としてマークが必要であり、同時に総sum値(未読メッセージ数)が減少し、対応するメッセージ生成appの未読数配列の値も減少する.
       全体の複雑さはO(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];
    vector  v[sz];
    int main()
    {
        int sum=0,n,q,a,b,p=0,cnt=0;
        scanf("%d%d",&n,&q);
        for(int i=0;i