705C - Thor - CodeForces Solution


brute force data structures implementation *1600

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>

#define __gcd() gcd()
#define C int(3e5+7)
#define M int(1e9+7)
#define el '\n'
#define all(a) a.begin(),a.end()

using namespace std;
typedef long long ll;

unordered_map<int,set<int> > mp;//value,idxs of this value
vector< array<int,2> > org;//id,value
int check[C];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
//    freopen("convention2.in","r",stdin);
//    freopen("convention2.out","w",stdout);

    int n,m;
    cin>>n>>m;
    org.push_back({0,0});
    int cur_id = 1,cur_noti = 0;
    for(int i=1;i <= m;i++){
        int t,x;
        cin>>t>>x;
        if(t == 1){
            mp[x].insert(i);
            org.push_back({i,x});
            cur_noti++;
        }
        else if(t == 2){
            for(auto it:mp[x]){
                if(!check[it]){
                    cur_noti--;
                    check[it] = 1;
                }
            }
            mp[x].clear();
        }
        else {
            for(int k = cur_id; k <= x; k++){
                if(!check[org[k][0]]){
                    cur_noti--;
                    mp[org[k][1]].erase(org[k][0]);
                    check[org[k][0]] = 1;
                }
            }
            cur_id = max(cur_id,x + 1);
        }
        cout<<cur_noti<<el;
    }
}


Comments

Submit
0 Comments
More Questions

292B - Network Topology
1339A - Filling Diamonds
910A - The Way to Home
617A - Elephant
48A - Rock-paper-scissors
294A - Shaass and Oskols
1213A - Chips Moving
490A - Team Olympiad
233A - Perfect Permutation
1360A - Minimal Square
467A - George and Accommodation
893C - Rumor
227B - Effective Approach
1534B - Histogram Ugliness
1611B - Team Composition Programmers and Mathematicians
110A - Nearly Lucky Number
1220B - Multiplication Table
1644A - Doors and Keys
1644B - Anti-Fibonacci Permutation
1610A - Anti Light's Cell Guessing
349B - Color the Fence
144A - Arrival of the General
1106A - Lunar New Year and Cross Counting
58A - Chat room
230A - Dragons
200B - Drinks
13A - Numbers
129A - Cookies
1367B - Even Array
136A - Presents