0w1

CFR 705 C. Thor ( Ad hoc )

Problem - C - Codeforces
Use set to manage all unread notifications, with amortized complexity, we know that it will be alright because each element will only be inserted and deleted at most once.
And actually set was not needed.

void solve(){
    int N, Q; cin >> N >> Q;
    vector< queue< int > > app( N + 1 );
    set< int > notif;
    int ans = 0;
    int msg_cnt = 0;
    for( int i = 0; i < Q; ++i ){
        int op, x; cin >> op >> x;
        if( op == 1 ){
            app[ x ].push( ++msg_cnt );
            ++ans;
            notif.insert( msg_cnt );
        } else if( op == 2 ){
            while( !app[ x ].empty() ){
                if( notif.count( app[ x ].front() ) )
                    notif.erase( app[ x ].front() ),
                    --ans;
                app[ x ].pop();
            }
        } else{
            for( auto it = notif.begin(); it != notif.end(); ){
                if( *it > x ) break;
                it = notif.erase( it );
                --ans;
            }
        }
        cout << ans << "\n";
    }
}