1292A - NEKO's Maze Game - CodeForces Solution


data structures dsu implementation *1400

Please click on ads to support us..

C++ Code:

#include <bits/stdc++.h>
#define fastio                    \
	ios_base::sync_with_stdio(0); \
	cin.tie(0);
#define vi vector<int>
#define vl vector<long long>
#define vc vector<char>
#define vs vector<string>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define vp vector<pi>
#define vpl vector<pl>
#define ll long long
#define MAX 2147000000
#define MOD 1000000007
using namespace std;

int main(){
	fastio;
    int n, q;
    cin >> n >> q;
    set<int> A, B;
    int cnt{0};
    while(q--){
        int a, b;
        cin >> a >> b;
        if(a == 1){
            if(A.count(b)){
                for(int i{-1}; i <= 1; ++i){
                    if(B.count(b + i)) cnt--;
                }
                A.erase(b);
            }
            else{
                for(int i{-1}; i <= 1; ++i){
                    if(B.count(b + i)) cnt++;
                }
                A.insert(b);
            }
        }   
        else{
            if(B.count(b)){
                for(int i{-1}; i <= 1; ++i){
                    if(A.count(b + i)) cnt--;
                }
                B.erase(b);
            }
            else{
                for(int i{-1}; i <= 1; ++i){
                    if(A.count(b + i)) cnt++;
                }
                B.insert(b);
            }
        }
        if(!B.count(n) && cnt == 0) cout << "Yes\n";
        else cout << "No\n";
    }
}


Comments

Submit
0 Comments
More Questions

729D - Sea Battle
788A - Functions again
1245B - Restricted RPS
1490D - Permutation Transformation
1087B - Div Times Mod
1213B - Bad Prices
1726B - Mainak and Interesting Sequence
1726D - Edge Split
1726C - Jatayu's Balanced Bracket Sequence
1726A - Mainak and Array
1613C - Poisoned Dagger
475B - Strongly Connected City
652B - z-sort
124B - Permutations
1496C - Diamond Miner
680B - Bear and Finding Criminals
1036E - Covered Points
1015D - Walking Between Houses
155B - Combination
1531A - Зингер | color
1678A - Tokitsukaze and All Zero Sequence
896A - Nephren gives a riddle
761A - Dasha and Stairs
1728B - Best Permutation
1728A - Colored Balls Revisited
276B - Little Girl and Game
1181A - Chunga-Changa
1728C - Digital Logarithm
1728D - Letter Picking
792B - Counting-out Rhyme