text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
int gcd__(int a, int b) {
if (a == 0) return b;
return gcd__(b % a, a);
}
int main() {
std::ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
t = 1;
while (t--) {
int n, m;
cin >> n >> m;
int arr[2][n];
memset(arr, 0, sizeof(arr));
int blockedPair = 0;
while (m--) {
int x, y;
cin >> x >> y;
x--;
y--;
int del = (arr[x][y] == 0) ? +1 : -1;
arr[x][y] = (arr[x][y] ^ 1);
for (int dy = -1; dy <= 1; dy++) {
if (y + dy < 0 || y + dy >= n) continue;
if (arr[1 - x][y + dy] == 1) {
blockedPair += del;
}
}
cout << ((blockedPair == 0) ? "Yes\n" : "No\n");
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e9 + 7;
int32_t main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
;
long long n, q;
cin >> n >> q;
long long arr[3][n + 2];
for (long long i = 1; i <= 2; i++) {
for (long long j = 0; j <= n + 1; j++) arr[i][j] = 0;
}
long long cnt = 0;
while (q--) {
long long r, c;
cin >> r >> c;
if (arr[r][c] == 1) {
if (r == 1) {
if (arr[2][c] == 1) cnt--;
if (arr[2][c + 1] == 1) cnt--;
if (arr[2][c - 1] == 1) cnt--;
} else {
if (arr[1][c] == 1) cnt--;
if (arr[1][c + 1] == 1) cnt--;
if (arr[1][c - 1] == 1) cnt--;
}
arr[r][c] = 0;
} else {
if (r == 1) {
if (arr[2][c] == 1) cnt++;
if (arr[2][c + 1] == 1) cnt++;
if (arr[2][c - 1] == 1) cnt++;
} else {
if (arr[1][c] == 1) cnt++;
if (arr[1][c + 1] == 1) cnt++;
if (arr[1][c - 1] == 1) cnt++;
}
arr[r][c] = 1;
}
if (cnt == 0)
cout << "Yes\n";
else
cout << "No\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, q;
int maze[3][100005];
int conf;
void helper(int x, int y) {
int mark = maze[x][y] ? -1 : 1;
conf += mark * (maze[3 - x][y - 1] + maze[3 - x][y] + maze[3 - x][y + 1]);
maze[x][y] ^= 1;
}
int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n >> q;
while (q--) {
int x, y;
cin >> x >> y;
helper(x, y);
cout << (conf ? "No" : "Yes") << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int maxn = 2e5 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int main() {
ios_base::sync_with_stdio(false), cin.tie(0);
int n, q;
cin >> n >> q;
vector<vector<int> > vis(3, vector<int>(n + 1, 0));
int cnt = 0;
while (q--) {
int first, second;
cin >> first >> second;
int delta = 0;
for (int yy = second - 1; yy <= second + 1; yy++) {
if (yy < 1 || yy > n) continue;
if (vis[3 - first][yy]) ++delta;
}
vis[first][second] ^= 1;
if (vis[first][second] == 1)
cnt += delta;
else
cnt -= delta;
cout << (cnt == 0 ? "YES\n" : "NO\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int vis[3][maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
int count = 0;
for (int i = 1; i <= q; i++) {
int a, b;
cin >> a >> b;
vis[a][b] ^= 1;
if (vis[a][b]) {
if (a == 1) {
if (vis[a + 1][b]) count++;
if (b + 1 <= n && vis[a + 1][b + 1]) count++;
if (b - 1 >= 1 && vis[a + 1][b - 1]) count++;
} else if (a == 2) {
if (vis[a - 1][b]) count++;
if (b + 1 <= n && vis[a - 1][b + 1]) count++;
if (b - 1 >= 1 && vis[a - 1][b - 1]) count++;
}
} else {
if (a == 1) {
if (vis[a + 1][b]) count--;
if (vis[a + 1][b + 1]) count--;
if (vis[a + 1][b - 1]) count--;
} else {
if (vis[a - 1][b]) count--;
if (vis[a - 1][b + 1]) count--;
if (vis[a - 1][b - 1]) count--;
}
}
if (!count)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
int n, q;
vector<vector<int>> lava;
void Input() {
cin >> n >> q;
lava.resize(2, vector<int>(n, 0));
}
void Solve() {
int blockedPair = 0;
while (q--) {
int x, y;
cin >> x >> y;
x--;
y--;
int delta = (lava[x][y] == 0) ? +1 : -1;
lava[x][y] = 1 - lava[x][y];
for (int dy = -1; dy <= 1; dy++) {
if (y + dy < 0 || y + dy >= n) continue;
if (lava[1 - x][y + dy] == 1) blockedPair += delta;
}
cout << ((blockedPair == 0) ? "Yes\n" : "No\n");
}
}
int main(int argc, char* argv[]) {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
Input();
Solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool comp(long long a, long long b) { return (a < b); }
void solve();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
solve();
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs"
<< "\n";
return 0;
}
void solve() {
int n, q;
cin >> n >> q;
map<pair<int, int>, int> mp;
int blocks = 0;
while (q--) {
int x, y;
cin >> x >> y;
x--, y--;
int add = 0, l = 0;
mp[make_pair(x, y)]++;
if (mp[make_pair(x, y)] % 2 == 1) {
add = 1;
} else {
add = -1;
}
if (x == 0) {
if (mp[make_pair(1, y)] % 2 == 1) {
blocks += add;
}
if (mp[make_pair(1, y - 1)] % 2 == 1) {
blocks += add;
}
if (mp[make_pair(1, y + 1)] % 2 == 1 && y + 1 < n) {
blocks += add;
}
}
if (x == 1) {
if (mp[make_pair(0, y)] % 2 == 1) {
blocks += add;
}
if (mp[make_pair(0, y + 1)] % 2 == 1) {
blocks += add;
}
if (mp[make_pair(0, y - 1)] % 2 == 1 && y - 1 >= 0) {
blocks += add;
}
}
if (blocks >= 1) {
cout << "No\n";
} else {
cout << "Yes"
<< "\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
cin >> n >> q;
bool lava[3][n + 2];
memset(lava, false, sizeof lava);
set<int> s;
lava[2][0] = 1;
lava[1][n + 1] = 1;
while (q--) {
int x, y;
cin >> x >> y;
lava[x][y] = lava[x][y] ^ 1;
if ((lava[1][y] || lava[1][y - 1]) && (lava[2][y] || lava[2][y - 1]))
s.insert(y);
if ((lava[1][y] || lava[1][y + 1]) && (lava[2][y] || lava[2][y + 1]))
s.insert(y + 1);
if (!(lava[1][y] || lava[1][y - 1]) || !(lava[2][y] || lava[2][y - 1])) {
if (s.count(y)) s.erase(y);
}
if (!(lava[1][y] || lava[1][y + 1]) || !(lava[2][y] || lava[2][y + 1])) {
if (s.count(y + 1)) s.erase(y + 1);
}
if (s.size() == 0)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
set<pair<int, int> > s;
long long cnt = 0;
for (int i = 0; i < int(q); i++) {
int x, y;
cin >> x >> y;
if (s.count(make_pair(x, y))) {
int dx = 3 - x;
for (int k = int(-1); k <= int(1); k++)
if (s.count({dx, y - k})) cnt--;
s.erase(make_pair(x, y));
} else {
int dx = 3 - x;
for (int k = int(-1); k <= int(1); k++)
if (s.count({dx, y - k})) cnt++;
s.insert(make_pair(x, y));
}
if (cnt == 0)
cout << "Yes" << '\n';
else
cout << "No" << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INT_INF = (int)(2e9);
const ll LL_INF = (ll)(2e18);
const int NIL = -1;
static mt19937 _g(time(nullptr));
inline ll randint(ll a, ll b) {
ll w = (_g() << 31LL) ^ _g();
return a + w % (b - a + 1);
}
inline void fast_io() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
};
template <typename T>
inline T sign(T x) {
return T(x > 0) - T(x < 0);
}
template <typename T, typename S>
inline ostream& operator<<(ostream& os, const pair<T, S> p) {
cout << "[" << p.first << ";" << p.second << "]";
return os;
}
template <typename T>
inline ostream& operator<<(ostream& os, const vector<T>& v) {
for (auto el : v) cout << el << " ";
return os;
}
template <typename T>
inline T fetch() {
T ret;
cin >> ret;
return ret;
}
template <typename T>
inline vector<T> fetch_vec(int sz) {
vector<T> ret(sz);
for (auto& elem : ret) cin >> elem;
return ret;
}
const int MAXN = (int)1e5 + 7;
int a[2][MAXN];
int n, q;
int cnt = 0;
void upd(int c, int s) {
int dlt = 0;
for (int j = max(0, c - 3); j <= min(n - 1, c + 3); ++j) {
dlt += a[0][j] && a[1][j];
if (j != 0) {
dlt += a[0][j - 1] && a[1][j];
dlt += a[0][j] && a[1][j - 1];
}
}
cnt += dlt * s;
}
void solve() {
cin >> n >> q;
while (q--) {
int r = fetch<int>() - 1;
int c = fetch<int>() - 1;
upd(c, -1);
a[r][c] ^= 1;
upd(c, +1);
cout << (cnt > 0 ? "No\n" : "Yes\n");
}
}
int main() {
fast_io();
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool a[2][100010];
int main() {
int n, q;
cin >> n >> q;
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) a[i][j] = false;
}
long long res = 0;
for (int i = 0; i < q; i++) {
int r, c;
cin >> r >> c;
r--;
c--;
if (!a[r][c]) {
a[r][c] = true;
if (r == 0) {
if (a[r + 1][c]) res++;
if (c != n - 1 && a[r + 1][c + 1]) res++;
if (c != 0 && a[r + 1][c - 1]) res++;
} else {
if (a[r - 1][c]) res++;
if (c != n - 1 && a[r - 1][c + 1]) res++;
if (c != 0 && a[r - 1][c - 1]) res++;
}
} else {
a[r][c] = false;
if (r == 0) {
if (a[r + 1][c]) res--;
if (c != n - 1 && a[r + 1][c + 1]) res--;
if (c != 0 && a[r + 1][c - 1]) res--;
} else {
if (a[r - 1][c]) res--;
if (c != n - 1 && a[r - 1][c + 1]) res--;
if (c != 0 && a[r - 1][c - 1]) res--;
}
}
if (res == 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long c[3][100005], a1[100005], a2[100005], a3[100005];
long long calc[100005];
long long solve() {
long long n, q;
cin >> n >> q;
long long debris = 0;
while (q--) {
long long t1, t2;
cin >> t1 >> t2;
if (c[t1][t2]) {
if (t1 == 1) {
if (c[1][t2] && c[2][t2]) debris--;
if (c[1][t2] && c[2][t2 + 1] && t2 + 1 <= n) debris--;
if (c[1][t2] && c[2][t2 - 1] && t2 - 1 >= 1) debris--;
} else {
if (c[2][t2] && c[1][t2]) debris--;
if (c[2][t2] && c[1][t2 + 1] && t2 + 1 <= n) debris--;
if (c[2][t2] && c[1][t2 - 1] && t2 - 1 >= 1) debris--;
}
c[t1][t2] = 0;
} else {
c[t1][t2] = 1;
if (t1 == 1) {
if (c[1][t2] && c[2][t2]) debris++;
if (c[1][t2] && c[2][t2 + 1] && t2 + 1 <= n) debris++;
if (c[1][t2] && c[2][t2 - 1] && t2 - 1 >= 1) debris++;
} else {
if (c[2][t2] && c[1][t2]) debris++;
if (c[2][t2] && c[1][t2 + 1] && t2 + 1 <= n) debris++;
if (c[2][t2] && c[1][t2 - 1] && t2 - 1 >= 1) debris++;
}
}
if (!debris)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
signed main() {
ios::sync_with_stdio(0);
long long t = 1;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
map<pair<int, int>, int> bio;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
pair<int, int> p;
int br = 0;
for (int i = 0; i < q; i++) {
cin >> p.first >> p.second;
p.first--;
p.second--;
if (bio[p]) {
bio[p] = 0;
if (p.first == 0) {
br -= bio[{p.first + 1, p.second}] + bio[{p.first + 1, p.second + 1}] +
bio[{p.first + 1, p.second - 1}];
} else {
br -= bio[{p.first - 1, p.second}] + bio[{p.first - 1, p.second + 1}] +
bio[{p.first - 1, p.second - 1}];
}
} else {
bio[p] = 1;
if (p.first == 0) {
br += bio[{p.first + 1, p.second}] + bio[{p.first + 1, p.second + 1}] +
bio[{p.first + 1, p.second - 1}];
} else {
br += bio[{p.first - 1, p.second}] + bio[{p.first - 1, p.second + 1}] +
bio[{p.first - 1, p.second - 1}];
}
}
if (!br) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
map<pair<int, int>, int> m1;
map<int, int> m2, m3, m4;
int col_block = 0;
int diagnol_block = 0;
for (int i = 0; i < q; i++) {
int u, v;
cin >> u >> v;
if (m1[{u, v}] == 1) {
m1[{u, v}] = 0;
m2[u + v]--;
if (m2[u + v] == 1) {
diagnol_block--;
}
m3[v]--;
if (m3[v] == 1) {
col_block--;
}
if (u == 1) {
if (m1[{u + 1, v + 1}] == 1) {
diagnol_block--;
}
} else {
if (m1[{u - 1, v - 1}] == 1) {
diagnol_block--;
}
}
} else {
m1[{u, v}]++;
m2[u + v]++;
if (m2[u + v] == 2) {
diagnol_block++;
}
m3[v]++;
if (m3[v] == 2) {
col_block++;
}
if (u == 1) {
if (m1[{u + 1, v + 1}] == 1) {
diagnol_block++;
}
} else {
if (m1[{u - 1, v - 1}] == 1) {
diagnol_block++;
}
}
}
if (col_block || diagnol_block) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return (b ? gcd(b, a % b) : a); }
bool isPrime(long long n) {
if (n == 1) return false;
if (n == 2) return true;
for (long long i = 2; i * i <= n; i++) {
if (n % i == 0) return false;
}
return true;
}
void solve() {
long long n;
cin >> n;
long long q;
cin >> q;
long long v[4][n + 4];
for (long long i = 0; i < n + 2; i++) {
v[0][i] = 0;
v[1][i] = 0;
v[2][i] = 0;
v[3][i] = 0;
}
long long blockage = 0;
while (q--) {
long long a;
cin >> a;
long long b;
cin >> b;
if (v[a][b]) {
v[a][b] = 0;
blockage -= (v[a - 1][b - 1] > 0) + (v[a - 1][b] > 0) +
(v[a - 1][b + 1] > 0) + (v[a + 1][b - 1] > 0) +
(v[a + 1][b] > 0) + (v[a + 1][b + 1] > 0);
} else {
v[a][b] = 1;
blockage += (v[a - 1][b - 1] > 0) + (v[a - 1][b] > 0) +
(v[a - 1][b + 1] > 0) + (v[a + 1][b - 1] > 0) +
(v[a + 1][b] > 0) + (v[a + 1][b + 1] > 0);
}
cout << (blockage == 0 && !v[2][n] ? "Yes" : "No") << endl;
;
}
}
int32_t main() {
ios_base ::sync_with_stdio(false), cin.tie(NULL);
long long t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7, inf = 1061109567;
const long long infll = 4557430888798830399;
const int N = 1e5 + 5;
int n, q, a[N];
set<int> bad;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
for (int i = 0; i < n; i++) a[i] = 3;
while (q--) {
int r, c;
cin >> r >> c;
r--, c--;
int prvc = a[c];
a[c] ^= (1 << r);
if (c) {
if ((a[c] & a[c - 1]) == 0)
bad.insert(c - 1);
else if ((prvc & a[c - 1]) == 0)
bad.erase(c - 1);
}
if (c < n - 1) {
if ((a[c] & a[c + 1]) == 0)
bad.insert(c);
else if ((prvc & a[c + 1]) == 0)
bad.erase(c);
}
if (bad.size())
cout << "No\n";
else
cout << "Yes\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, q, bk = 0;
vector<vector<int>> v;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q;
v.assign(2, vector<int>(n, 0));
for (int i = 0; i < q; ++i) {
int r, c;
cin >> r >> c;
r--;
c--;
if (v[r][c] == 0) {
for (int j = 0; j < 3; ++j) {
if (c - 1 + j >= 0 && c - 1 + j < n && v[1 ^ r][c - 1 + j] == 1) {
bk++;
}
}
v[r][c] = 1;
} else {
for (int j = 0; j < 3; ++j) {
if (c - 1 + j >= 0 && c - 1 + j < n && v[1 ^ r][c - 1 + j] == 1) {
bk--;
}
}
v[r][c] = 0;
}
cout << (bk ? "No" : "Yes") << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
scanf("%d%d", &n, &q);
set<pair<int, int>> cells;
int bad_nei = 0;
for (int i = 0; i < q; i++) {
int row, col;
scanf("%d%d", &row, &col);
bool was_forbidden = cells.count({row, col});
for (int r = row - 1; r <= row + 1; r++) {
for (int c = col - 1; c <= col + 1; c++) {
if (r == row) {
continue;
}
if (!(1 <= r && r <= 2 && 1 <= c && c <= n)) {
continue;
}
if (cells.count({r, c})) {
if (was_forbidden) {
bad_nei--;
} else {
bad_nei++;
}
}
}
}
if (cells.count({row, col})) {
cells.erase({row, col});
} else {
cells.insert({row, col});
}
if (bad_nei >= 1) {
puts("NO");
} else {
puts("YES");
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q, r, c;
cin >> n >> q;
vector<vector<int>> a(2, vector<int>(n, 1));
vector<string> pass(q);
set<pair<pair<int, int>, pair<int, int>>> count;
for (int o = 0; o < q; o++) {
cin >> r >> c;
r--;
c--;
a[r][c] *= -1;
if (a[r][c] == -1) {
if (r == 1) {
if (c - 1 >= 0 && a[0][c - 1] == -1) {
count.insert({{0, c - 1}, {r, c}});
count.insert({{r, c}, {0, c - 1}});
}
if (a[0][c] == -1) {
count.insert({{0, c}, {r, c}});
count.insert({{r, c}, {0, c}});
}
if (c + 1 < n && a[0][c + 1] == -1) {
count.insert({{0, c + 1}, {r, c}});
count.insert({{r, c}, {0, c + 1}});
}
} else {
if (c - 1 >= 0 && a[1][c - 1] == -1) {
count.insert({{1, c - 1}, {r, c}});
count.insert({{r, c}, {1, c - 1}});
}
if (a[1][c] == -1) {
count.insert({{1, c}, {r, c}});
count.insert({{r, c}, {1, c}});
}
if (c + 1 < n && a[1][c + 1] == -1) {
count.insert({{1, c + 1}, {r, c}});
count.insert({{r, c}, {1, c + 1}});
}
}
} else {
if (!count.empty()) {
if (r == 1) {
if (c - 1 >= 0 && count.find({{0, c - 1}, {r, c}}) != count.end()) {
count.erase({{0, c - 1}, {r, c}});
count.erase({{r, c}, {0, c - 1}});
}
if (count.find({{0, c}, {r, c}}) != count.end()) {
count.erase({{0, c}, {r, c}});
count.erase({{r, c}, {0, c}});
}
if (c + 1 < n && count.find({{0, c + 1}, {r, c}}) != count.end()) {
count.erase({{0, c + 1}, {r, c}});
count.erase({{r, c}, {0, c + 1}});
}
} else {
if (c - 1 >= 0 && count.find({{1, c - 1}, {r, c}}) != count.end()) {
count.erase({{1, c - 1}, {r, c}});
count.erase({{r, c}, {1, c - 1}});
}
if (count.find({{1, c}, {r, c}}) != count.end()) {
count.erase({{1, c}, {r, c}});
count.erase({{r, c}, {1, c}});
}
if (c + 1 < n && count.find({{1, c + 1}, {r, c}}) != count.end()) {
count.erase({{1, c + 1}, {r, c}});
count.erase({{r, c}, {1, c + 1}});
}
}
}
}
if (count.empty())
pass[o] = "Yes";
else
pass[o] = "No";
}
for (int i = 0; i < q; i++) {
cout << pass[i] << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long N = 1001;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
int n, q;
cin >> n >> q;
vector<vector<bool>> free(2, vector<bool>(n, true));
set<pair<pair<int, int>, pair<int, int>>> blocks;
while (q--) {
int r, c;
cin >> r >> c;
r--, c--;
if (free[r][c]) {
for (int i = -1; i < 2; i++) {
if (c + i < n and c + i >= 0 and !free[1 - r][c + i]) {
blocks.insert({{r, c}, {1 - r, c + i}});
blocks.insert({{1 - r, c + i}, {r, c}});
}
}
free[r][c] = false;
} else {
for (int i = -1; i < 2; i++) {
if (c + i < n and c + i >= 0 and !free[1 - r][c + i]) {
blocks.erase({{r, c}, {1 - r, c + i}});
blocks.erase({{1 - r, c + i}, {r, c}});
}
}
free[r][c] = true;
}
cout << ((int)blocks.size() ? "no" : "yes") << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
bool v[5][N];
int main() {
int n, m, nr = 0;
cin >> n >> m;
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
if (!v[x][y]) {
v[x][y] = 1;
if (v[x - 1][y] || v[x + 1][y]) nr++;
if (v[x - 1][y + 1] || v[x + 1][y + 1]) nr++;
if (v[x - 1][y - 1] || v[x + 1][y - 1]) nr++;
} else {
v[x][y] = 0;
if (v[x - 1][y] || v[x + 1][y]) nr--;
if (v[x - 1][y + 1] || v[x + 1][y + 1]) nr--;
if (v[x - 1][y - 1] || v[x + 1][y - 1]) nr--;
}
if (!nr)
cout << "Yes\n";
else
cout << "No\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const double pi = 3.14159265358979323846;
void cp() {}
void solve() {
long long n, m;
cin >> n >> m;
long long a[2][n];
memset(a, 0, sizeof(a));
long long flag = 0;
for (int i = 1; i <= m; i++) {
long long x, y;
cin >> x >> y;
long long cur;
x--;
y--;
cur = (a[x][y] == 0 ? 1 : -1);
a[x][y] ^= 1;
for (int j = -1; j <= 1; j++) {
if (j + y < 0 or j + y > n) continue;
if (a[1 - x][j + y] == 1) flag += cur;
}
if (flag > 0)
cout << "NO\n";
else
cout << "YES\n";
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
long long t = 1;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
inline int read() {
int x = 0, f = 1;
char c = getchar();
while (c < '0' || c > '9') {
if (c == '-') f = -1;
c = getchar();
}
while (c >= '0' && c <= '9') {
x = (x << 3) + (x << 1) + c - '0';
c = getchar();
}
return x * f;
}
int n, Q, mp[2][100010], cnt;
int main() {
n = read(), Q = read();
while (Q--) {
int x = read() - 1, y = read();
mp[x][y] ^= 1;
if (mp[x][y]) {
cnt += mp[x ^ 1][y] + mp[x ^ 1][y - 1] + mp[x ^ 1][y + 1];
} else {
cnt -= mp[x ^ 1][y] + mp[x ^ 1][y - 1] + mp[x ^ 1][y + 1];
}
if (!cnt) {
printf("YES\n");
} else {
printf("NO\n");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int board[3][100000 + 5];
int dy[3] = {-1, 0, 1};
int main() {
memset(board, 0, sizeof(board));
int n, q, fail = 0;
scanf("%d%d", &n, &q);
for (int i = 0; i < q; i++) {
int x, y;
scanf("%d%d", &x, &y);
int pos = 3 - x;
board[x][y] = 1 - board[x][y];
for (int i = 0; i < 3; i++) {
if ((y + dy[i] >= 1 && y + dy[i] <= n)) {
if (board[x][y] == 0) {
if (board[pos][y + dy[i]] == 1) fail--;
} else {
if (board[pos][y + dy[i]] == 1) fail++;
}
}
}
if (fail == 0) {
printf("Yes\n");
} else {
printf("No\n");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
int a[3][n + 1];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n + 1; j++) {
a[i][j] = 0;
}
}
int noOfPairs = 0;
while (q--) {
int x, y;
cin >> x >> y;
a[x][y] = a[x][y] ^ 1;
if (y - 1 > 0) {
if (a[3 - x][y - 1] == 1 && a[x][y] == 1) {
noOfPairs++;
} else if (a[3 - x][y - 1] == 1)
noOfPairs--;
}
if (a[3 - x][y] == 1 && a[x][y] == 1) {
noOfPairs++;
} else if (a[3 - x][y] == 1)
noOfPairs--;
if (y + 1 < n + 1) {
if (a[3 - x][y + 1] == 1 && a[x][y] == 1) {
noOfPairs++;
} else if (a[3 - x][y + 1] == 1)
noOfPairs--;
}
if (noOfPairs > 0)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int ara[2][100000];
int main() {
int i, j, k;
int n, q;
int obs = 0;
scanf("%d %d", &n, &q);
for (i = 0; i < q; i++) {
scanf("%d %d", &j, &k);
j--;
k--;
ara[j][k] = !ara[j][k];
if (ara[j][k] == 0) {
if (j == 0) {
if (ara[1][k]) obs++;
if (k < n - 1 && ara[1][k + 1]) obs++;
if (k > 0 && ara[1][k - 1]) obs++;
} else {
if (ara[0][k]) obs++;
if (k < n - 1 && ara[0][k + 1]) obs++;
if (k > 0 && ara[0][k - 1]) obs++;
}
} else {
if (j == 0) {
if (ara[1][k]) obs--;
if (k < n - 1 && ara[1][k + 1]) obs--;
if (k > 0 && ara[1][k - 1]) obs--;
} else {
if (ara[0][k]) obs--;
if (k < n - 1 && ara[0][k + 1]) obs--;
if (k > 0 && ara[0][k - 1]) obs--;
}
}
if (obs == 0)
printf("Yes\n");
else
printf("No\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q, cant = 0, r, c, x, y;
cin >> n >> q;
bool** cells = new bool*[2];
for (int i = 0; i < 2; i++) cells[i] = new bool[n]();
for (int i = 0; i < q; i++) {
cin >> r >> c;
r--, c--;
if (r == 0)
x = 1;
else
x = 0;
if (!cells[r][c]) {
cells[r][c] = 1;
if (cells[x][c]) cant++;
if (c > 0 && cells[x][c - 1]) cant++;
if (c < n - 1 && cells[x][c + 1]) cant++;
} else {
cells[r][c] = 0;
if (cells[x][c]) cant--;
if (c > 0 && cells[x][c - 1]) cant--;
if (c < n - 1 && cells[x][c + 1]) cant--;
}
if (cant)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long ans = 0, r, d, a, pos, b, i, n, k, m, t, tot = 0, c = 0, s = 0, t1,
c1 = 0, k4 = 0, c2 = 0, j = 0, k1, k2, k3;
char ch;
string s1;
ios::sync_with_stdio(0);
cin.tie(0);
t = 1;
cin >> n >> t;
vector<long long> v(n);
long long a1[2][200010] = {0};
c = 0;
while (t--) {
cin >> a >> b;
a--;
b--;
if (a1[a][b])
d = -1;
else
d = 1;
a1[a][b] = 1 - a1[a][b];
for (i = -1; i <= 1; i++) {
if (b + i < 0 || b + i > n - 1) continue;
if (a1[1 - a][b + i] == 1) c += d;
}
if (c == 0)
cout << "Yes"
<< "\n";
else
cout << "No"
<< "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool maze[3][100001];
int judge(int r, int c) {
if (r == 1) {
if (c == 100000) return maze[2][c - 1] + maze[2][c];
return maze[2][c - 1] + maze[2][c] + maze[2][c + 1];
} else {
if (c == 1) return maze[1][1] + maze[1][2];
if (c == 100000) return maze[1][c - 1] + maze[1][c];
return maze[1][c - 1] + maze[1][c] + maze[1][c + 1];
}
}
int main() {
memset(maze, 0, sizeof(maze));
int n, q, cont = 0, r, c;
cin >> n >> q;
for (int i = 1; i <= q; i++) {
cin >> r >> c;
if (maze[r][c] == 0) {
maze[r][c] = 1;
cont += judge(r, c);
} else {
maze[r][c] = 0;
cont -= judge(r, c);
}
cout << (cont == 0 ? "Yes" : "No") << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, t, counterof = 0;
cin >> n >> t;
bool arr[3][n + 1];
bool visited[n + 1];
int dx[] = {-1, 0, 1};
memset(arr, 0, sizeof arr);
memset(visited, 0, sizeof visited);
for (int i = 0; i < t; i++) {
int row, col;
cin >> row >> col;
arr[row][col] = !arr[row][col];
if (arr[row][col] == 1) {
if (row == 1) {
for (int j = 0; j < 3; j++) {
if (dx[j] + col > n || dx[j] + col < 1) {
continue;
}
if (arr[2][dx[j] + col]) {
counterof++;
}
}
} else {
for (int j = 0; j < 3; j++) {
if (dx[j] + col > n || dx[j] + col < 1) {
continue;
}
if (arr[1][dx[j] + col]) {
counterof++;
}
}
}
} else {
if (row == 1) {
for (int j = 0; j < 3; j++) {
if (dx[j] + col > n || dx[j] + col < 1) {
continue;
}
if (arr[2][dx[j] + col]) {
counterof--;
}
}
} else {
for (int j = 0; j < 3; j++) {
if (dx[j] + col > n || dx[j] + col < 1) {
continue;
}
if (arr[1][dx[j] + col]) {
counterof--;
}
}
}
}
if (counterof) {
cout << "No\n";
} else {
cout << "Yes\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1000 * 100 + 3;
int n, q;
set<pair<int, int>> s;
set<pair<pair<int, int>, pair<int, int>>> x;
void up(int a, int b) {
bool res = true;
s.insert({a, b});
if (a == 1) {
for (int i = -1; i < 2; i++)
if (s.count({a + 1, b + i})) {
x.insert({{a + 1, b + i}, {a, b}});
x.insert({{a, b}, {a + 1, b + i}});
}
}
if (a == 2) {
for (int i = -1; i < 2; i++)
if (s.count({a - 1, b + i})) {
x.insert({{a - 1, b + i}, {a, b}});
x.insert({{a, b}, {a - 1, b + i}});
}
}
}
void get(int a, int b) {
bool res = false;
s.erase({a, b});
if (a == 1) {
for (int i = -1; i < 2; i++)
if (s.count({a + 1, b + i})) {
x.erase({{a, b}, {a + 1, b + i}});
x.erase({{a + 1, b + i}, {a, b}});
}
}
if (a == 2) {
for (int i = -1; i < 2; i++)
if (s.count({a - 1, b + i})) {
x.erase({{a, b}, {a - 1, b + i}});
x.erase({{a - 1, b + i}, {a, b}});
}
}
}
void solve() {
int q;
cin >> q;
while (q--) {
int a, b;
cin >> a >> b;
if (s.count({a, b}) == false)
up(a, b);
else
get(a, b);
cout << (x.size() ? "No\n" : "Yes\n");
}
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
cin >> n;
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool maze[3][100001];
int judge(int r, int c) {
if (r == 1) {
if (c == 100000) return maze[2][99999] + maze[2][100000];
return maze[2][c - 1] + maze[2][c] + maze[2][c + 1];
} else {
if (c == 1) return maze[1][1] + maze[1][2];
if (c == 100000) return maze[1][c - 1] + maze[1][c];
return maze[1][c - 1] + maze[1][c] + maze[1][c + 1];
}
}
int main() {
memset(maze, 0, sizeof(maze));
int n, q, cont = 0, r, c;
cin >> n >> q;
for (int i = 1; i <= q; i++) {
cin >> r >> c;
if (maze[r][c] == 0) {
maze[r][c] = 1;
cont += judge(r, c);
} else {
maze[r][c] = 0;
cont -= judge(r, c);
}
cout << (cont == 0 ? "Yes" : "No") << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
constexpr int kN = int(2E5 + 10);
vector<pair<int, int>> graph[3][kN];
bool have[3][kN];
int main() {
int n, q, x, y, cnt = 0;
scanf("%d%d", &n, &q);
for (int i = 1; i <= n; i++) {
graph[1][i].push_back({2, i});
graph[2][i].push_back({1, i});
if (i != 1) {
graph[1][i].push_back({2, i - 1});
graph[2][i - 1].push_back({1, i});
}
if (i != n) {
graph[1][i].push_back({2, i + 1});
graph[2][i + 1].push_back({1, i});
}
}
for (int i = 1; i <= q; i++) {
scanf("%d%d", &x, &y);
if (have[x][y]) {
have[x][y] = false;
for (pair<int, int> j : graph[x][y])
if (have[j.first][j.second]) cnt--;
} else {
have[x][y] = true;
for (pair<int, int> j : graph[x][y])
if (have[j.first][j.second]) cnt++;
}
if (cnt)
printf("No\n");
else
printf("Yes\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
void mult(vector<vector<long long>> a, vector<vector<long long>> b, long long n,
long long k, long long m, vector<vector<long long>>& ans) {
for (long long i = 0; i < n; i++) {
for (long long j = 0; j < m; j++) {
ans[i][j] = 0;
for (long long l = 0; l < k; l++)
ans[i][j] = (ans[i][j] + a[i][l] * b[l][j]) % mod;
}
}
}
vector<vector<long long>> matpower(vector<vector<long long>> a, long long n,
long long x) {
vector<vector<long long>> ans(n, vector<long long>(n, 0));
for (long long i = 0; i < n; i++) ans[i][i] = 1;
while (x > 0) {
if (x % 2) mult(ans, a, n, n, n, ans);
mult(a, a, n, n, n, a);
x /= 2;
}
return ans;
}
vector<long long> parent, siz;
long long par(long long x) {
if (parent[x] == x) return x;
return parent[x] = par(parent[x]);
}
void unionxy(long long x, long long y) {
long long px = par(x), py = par(y);
if (px == py) return;
if (siz[px] > siz[py]) swap(px, py);
parent[px] = py;
siz[py] += siz[px];
}
void abcd() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, q;
cin >> n >> q;
vector<vector<bool>> check(3, vector<bool>(n + 1, 0));
long long bad = 0;
while (q--) {
long long r, c;
cin >> r >> c;
long long i = r == 1 ? 2 : 1;
for (long long j = c - 1; j <= c + 1; j++) {
if (j <= 0 or j > n) continue;
if (check[i][j]) {
if (check[r][c])
bad--;
else
bad++;
}
}
if (bad <= 0)
cout << "Yes";
else
cout << "No";
cout << endl;
check[r][c] = !check[r][c];
}
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
abcd();
cout << endl;
}
|
#include <bits/stdc++.h>
using namespace std;
void fast() {
ios::sync_with_stdio(NULL);
cin.tie(NULL);
cout.tie(NULL);
}
const int N = 2e5 + 2;
int n, q;
int x, y, flag;
void solve() {
cin >> n >> q;
vector<vector<bool>> matrix(2, vector<bool>(n + 2, 0));
while (q--) {
cin >> x >> y;
int X = x - 1;
if (x == 2) x = 0;
if (!matrix[X][y]) {
flag += (matrix[x][y - 1] + matrix[x][y] + matrix[x][y + 1]);
matrix[X][y] = 1;
} else {
flag -= (matrix[x][y - 1] + matrix[x][y] + matrix[x][y + 1]);
matrix[X][y] = 0;
}
if (flag)
cout << "no" << endl;
else
cout << "yes" << endl;
}
}
int main() {
fast();
solve();
}
|
#include <bits/stdc++.h>
using namespace std;
int n, q;
vector<vector<int> > lava;
void input() {
cin >> n >> q;
lava.resize(2, vector<int>(n, 0));
}
int main() {
input();
int blocked = 0;
while (q--) {
int x, y;
cin >> x >> y;
x--;
y--;
int delta = (lava[x][y] == 0) ? 1 : -1;
lava[x][y] = 1 - lava[x][y];
for (int dy = -1; dy <= 1; dy++) {
if (y + dy < 0 || y + dy >= n) continue;
if (lava[1 - x][y + dy] == 1) blocked += delta;
}
cout << ((blocked == 0) ? "Yes\n" : "No\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int arr[2][100005];
int n, q;
int main() {
cin >> n >> q;
int num = 0;
int a, b;
for (int i = 0; i < q; i++) {
scanf("%d %d", &a, &b);
a--;
arr[a][b] += 1;
arr[a][b] %= 2;
if (arr[a][b] == 1) {
int tmp = (a + 1) % 2;
num += (arr[tmp][b] + arr[tmp][b - 1] + arr[tmp][b + 1]);
} else if (arr[a][b] == 0) {
int tmp = (a + 1) % 2;
num -= (arr[tmp][b] + arr[tmp][b - 1] + arr[tmp][b + 1]);
}
if (num == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int64_t n, q, x, y;
cin >> n >> q;
vector<vector<int64_t> > v(3, vector<int64_t>(n + 1, 0));
set<vector<pair<int64_t, int64_t> > > st;
for (int64_t i = 0; i < q; i++) {
cin >> x >> y;
if (v[x][y] == 0) {
v[x][y] = 1;
int64_t z = (x == 1) ? 2 : 1;
if (v[z][y] == 1) {
vector<pair<int64_t, int64_t> > vp;
vp.push_back({x, y});
vp.push_back({z, y});
sort((vp).begin(), (vp).end());
st.insert(vp);
}
if (y - 1 >= 1 and v[z][y - 1] == 1) {
vector<pair<int64_t, int64_t> > vp;
vp.push_back({x, y});
vp.push_back({z, y - 1});
sort((vp).begin(), (vp).end());
st.insert(vp);
}
if (y + 1 <= n and v[z][y + 1] == 1) {
vector<pair<int64_t, int64_t> > vp;
vp.push_back({x, y});
vp.push_back({z, y + 1});
sort((vp).begin(), (vp).end());
st.insert(vp);
}
} else {
v[x][y] = 0;
int64_t z = (x == 1) ? 2 : 1;
if (v[z][y] == 1) {
vector<pair<int64_t, int64_t> > vp;
vp.push_back({x, y});
vp.push_back({z, y});
sort((vp).begin(), (vp).end());
st.erase(vp);
}
if (y - 1 >= 1 and v[z][y - 1] == 1) {
vector<pair<int64_t, int64_t> > vp;
vp.push_back({x, y});
vp.push_back({z, y - 1});
sort((vp).begin(), (vp).end());
st.erase(vp);
}
if (y + 1 <= n and v[z][y + 1] == 1) {
vector<pair<int64_t, int64_t> > vp;
vp.push_back({x, y});
vp.push_back({z, y + 1});
sort((vp).begin(), (vp).end());
st.erase(vp);
}
}
if (st.empty())
cout << "YES"
<< "\n";
else
cout << "NO"
<< "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool get_int(T &x) {
char t = getchar();
bool neg = false;
x = 0;
for (; (t > '9' || t < '0') && t != '-' && t != EOF; t = getchar())
;
if (t == '-') neg = true, t = getchar();
if (t == EOF) return false;
for (; t <= '9' && t >= '0'; t = getchar()) x = x * 10 + t - '0';
if (neg) x = -x;
return true;
}
template <typename T>
void print_int(T x) {
if (x < 0) putchar('-'), x = -x;
short a[20] = {}, sz = 0;
while (x > 0) a[sz++] = x % 10, x /= 10;
if (sz == 0) putchar('0');
for (int i = sz - 1; i >= 0; i--) putchar('0' + a[i]);
}
const int inf = 0x3f3f3f3f;
const long long Linf = 1ll << 61;
const double pi = acos(-1.0);
const int maxn = 1000111;
int n, q, a[2][maxn], tot;
void add(int x) {
for (int i = 0; i < 2; i++)
if (a[i][x] && a[i][x + 1]) {
tot++;
return;
}
}
void remove(int x) {
for (int i = 0; i < 2; i++)
if (a[i][x] && a[i][x + 1]) {
tot--;
return;
}
}
int main() {
(get_int(n) && get_int(q));
tot = n - 1;
for (int i = 0; i < 2; i++)
for (int j = 1; j <= n; j++) a[i][j] = 1;
for (int i = 1, r, c; i <= q; i++) {
(get_int(r) && get_int(c));
r--;
if (c > 1) remove(c - 1);
if (c < n) remove(c);
a[r][c] ^= 1;
if (c > 1) add(c - 1);
if (c < n) add(c);
puts(tot == n - 1 ? "Yes" : "No");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q, a[3][100100], i, j, r, c;
memset(a, 0, sizeof a);
scanf("%d %d", &n, &q);
int flag = 0;
for (j = 0; j < q; j++) {
scanf("%d %d", &r, &c);
if (a[r][c] == 0) {
a[r][c] = 1;
if (a[2 - r + 1][c] == 1) {
flag++;
}
if (a[2 - r + 1][c + 1] == 1) {
flag++;
}
if (a[2 - r + 1][c - 1] == 1) {
flag++;
}
} else {
a[r][c] = 0;
if (a[2 - r + 1][c] == 1) {
flag--;
}
if (a[2 - r + 1][c + 1] == 1) {
flag--;
}
if (a[2 - r + 1][c - 1] == 1) {
flag--;
}
}
if (flag > 0)
printf("NO\n");
else
printf("YES\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool a[2][100010];
int n, q, nr, x, y;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
for (int i = 1; i <= q; i++) {
cin >> x >> y;
x--;
if (a[x][y])
nr -= a[(x + 1) % 2][y - 1] + a[(x + 1) % 2][y] + a[(x + 1) % 2][y + 1],
a[x][y] = 0;
else
nr += a[(x + 1) % 2][y - 1] + a[(x + 1) % 2][y] + a[(x + 1) % 2][y + 1],
a[x][y] = 1;
if (!nr)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void par(int a[], int n) {
for (long long int i = 0; i < n; i++) {
cout << a[i] << " ";
}
}
void pv(vector<long long int> a) {
for (long long int i = 0; i < a.size(); i++) {
cout << a[i] << " ";
}
}
long long int ceiling(long long int n, long long int m) {
if (n % m == 0)
return n / m;
else
return n / m + 1;
}
long long int mod = 1e9 + 7;
long long int MOD = mod;
long long int fact(long long int n);
long long int nCr(long long int n, long long int r) {
return fact(n) / (fact(r) * fact(n - r));
}
bool isprime(long long int n) {
for (long long int i = 2; i * i <= n; i++) {
if (n % i == 0) {
return 0;
}
}
return 1;
}
long long int fact(long long int n) {
int res = 1;
for (int i = 2; i <= n; i++) res = res * i;
return res;
}
bool seive(long long int n) {
long long int prime[n + 1];
memset(prime, 1, sizeof(prime));
for (int i = 2; i * i <= n; i++) {
if (prime[i] == 1) {
for (int j = i * i; j <= n; j++) {
prime[i] = 0;
}
}
}
return prime[n];
}
void re() {
long long int n, q;
cin >> n >> q;
vector<vector<long long int>> a(3, vector<long long int>(n + 2, 0));
long long int d = 0;
while (q--) {
long long int x, y;
cin >> x >> y;
a[x][y] = 1 - a[x][y];
long long int h = (x == 1 ? 2 : 1);
for (long long int j = y - 1; j < y + 2; j++) {
if (a[x][y] && a[h][j]) {
d++;
} else if (a[x][y] == 0 && a[h][j]) {
d--;
}
}
if (d == 0 && a[2][n] == 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cout.tie(NULL);
cin.tie(NULL);
;
re();
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
const long long MAXN = 1e+2 + 7;
const long long MOD = 1e+9 + 7, INF = 0x7f7f7f7f7f7f7f7f;
const int INFi = 0x7f7f7f7f;
double EPS = 1e-9;
double PI = acos(-1);
vector<long long> adj[MAXN];
long long visit[MAXN] = {};
int dx8[] = {0, 1, 1, 1, 0, -1, -1, -1}, dy8[] = {1, 1, 0, -1, -1, -1, 0, 1},
dx4[] = {0, 1, 0, -1}, dy4[] = {1, 0, -1, 0};
long long t, n;
long long i, j;
long long a[3][100007], q, b, c;
set<pair<pair<long long, long long>, pair<long long, long long>>> set1;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout << fixed;
cout << setprecision(10);
;
cin >> n >> q;
for (i = 1; i <= 2; i++) {
for (j = 1; j <= n; j++) a[i][j] = 0;
}
while (q--) {
cin >> b >> c;
if (a[b][c] == 0)
a[b][c] = 1;
else
a[b][c] = 0;
if (a[b][c] == 1) {
if (b == 1) {
if (a[2][c] == 1) set1.insert({{1, c}, {2, c}});
if (a[2][c + 1] == 1 && c + 1 != n + 1)
set1.insert({{1, c}, {2, c + 1}});
if (a[2][c - 1] == 1 && c - 1 != 0) set1.insert({{1, c}, {2, c - 1}});
}
if (b == 2) {
if (a[1][c] == 1) set1.insert({{1, c}, {2, c}});
if (a[1][c + 1] == 1 && c + 1 != n + 1)
set1.insert({{2, c}, {1, c + 1}});
if (a[1][c - 1] == 1 && c - 1 != n - 1)
set1.insert({{2, c}, {1, c - 1}});
}
}
if (a[b][c] == 0) {
if (b == 1) {
set1.erase({{1, c}, {2, c}});
set1.erase({{2, c}, {1, c}});
set1.erase({{1, c}, {2, c + 1}});
set1.erase({{2, c + 1}, {1, c}});
set1.erase({{1, c}, {2, c - 1}});
set1.erase({{2, c - 1}, {1, c}});
}
if (b == 2) {
set1.erase({{2, c}, {1, c}});
set1.erase({{1, c}, {2, c}});
set1.erase({{2, c}, {1, c + 1}});
set1.erase({{1, c + 1}, {2, c}});
set1.erase({{2, c}, {1, c - 1}});
set1.erase({{1, c - 1}, {2, c}});
}
}
if (set1.empty())
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
vector<vector<bool> > g(2, vector<bool>(n));
int x = 0;
for (int i = 0; i < q; i++) {
int ri, ci;
cin >> ri >> ci;
ri -= 1;
ci -= 1;
bool old = g[ri][ci], nw = !g[ri][ci];
g[ri][ci] = nw;
for (int j = -1; j <= 1; j += 2) {
for (int k = -1; k <= 1; k++) {
if (j == 0 and k == 0) continue;
int r2 = ri + j, c2 = ci + k;
if (r2 >= 0 and r2 < 2 and c2 >= 0 and c2 < n) {
bool nb = g[r2][c2];
if (nw == true and nb == true) {
x++;
} else if (nw == false and nb == true) {
x--;
}
}
}
}
cout << (x ? "No" : "Yes") << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 10e5;
bool plano[2][MAXN];
int n, q;
map<pair<int, int>, set<pair<int, int> > > conflictos;
int conflictoTot = 0;
void addConflicto(int &x1, int y1, int &x2, int &y2) {
pair<int, int> a = {x1, y1}, b = {x2, y2};
conflictos[a].insert(b);
conflictos[b].insert(a);
conflictoTot++;
}
void deleteConflictos(int &x, int &y) {
pair<int, int> a = {x, y};
for (auto &i : conflictos[a]) {
conflictos[i].erase(a);
conflictoTot--;
}
conflictos.erase(a);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
;
cin >> n >> q;
for (int i = 0; i < int(q); i++) {
int x, y;
bool posib = true;
cin >> x >> y;
x--;
y--;
plano[x][y] = !plano[x][y];
if (plano[x][y]) {
int newX = (x == 1 ? 0 : 1);
if (plano[newX][y]) addConflicto(newX, y, x, y);
if (y - 1 >= 0 and plano[newX][y - 1]) addConflicto(newX, y - 1, x, y);
if (y + 1 >= 0 and plano[newX][y + 1]) addConflicto(newX, y + 1, x, y);
} else
deleteConflictos(x, y);
if (conflictoTot)
cout << "No" << '\n';
else
cout << "Yes" << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
scanf("%d%d", &n, &q);
map<pair<int, int>, int> m1;
map<pair<int, int>, int> m2;
for (int i = 1; i <= n; i++) {
pair<int, int> p(1, i);
pair<int, int> p1(2, i);
m1[p] = 0;
m2[p] = 0;
}
int kt = 0, s = 0;
while (q--) {
int a, b;
scanf("%d%d", &a, &b);
pair<int, int> p(a, b);
pair<int, int> p1(3 - a, b - 1);
pair<int, int> p2(3 - a, b);
pair<int, int> p3(3 - a, b + 1);
if (m2[p] == 0) {
m2[p] = 1;
} else {
m2[p] = 0;
}
if (m2[p] == 0) {
s -= m1[p];
if (m2[p1] != 0) {
m1[p1]--;
}
if (m2[p2] != 0) {
m1[p2]--;
}
if (m2[p3] != 0) {
m1[p3]--;
}
m1[p] = 0;
} else {
int count = 0;
if (m2[p1] != 0) {
m1[p1]++;
count++;
}
if (m2[p2] != 0) {
m1[p2]++;
count++;
}
if (m2[p3] != 0) {
m1[p3]++;
count++;
}
m1[p] = count;
s += count;
}
if (s != 0)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
scanf("%d%d", &n, &q);
set<pair<int, int>> cells;
int bad_nei = 0;
for (int i = 0; i < q; i++) {
int row, col;
scanf("%d%d", &row, &col);
bool was_forbidden = cells.count({row, col});
for (int r = row - 1; r <= row + 1; r++) {
for (int c = col - 1; c <= col + 1; c++) {
if (r == row) {
continue;
}
if (!(1 <= r && r <= 2 && 1 <= c && c <= n)) {
continue;
}
if (cells.count({r, c})) {
if (was_forbidden) {
bad_nei--;
} else {
bad_nei++;
}
}
}
}
if (cells.count({row, col})) {
cells.erase({row, col});
} else {
cells.insert({row, col});
}
if (bad_nei >= 1) {
puts("NO");
} else {
puts("YES");
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
int a[3][n + 1];
int i, j;
for (i = 0; i < 3; i++) {
for (j = 0; j <= n; j++) a[i][j] = 0;
}
int c = 0;
int x, y;
for (i = 0; i < q; i++) {
cin >> x >> y;
if (a[x][y] == 1) {
a[x][y] = 0;
if (x == 1) {
if (a[2][y] == 1) c--;
if (a[2][y - 1] == 1 && y - 1 >= 1) c--;
if (a[2][y + 1] == 1 && y + 1 <= n) c--;
} else {
if (a[1][y] == 1) c--;
if (a[1][y - 1] == 1 && y - 1 >= 1) c--;
if (a[1][y + 1] == 1 && y + 1 <= n) c--;
}
} else {
a[x][y] = 1;
if (x == 1) {
if (a[2][y] == 1) c++;
if (a[2][y - 1] == 1 && y - 1 >= 1) c++;
if (a[2][y + 1] == 1 && y + 1 <= n) c++;
} else {
if (a[1][y] == 1) c++;
if (a[1][y - 1] == 1 && y - 1 >= 1) c++;
if (a[1][y + 1] == 1 && y + 1 <= n) c++;
}
}
if (c >= 1)
cout << "No\n";
else {
if (a[2][n] == 0 && a[1][1] == 0)
cout << "Yes\n";
else
cout << "No\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, q;
bool a[2][100000];
int cnt1, cnt2;
int main() {
cin >> n >> q;
for (int i = 0; i < q; ++i) {
int r, c;
cin >> r >> c;
r--;
c--;
if (a[0][c] && a[1][c]) {
cnt1--;
}
if (c > 0 && ((a[0][c] && a[1][c - 1]) || (a[1][c] && a[0][c - 1]))) {
cnt2--;
}
if (c < n - 1 && ((a[0][c] && a[1][c + 1]) || (a[1][c] && a[0][c + 1]))) {
cnt2--;
}
a[r][c] = !a[r][c];
if (a[0][c] && a[1][c]) {
cnt1++;
}
if (c > 0 && ((a[0][c] && a[1][c - 1]) || (a[1][c] && a[0][c - 1]))) {
cnt2++;
}
if (c < n - 1 && ((a[0][c] && a[1][c + 1]) || (a[1][c] && a[0][c + 1]))) {
cnt2++;
}
if (cnt1 + cnt2) {
cout << "No\n";
} else
cout << "Yes\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, q;
int d[2][200000];
int cnt[3];
void calc(int x, int y, int e) {
if (d[x][y] == 0) return;
if (x == 0) {
if (y + 1 < n && d[x + 1][y + 1]) cnt[0] += e;
if (y - 1 >= 0 && d[x + 1][y - 1]) cnt[1] += e;
if (d[x + 1][y]) cnt[2] += e;
} else {
if (y - 1 >= 0 && d[x - 1][y - 1]) cnt[0] += e;
if (y + 1 < n && d[x - 1][y + 1]) cnt[1] += e;
if (d[x - 1][y]) cnt[2] += e;
}
}
int main() {
cin >> n >> q;
for (int i = 0; i < q; i++) {
int r, c;
scanf("%d%d", &r, &c);
r--;
c--;
calc(r, c, -1);
d[r][c] ^= 1;
calc(r, c, 1);
if (cnt[0] || cnt[1] || cnt[2])
puts("No");
else
puts("Yes");
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, q;
int now;
bool v[3][110000];
int va[3][110000];
int x, y;
void cal(int ha, int xx, int yy) {
int tx = x == 1 ? 2 : 1;
if (v[tx][yy - 1]) va[xx][yy] += ha, va[tx][yy - 1] += ha, now += ha * 2;
if (v[tx][yy]) va[xx][yy] += ha, va[tx][yy] += ha, now += ha * 2;
if (v[tx][yy + 1]) va[xx][yy] += ha, va[tx][yy + 1] += ha, now += ha * 2;
}
int main() {
scanf("%d%d", &n, &q);
for (int i = 1; i <= q; i++) {
scanf("%d%d", &x, &y);
if (!v[x][y]) {
v[x][y] = 1;
cal(1, x, y);
} else {
v[x][y] = 0;
cal(-1, x, y);
}
if (now)
printf("No\n");
else
printf("Yes\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[2][100100];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int cnt = 0;
int q;
cin >> q;
for (int i = 0; i < (int)(q); ++i) {
int x, y;
cin >> x >> y;
--x;
for (int j = 0; j < (int)(3); ++j) {
if (a[x][y]) {
cnt -= a[1 - x][y - 1 + j];
} else {
cnt += a[1 - x][y - 1 + j];
}
}
a[x][y] = 1 - a[x][y];
if (cnt == 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10, mod = 1e9 + 7;
const long long inf = 2e16 + 10;
int a[maxn];
int A, B, n;
void add(int x, int y) {
A -= a[y] == 3;
if (y > 0) B -= (a[y - 1] | a[y]) == 3;
if (y < n - 1) B -= (a[y] | a[y + 1]) == 3;
a[y] ^= 1 << x;
A += a[y] == 3;
if (y > 0) B += (a[y - 1] | a[y]) == 3;
if (y < n - 1) B += (a[y] | a[y + 1]) == 3;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie();
int q;
cin >> n >> q;
while (q--) {
int a, b;
cin >> a >> b;
add(--a, --b);
cout << (A == 0 && B == 0 ? "Yes\n" : "No\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1050;
struct node {
int u;
int v;
int a;
int b;
bool operator<(const node& t) const {
if (u != t.u) return u < t.u;
if (v != t.v) return v < t.v;
if (a != t.a) return a < t.a;
return b < t.b;
}
};
set<pair<int, int> > s;
map<node, int> mp;
int main() {
int n, q;
scanf("%d%d", &n, &q);
while (q--) {
int u, v;
scanf("%d%d", &u, &v);
if (s.count({u, v})) {
s.erase({u, v});
int uu;
if (u == 1)
uu = 2;
else
uu = 1;
if (s.count({uu, v})) {
mp.erase({uu, v, u, v});
mp.erase({u, v, uu, v});
}
if (s.count({uu, v - 1})) {
mp.erase({uu, v - 1, u, v});
mp.erase({u, v, uu, v - 1});
}
if (s.count({uu, v + 1})) {
mp.erase({uu, v + 1, u, v});
mp.erase({u, v, uu, v + 1});
}
} else {
s.insert({u, v});
int uu;
if (u == 1)
uu = 2;
else
uu = 1;
if (s.count({uu, v})) {
mp[{uu, v, u, v}]++;
mp[{u, v, uu, v}]++;
}
if (s.count({uu, v + 1})) {
mp[{uu, v + 1, u, v}]++;
mp[{u, v, uu, v + 1}]++;
}
if (s.count({uu, v - 1})) {
mp[{uu, v - 1, u, v}]++;
mp[{u, v, uu, v - 1}]++;
}
}
if (mp.size() != 0) {
puts("NO");
} else
puts("YES");
}
}
|
#include <bits/stdc++.h>
using namespace std;
int fv[100005][2];
int main() {
ios_base::sync_with_stdio(false);
int n, i, j = 0, m, cnt = 0;
cin >> n >> m;
for (i = 1; i <= m; ++i) {
int a, b;
cin >> a >> b;
--a;
if (fv[b][a] == 1)
cnt -= (fv[b - 1][1 - a] + fv[b][1 - a] + fv[b + 1][1 - a]);
if (fv[b][a] == 0)
cnt += (fv[b - 1][1 - a] + fv[b][1 - a] + fv[b + 1][1 - a]);
fv[b][a] = 1 - fv[b][a];
if (cnt == 0)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int vis[3][maxn];
int main() {
for (int i = 1; i <= 1000; ++i)
;
for (int i = 1; i <= 1000; ++i)
;
for (int i = 1; i <= 1000; ++i)
;
for (int i = 1; i <= 1000; ++i)
;
int n, q;
cin >> n >> q;
int sum = 0;
int x, y;
while (q--) {
cin >> x >> y;
if (x == 1) {
if (vis[x][y] == 1) {
vis[x][y] = 0;
if (vis[x + 1][y - 1] == 1) sum--;
if (vis[x + 1][y + 1] == 1) sum--;
if (vis[x + 1][y] == 1) sum--;
} else {
vis[x][y] = 1;
if (vis[x + 1][y - 1] == 1) sum++;
if (vis[x + 1][y + 1] == 1) sum++;
if (vis[x + 1][y] == 1) sum++;
}
} else {
if (vis[x][y] == 1) {
vis[x][y] = 0;
if (vis[x - 1][y - 1] == 1) sum--;
if (vis[x - 1][y + 1] == 1) sum--;
if (vis[x - 1][y] == 1) sum--;
} else {
vis[x][y] = 1;
if (vis[x - 1][y - 1] == 1) sum++;
if (vis[x - 1][y + 1] == 1) sum++;
if (vis[x - 1][y] == 1) sum++;
}
}
if (!sum)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
for (int i = 1; i <= 1000; ++i)
;
for (int i = 1; i <= 1000; ++i)
;
for (int i = 1; i <= 1000; ++i)
;
for (int i = 1; i <= 1000; ++i)
;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[3][200000], b[10000];
int main() {
int i, j, n, m, x, y, sum = 0, k;
cin >> n >> m;
for (i = 0; i < m; i++) {
cin >> x >> y;
if (a[x][y] == 0) {
a[x][y] = 1;
if (x == 1) {
if (a[x + 1][y] == 1 && a[x + 1][y - 1] == 1 && a[x + 1][y + 1] == 1) {
sum += 3;
} else if ((a[x + 1][y] == 1 && a[x + 1][y - 1] == 1) ||
(a[x + 1][y] && a[x + 1][y + 1] == 1) ||
(a[x + 1][y - 1] == 1 && a[x + 1][y + 1] == 1)) {
sum += 2;
} else if (a[x + 1][y] == 1 || a[x + 1][y - 1] == 1 ||
a[x + 1][y + 1] == 1) {
sum++;
}
} else {
if (a[x - 1][y] == 1 && a[x - 1][y - 1] == 1 && a[x - 1][y + 1] == 1) {
sum += 3;
} else if ((a[x - 1][y] == 1 && a[x - 1][y - 1] == 1) ||
(a[x - 1][y] && a[x - 1][y + 1] == 1) ||
(a[x - 1][y - 1] == 1 && a[x - 1][y + 1] == 1)) {
sum += 2;
} else if (a[x - 1][y] == 1 || a[x - 1][y - 1] == 1 ||
a[x - 1][y + 1] == 1) {
sum++;
}
}
} else {
a[x][y] = 0;
if (x == 1) {
if (a[x + 1][y] == 1 && a[x + 1][y - 1] == 1 && a[x + 1][y + 1] == 1) {
sum -= 3;
} else if ((a[x + 1][y] == 1 && a[x + 1][y - 1] == 1) ||
(a[x + 1][y] && a[x + 1][y + 1] == 1) ||
(a[x + 1][y - 1] == 1 && a[x + 1][y + 1] == 1)) {
sum -= 2;
} else if (a[x + 1][y] == 1 || a[x + 1][y - 1] == 1 ||
a[x + 1][y + 1] == 1) {
sum--;
}
} else {
if (a[x - 1][y] == 1 && a[x - 1][y - 1] == 1 && a[x - 1][y + 1] == 1) {
sum -= 3;
} else if ((a[x - 1][y] == 1 && a[x - 1][y - 1] == 1) ||
(a[x - 1][y] && a[x - 1][y + 1] == 1) ||
(a[x - 1][y - 1] == 1 && a[x - 1][y + 1] == 1)) {
sum -= 2;
} else if (a[x - 1][y] == 1 || a[x - 1][y - 1] == 1 ||
a[x - 1][y + 1] == 1) {
sum--;
}
}
}
if (sum == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-8;
const long long MOD = 1000000007;
const long long MAXN = 100010;
int n, m, T, k;
int a[3][MAXN];
int cntt;
int main() {
int i, j, t, ii, jj;
int n1, n2, n3;
char ch;
cntt = 1;
int x, y;
int cnt = 0;
scanf("%d %d", &n, &m);
while (m--) {
scanf("%d %d", &x, &y);
k = 1;
if (x == 1) {
k = 2;
}
if (a[x][y] == 1) {
for (i = y - 1; i <= y + 1; i++) {
if (a[k][i]) {
cnt--;
}
}
a[x][y] = 0;
} else {
for (i = y - 1; i <= y + 1; i++) {
if (a[k][i]) {
cnt++;
}
}
a[x][y] = 1;
}
if (cnt) {
printf("No\n");
} else {
printf("Yes\n");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
bool vis[3][n + 1];
for (int i = 0; i < 3; i++) {
for (int j = 0; j < n + 1; j++) vis[i][j] = false;
}
int bad_nei = 0;
while (q--) {
int row, col;
cin >> row >> col;
for (int i = row - 1; i <= row + 1; i++) {
for (int j = col - 1; j <= col + 1; j++) {
if (i == row) continue;
if (!(i >= 1 && i <= 2 && j >= 1 && j <= n)) continue;
if (vis[i][j]) {
if (vis[row][col])
bad_nei--;
else
bad_nei++;
}
}
}
vis[row][col] = !vis[row][col];
if (bad_nei >= 1)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q, cnt = 0;
cin >> n >> q;
set<pair<int, int> > s;
int curr = 0;
for (int i = 1; i <= q; i++) {
int x, y;
cin >> x >> y;
if (s.find({x, y}) == s.end()) {
s.insert({x, y});
if (x == 1) {
if (((y - 1) > 0) && (s.find({2, y - 1}) != s.end())) cnt++;
if (((y + 1) <= n) && (s.find({2, y + 1}) != s.end())) cnt++;
if (s.find({2, y}) != s.end()) cnt++;
} else {
if (((y - 1) > 0) && (s.find({1, y - 1}) != s.end())) cnt++;
if (((y + 1) <= n) && (s.find({1, y + 1}) != s.end())) cnt++;
if (s.find({1, y}) != s.end()) cnt++;
}
} else {
s.erase({x, y});
if (x == 1) {
if (((y - 1) > 0) && (s.find({2, y - 1}) != s.end())) cnt--;
if (((y + 1) <= n) && (s.find({2, y + 1}) != s.end())) cnt--;
if (s.find({2, y}) != s.end()) cnt--;
} else {
if (((y - 1) > 0) && (s.find({1, y - 1}) != s.end())) cnt--;
if (((y + 1) <= n) && (s.find({1, y + 1}) != s.end())) cnt--;
if (s.find({1, y}) != s.end()) cnt--;
}
}
if (cnt <= 0)
cout << "Yes"
<< "\n";
else
cout << "No"
<< "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long n, q, c = 0, x, y, i;
cin >> n >> q;
long long a[2][2 + n];
for (i = 0; i <= n + 1; i++) a[0][i] = a[1][i] = 0;
while (q--) {
cin >> x >> y;
x--;
if (a[x][y]) {
c -= a[1 - x][y - 1] + a[1 - x][y] + a[1 - x][y + 1];
a[x][y] = 0;
} else {
c += a[1 - x][y - 1] + a[1 - x][y] + a[1 - x][y + 1];
a[x][y] = 1;
}
if (c)
cout << "No\n";
else
cout << "Yes\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool bloque[2][(long long)1e5];
signed main() {
long long largeur, nReqs, nBads;
cin >> largeur >> nReqs;
nBads = 0;
while (nReqs--) {
long long x, y;
cin >> x >> y;
--x;
--y;
if (bloque[x][y]) {
for (long long newY = max(0ll, y - 1); newY <= min(largeur - 1, y + 1);
++newY)
nBads -= bloque[1 - x][newY];
bloque[x][y] = false;
if ((x == 1 && y == largeur - 1) || (x == 0 && y == 0)) nBads--;
} else {
for (long long newY = max(0ll, y - 1); newY <= min(largeur - 1, y + 1);
++newY)
nBads += bloque[1 - x][newY];
bloque[x][y] = true;
if ((x == 1 && y == largeur - 1) || (x == 0 && y == 0)) nBads++;
}
if (nBads == 0)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
long long n;
cin >> n;
long long q;
cin >> q;
map<long long, long long> m1, m2;
long long problem = 0;
while (q--) {
long long r, c;
cin >> r >> c;
if (r == 1) {
if (m1[c] == 1) {
m1[c] = 0;
if (m2[c - 1] == 1) {
problem--;
}
if (m2[c + 1] == 1) {
problem--;
}
if (m2[c] == 1) problem--;
} else {
m1[c] = 1;
if (m2[c - 1] == 1) problem++;
if (m2[c + 1] == 1) problem++;
if (m2[c] == 1) problem++;
}
} else {
if (m2[c] == 1) {
m2[c] = 0;
if (m1[c - 1] == 1) {
problem--;
}
if (m1[c + 1] == 1) {
problem--;
}
if (m1[c] == 1) problem--;
} else {
m2[c] = 1;
if (m1[c - 1] == 1) problem++;
if (m1[c + 1] == 1) problem++;
if (m1[c] == 1) problem++;
}
}
if (problem > 0)
cout << "NO\n";
else
cout << "YES\n";
}
}
|
#include <bits/stdc++.h>
#pragma GCC optimize(2)
#pragma warning(disable : 4996)
using namespace std;
const long long INF = 2147483647;
const double PI = acos(-1);
const int mod = 1e9 + 7;
bool vis[3][120000];
int main() {
long long n, q;
cin >> n >> q;
long long obstacles = 0;
for (int j = 1; j <= q; j++) {
long long x, y;
cin >> x >> y;
long long increment = vis[x][y] == 1 ? -1 : 1;
vis[x][y] = 1 - vis[x][y];
long long dx = x == 2 ? 1 : 2;
for (int i = -1; i <= 1; i++) {
if (vis[dx][y + i]) obstacles += increment;
}
if (obstacles)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma optimize("O2")
using namespace std;
set<pair<long long, long long>> A;
int32_t main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(false);
long long n, q;
cin >> n >> q;
long long block = 0;
for (long long i = 0; i < q; i++) {
long long x, y;
cin >> x >> y;
if (A.find({x, y}) == A.end()) {
A.insert({x, y});
if (A.find({3 - x, y - 1}) != A.end()) {
block++;
}
if (A.find({3 - x, y}) != A.end()) {
block++;
}
if (A.find({3 - x, y + 1}) != A.end()) {
block++;
}
} else {
A.erase({x, y});
if (A.find({3 - x, y - 1}) != A.end()) {
block--;
}
if (A.find({3 - x, y}) != A.end()) {
block--;
}
if (A.find({3 - x, y + 1}) != A.end()) {
block--;
}
}
if (block == 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
int tab[32] = {0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, -1, 0, -1,
1, 1, 2, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, -1, 0, -1};
using std::bitset;
bitset<262144> tag[2];
inline int query(int x, int y) {
const int sign = (tag[x][y] == 1) ? -1 : 1;
tag[x][y] = !tag[x][y];
int cas = tag[x][y + 1];
cas += tag[!x][y + 1] * 2;
cas += tag[!x][y] * 4;
cas += tag[x][y - 1] * 8;
cas += tag[!x][y - 1] * 16;
return sign * tab[cas];
}
int main(void) {
int n, q, cnt = 1;
scanf("%d%d", &n, &q);
tag[0][0] = tag[1][0] = 1;
tag[0][n + 1] = tag[1][n + 1] = 1;
for (int i = 0; i < q; ++i) {
int x, y;
scanf("%d%d", &x, &y);
cnt += query(x - 1, y);
if (cnt == 1)
puts("Yes");
else
puts("No");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
set<pair<int, int>> st;
int w[2][100000];
bool lava[2][100000];
int n, q;
void rmv_set(int r, int c) {
st.erase(make_pair(r, c));
int n_r = (r + 1) % 2;
if (w[n_r][c] > 0) {
w[n_r][c]--;
if (w[n_r][c] == 0) {
rmv_set(n_r, c);
}
}
if (c < n - 1 && w[n_r][c + 1] > 0) {
w[n_r][c + 1]--;
if (w[n_r][c + 1] == 0) {
rmv_set(n_r, c + 1);
}
}
if (c > 0 && w[n_r][c - 1] > 0) {
w[n_r][c - 1]--;
if (w[n_r][c - 1] == 0) {
rmv_set(n_r, c - 1);
}
}
}
int main() {
cin >> n >> q;
while (q--) {
int r, c;
cin >> r >> c;
r--;
c--;
lava[r][c] = 1 - lava[r][c];
if (w[r][c] > 0) {
w[r][c] = 0;
rmv_set(r, c);
} else {
if (lava[r][c]) {
int n_r = (r + 1) % 2;
if (lava[n_r][c]) {
if (w[r][c] == 0) {
st.insert(make_pair(r, c));
}
w[r][c]++;
if (w[n_r][c] == 0) {
st.insert(make_pair(r, c));
}
w[n_r][c]++;
}
if (c < n - 1 && lava[n_r][c + 1]) {
if (w[r][c] == 0) {
st.insert(make_pair(r, c));
}
w[r][c]++;
if (w[n_r][c + 1] == 0) {
st.insert(make_pair(n_r, c + 1));
}
w[n_r][c + 1]++;
}
if (c > 0 && lava[n_r][c - 1]) {
if (w[r][c] == 0) {
st.insert(make_pair(r, c));
}
w[r][c]++;
if (w[n_r][c - 1] == 0) {
st.insert(make_pair(n_r, c - 1));
}
w[n_r][c - 1]++;
}
}
}
if (st.empty()) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const int inf = 0x3f3f3f3f;
int dp[3][maxn], cnt = 0;
int n, q;
void solve(int r, int c) {
r--;
if (dp[r][c]) {
dp[r][c] = 0;
r ^= 1;
for (int i = -1; i <= 1; i++) {
int now = c + i;
if (now <= 0 || now > n) continue;
if (dp[r][now]) cnt--;
}
} else {
dp[r][c] = 1;
r ^= 1;
for (int i = -1; i <= 1; i++) {
int now = c + i;
if (now <= 0 || now > n) continue;
if (dp[r][now]) cnt++;
}
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q;
while (q--) {
int r, c;
cin >> r >> c;
solve(r, c);
if (cnt)
cout << "No" << '\n';
else
cout << "Yes" << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int grid[3][100069];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
memset(grid, 0, sizeof grid);
int n, q;
int bad = 0;
cin >> n >> q;
for (int i = 0; i < q; i++) {
int r, c;
cin >> r >> c;
if (grid[r][c] == 1) {
int q = (r == 1) ? 2 : 1;
for (int j = max(c - 1, 1); j < min(c + 2, n + 1); j++) {
if (grid[q][j] == 1) bad--;
}
grid[r][c] = 0;
} else {
int q = (r == 1) ? 2 : 1;
for (int j = max(c - 1, 1); j < min(c + 2, n + 1); j++) {
if (grid[q][j] == 1) bad++;
}
grid[r][c] = 1;
}
if (bad == 0)
cout << "Yes\n";
else
cout << "No\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int dy[] = {-1, -1, -1, 1, 1, 1}, dx[] = {-1, 0, 1, -1, 0, 1};
int arr[2][200001], n, m;
int main() {
scanf("%d%d", &n, &m);
int cnt = 0;
for (int i = 0; i < m; i++) {
int x, y;
scanf("%d%d", &y, &x);
y--;
x--;
arr[y][x] ^= 1;
for (int k = 0; k < 6; k++) {
int yy = y + dy[k], xx = x + dx[k];
if (yy >= 0 && yy < 2 && xx >= 0 && xx < n && arr[yy][xx] == 1) {
cnt += (arr[y][x] == 1 ? 1 : -1);
}
}
puts(cnt ? "No" : "Yes");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int n, q;
cin >> n >> q;
long long int arr[3][n + 1];
for (long long int i = 0; i < 3; i++) {
for (long long int j = 0; j < n + 1; j++) {
arr[i][j] = 0;
}
}
long long int blocks = 0;
long long int x, y;
for (long long int i = 0; i < q; i++) {
cin >> x >> y;
if (arr[x][y] == 0) {
arr[x][y] = 1;
if (x + 1 <= 2 && arr[x + 1][y] == 1) {
blocks++;
}
if (x + 1 <= 2 && y + 1 <= n && arr[x + 1][y + 1] == 1) {
blocks++;
}
if (x + 1 <= 2 && y - 1 > 0 && arr[x + 1][y - 1] == 1) {
blocks++;
}
if (x - 1 > 0 && arr[x - 1][y] == 1) {
blocks++;
}
if (x - 1 > 0 && y - 1 > 0 && arr[x - 1][y - 1] == 1) {
blocks++;
}
if (x - 1 > 0 && y + 1 <= n && arr[x - 1][y + 1] == 1) {
blocks++;
}
} else {
arr[x][y] = 0;
if (x + 1 <= 2 && arr[x + 1][y] == 1) {
blocks--;
}
if (x + 1 <= 2 && y + 1 <= n && arr[x + 1][y + 1] == 1) {
blocks--;
}
if (x + 1 <= 2 && y - 1 > 0 && arr[x + 1][y - 1] == 1) {
blocks--;
}
if (x - 1 > 0 && arr[x - 1][y] == 1) {
blocks--;
}
if (x - 1 > 0 && y - 1 > 0 && arr[x - 1][y - 1] == 1) {
blocks--;
}
if (x - 1 > 0 && y + 1 <= n && arr[x - 1][y + 1] == 1) {
blocks--;
}
}
if (blocks == 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, q, sum, vis[2][N];
void solve(int x, int y) {
if (vis[x][y]) {
vis[x][y] = 0;
if (vis[!x][y]) sum--;
if (vis[!x][y - 1]) sum--;
if (vis[!x][y + 1]) sum--;
} else {
vis[x][y] = 1;
if (vis[!x][y]) sum++;
if (vis[!x][y - 1]) sum++;
if (vis[!x][y + 1]) sum++;
}
}
int main() {
scanf("%d%d", &n, &q);
int x, y;
while (q--) {
scanf("%d%d", &x, &y);
solve(x - 1, y);
if (!sum) {
printf("Yes\n");
} else
printf("No\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, q, t;
bool s[200000][2];
void count(int i, int d) {
if (i < 0 || i >= n - 1) return;
t += d * (!s[i][0] && !s[i + 1][0] || !s[i][1] && !s[i + 1][1] ? 0 : 1);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(10);
cin >> n >> q;
int r, c;
for (int i = 0; i < q; i++) {
cin >> r >> c, r--, c--;
count(c - 1, -1);
count(c, -1);
s[c][r] = !s[c][r];
count(c - 1, 1);
count(c, 1);
cout << (t == 0 && !s[0][0] && !s[n - 1][1] ? "Yes\n" : "No\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, Q;
int cnt_bad = 0;
bool bad[2][100100];
int main() {
scanf("%d%d", &n, &Q);
memset(bad, 0, sizeof(bad));
for (int i = 0; i < Q; i++) {
int x, y;
scanf("%d%d", &x, &y);
x--, y--;
if (bad[x][y]) {
bad[x][y] = 0;
if (y - 1 >= 0) cnt_bad -= bad[x ^ 1][y - 1];
cnt_bad -= bad[x ^ 1][y];
if (y + 1 < n) cnt_bad -= bad[x ^ 1][y + 1];
} else {
bad[x][y] = 1;
if (y - 1 >= 0) cnt_bad += bad[x ^ 1][y - 1];
cnt_bad += bad[x ^ 1][y];
if (y + 1 < n) cnt_bad += bad[x ^ 1][y + 1];
}
if (cnt_bad == 0)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline T abs(T t) {
return t < 0 ? -t : t;
}
const long long modn = 1000000007;
inline long long mod(long long x) { return x % modn; }
const int MAXN = 212345;
int n, m, k;
bool M[2][MAXN];
int lava(int i, int j) {
return (i >= 0 && j >= 0 && i < 2 && j < n && M[i][j]);
}
void t(int i, int j) {
if (M[i][j])
k -= lava(i - 1, j) + lava(i - 1, j - 1) + lava(i - 1, j + 1) +
lava(i + 1, j) + lava(i + 1, j - 1) + lava(i + 1, j + 1);
else
k += lava(i - 1, j) + lava(i - 1, j - 1) + lava(i - 1, j + 1) +
lava(i + 1, j) + lava(i + 1, j - 1) + lava(i + 1, j + 1);
M[i][j] = !M[i][j];
}
int main() {
scanf("%d%d", &n, &m);
for (int a = 0; a < m; a++) {
int i, j;
scanf("%d%d", &i, &j);
i--;
j--;
t(i, j);
if (k)
puts("No");
else
puts("Yes");
}
}
|
#include <bits/stdc++.h>
using namespace std;
const long double eps = (long double)1e-9;
const long double PI = (long double)acos(-1.0);
const int inf = 1e9 + 5;
const long long linf = 1e18L + 5;
const int mod = 1e9 + 7;
void solve() {
int n, q, r, c;
cin >> n >> q;
unordered_set<int> s[3];
set<pair<int, int> > p;
pair<int, int> pr;
for (int i = 0; i < q; ++i) {
cin >> r >> c;
if (s[r].count(c)) {
s[r].erase(c);
for (int j : {c - 1, c, c + 1}) {
if (j < 1 || j > n) continue;
if (r == 1)
pr = {c, j};
else
pr = {j, c};
auto it = p.find(pr);
if (it != p.end()) p.erase(it);
}
} else {
s[r].insert(c);
for (int j : {c - 1, c, c + 1}) {
if (j < 1 || j > n) continue;
if (r == 1)
pr = {c, j};
else
pr = {j, c};
if (s[3 - r].count(j)) p.insert(pr);
}
}
cout << ((int)(p).size() ? "no" : "yes") << '\n';
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
int test = 1;
while (test--) {
solve();
cout << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
cin >> n >> q;
std::vector<vector<int>> v;
v.resize(2, vector<int>(n, 0));
int ans = 0;
while (q--) {
int change = 0;
int x, y;
cin >> x >> y;
x--;
y--;
if (v[x][y] == 0)
change++;
else
change--;
v[x][y] = 1 - v[x][y];
for (int i = -1; i <= 1; i++) {
if (y + i >= n && y + i <= 0) continue;
if (v[1 - x][y + i] == 1) ans += change;
}
if (ans == 0)
cout << "YES\n";
else
cout << "NO\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
int cek[3][100010] = {0};
int x, y;
int key = 0;
while (q--) {
cin >> x >> y;
if (cek[x][y] == 0) {
cek[x][y] = 1;
for (int i = y - 1; i <= y + 1; i++) {
if (cek[3 - x][i] == 1) key++;
}
} else {
cek[x][y] = 0;
for (int i = y - 1; i <= y + 1; i++) {
if (cek[3 - x][i] == 1) key--;
}
}
if (key)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
#pragma warning(disable : 4996)
int N, Q;
bool I[3][1000009];
int cnt = 0;
int main() {
scanf("%d%d", &N, &Q);
for (int i = 1; i <= Q; i++) {
int px, py;
scanf("%d%d", &px, &py);
if (I[1][py] == true && I[2][py] == true) cnt--;
if (px == 1) {
if (I[2][py - 1] == true && I[1][py] == true) cnt--;
if (I[2][py + 1] == true && I[1][py] == true) cnt--;
}
if (px == 2) {
if (I[1][py - 1] == true && I[2][py] == true) cnt--;
if (I[1][py + 1] == true && I[2][py] == true) cnt--;
}
I[px][py] ^= true;
if (I[1][py] == true && I[2][py] == true) cnt++;
if (px == 1) {
if (I[2][py - 1] == true && I[1][py] == true) cnt++;
if (I[2][py + 1] == true && I[1][py] == true) cnt++;
}
if (px == 2) {
if (I[1][py - 1] == true && I[2][py] == true) cnt++;
if (I[1][py + 1] == true && I[2][py] == true) cnt++;
}
if (cnt == 0)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int pw(long long int a, long long int b, long long int mod) {
if (!b) return 1;
if (b & 1) return a * pw(a * a % mod, b / 2, mod) % mod;
return pw(a * a % mod, b / 2, mod) % mod;
}
const long long int MAXN = 1e5 + 10;
const long long int INF = 8e18;
const long long int MOD = 1e9 + 7;
int n, q, A[MAXN], cnt;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
fill(A, A + MAXN, 3);
cin >> n >> q;
while (q--) {
int r, c;
cin >> r >> c;
r--;
if (c < n) {
cnt -= (A[c] & A[c + 1]) == 0;
cnt += ((A[c] ^ (1 << r)) & A[c + 1]) == 0;
}
if (c > 1) {
cnt -= (A[c] & A[c - 1]) == 0;
cnt += ((A[c] ^ (1 << r)) & A[c - 1]) == 0;
}
A[c] ^= (1 << r);
cout << (cnt > 0 ? "No" : "Yes") << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[2][100005];
int ob = 0, x, y, n, t;
void solve() {
int d = (a[x][y] == 0) ? 1 : -1;
a[x][y] = 1 - a[x][y];
for (int i = -1; i <= 1; ++i) {
if (y + i >= n || y + i < 0) continue;
if (a[1 - x][y + i] == 1) ob += d;
}
}
int main() {
cin >> n >> t;
while (t--) {
cin >> x >> y;
x--;
y--;
solve();
if (ob > 0)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[2][1000000];
int main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int n, q;
cin >> n >> q;
int x, y;
int b = 0;
for (int i = 0; i < q; i++) {
cin >> x >> y;
x -= 1;
y -= 1;
int prev = a[x][y];
for (int r = x - 1; r <= x + 1; r++) {
for (int c = y - 1; c <= y + 1; c++) {
if (r < 0 || r > 1 || c < 0 || c > n - 1) continue;
if (r == x) continue;
if (a[r][c]) {
int flag = 0;
for (int t = r - 1; t >= r + 1; t++) {
if (r < 0 || r > 1 || c < 0 || c > n - 1)
continue;
else if (a[t][c]) {
flag = 1;
break;
}
}
if (flag) continue;
if (prev)
b--;
else
b++;
}
}
}
if (a[x][y])
a[x][y] = 0;
else
a[x][y] = 1;
if (b > 0)
cout << "NO" << '\n';
else
cout << "YES" << '\n';
}
}
|
#include <bits/stdc++.h>
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = int_fast64_t;
using ld = long double;
constexpr ll mod = 1e9 + 7;
constexpr ll Mod = 998244353;
constexpr ll MXN = 500000 + 100;
constexpr ld EPS = 1e-10;
constexpr ll inf = 3 * 1e18;
constexpr ll Inf = 15 * 1e8;
const vector<ll> dx{-1, 1, 0, 0}, dy{0, 0, -1, 1};
template <class T>
bool chmax(T& a, const T& b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
if (b < a) {
a = b;
return 1;
}
return 0;
}
ll read() {
ll u, k = scanf("%lld", &u);
return u;
}
string reads() {
string s;
cin >> s;
return s;
}
pair<ll, ll> readh(bool g = 0) {
pair<ll, ll> u;
ll k = scanf("%lld %lld", &u.first, &u.second);
if (g) u.first--, u.second--;
return u;
}
void printh(pair<ll, ll> t) { printf("%lld %lld\n", t.first, t.second); }
bool inarea(pair<ll, ll> t, ll h, ll w) {
return 0 <= t.first && t.first < h && 0 <= t.second && t.second < w;
}
ll gcd(ll i, ll j) { return j ? gcd(j, i % j) : i; }
ll mod_pow(ll x, ll n, ll p = mod) {
ll res = 1;
while (n > 0) {
if (n & 1) res = res * x % p;
x = x * x % p;
n >>= 1;
}
return res;
}
ll bitcount(ll x) {
ll sum = 0;
for (ll i = 0; i < 60; i++)
if ((1ll << i) & x) sum++;
return sum;
}
ll n, q;
ll a[2][200000];
ll b[200000];
set<ll> se, se2;
signed main() {
cin >> n >> q;
for (ll(i) = 0; (i) < (q); (i)++) {
ll t = read(), r = read();
t--;
r--;
if (a[t][r]) {
if (se.find(r) != se.end()) se.erase(r);
a[t][r] = 0;
if (r > 0 && a[!t][r - 1]) {
b[r - 1]--;
if (b[r - 1] == 0) se2.erase(r - 1);
}
if (r < n - 1 && a[!t][r + 1]) {
b[r]--;
if (b[r] == 0) se2.erase(r);
}
} else {
a[t][r] = 1;
if (a[0][r] && a[1][r]) se.insert(r);
if (r > 0 && a[!t][r - 1]) {
b[r - 1]++;
if (b[r - 1] >= 1) se2.insert(r - 1);
}
if (r < n - 1 && a[!t][r + 1]) {
b[r]++;
if (b[r] >= 1) se2.insert(r);
}
}
if (se.empty() && se2.empty())
cout << "Yes\n";
else
cout << "No\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, q;
int x, y;
int lu[100001][3], shu = 0;
int main() {
cin >> n >> q;
for (int i = 1; i <= q; i++) {
cin >> x >> y;
x--;
if (lu[y][x] == 0) {
lu[y][x] = 1;
if (lu[y - 1][1 - x] == 1) shu++;
if (lu[y + 1][1 - x] == 1) shu++;
if (lu[y][1 - x] == 1) shu++;
} else {
lu[y][x] = 0;
if (lu[y - 1][1 - x] == 1) shu--;
if (lu[y + 1][1 - x] == 1) shu--;
if (lu[y][1 - x] == 1) shu--;
}
if (shu == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 100000;
int a[3][N + 2];
int main() {
int ans, n, q, xf, x, y;
scanf("%d%d", &n, &q);
ans = 0;
while (q--) {
scanf("%d%d", &x, &y);
xf = x == 1 ? 2 : 1;
if (a[x][y]) {
ans -= a[xf][y - 1] + a[xf][y] + a[xf][y + 1];
} else {
ans += a[xf][y - 1] + a[xf][y] + a[xf][y + 1];
}
a[x][y] = !a[x][y];
if (ans == 0) {
printf("Yes\n");
} else {
printf("No\n");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, q, a[3][100010];
const int bux[] = {1, -1, 1, -1, 1, -1};
const int buy[] = {0, 0, 1, 1, -1, -1};
int main() {
scanf("%d%d", &n, &q);
memset(a, 0, sizeof(a));
int x, y, k = 0;
while (q--) {
scanf("%d%d", &x, &y);
if (a[x][y] == 1) {
for (int i = 0; i < 6; i++) {
int xx = x + bux[i], yy = y + buy[i];
if (xx >= 1 && xx <= 2 && yy >= 1 && yy <= n)
if (a[xx][yy] == 1) k--;
}
a[x][y] = 0;
} else {
for (int i = 0; i < 6; i++) {
int xx = x + bux[i], yy = y + buy[i];
if (xx >= 1 && xx <= 2 && yy >= 1 && yy <= n)
if (a[xx][yy] == 1) k++;
}
a[x][y] = 1;
}
if (k == 0)
puts("Yes");
else
puts("No");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1E5 + 7;
int dp[3][N];
int main() {
int n, m;
cin >> n >> m;
int flag = 0;
for (int i = 1; i <= m; i++) {
int x, y;
cin >> x >> y;
if (dp[x][y]) {
int x1 = x;
if (x == 1)
x1++;
else
x1--;
if (dp[x1][y]) flag--;
if (dp[x1][y + 1]) flag--;
if (dp[x1][y - 1]) flag--;
dp[x][y] = 0;
if (flag >= 1)
cout << "NO" << endl;
else
cout << "YES" << endl;
} else {
int x1 = x;
if (x == 1)
x1++;
else
x1--;
if (dp[x1][y]) flag++;
if (dp[x1][y + 1]) flag++;
if (dp[x1][y - 1]) flag++;
dp[x][y] = 1;
if (flag >= 1)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool maps[3][100002];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, Q;
cin >> n >> Q;
int cnt = 0;
while (Q--) {
int r, c;
cin >> r >> c;
maps[r][c] ^= true;
if (maps[r][c]) {
if (maps[3 - r][c - 1]) cnt++;
if (maps[3 - r][c]) cnt++;
if (maps[3 - r][c + 1]) cnt++;
} else {
if (maps[3 - r][c - 1]) cnt--;
if (maps[3 - r][c]) cnt--;
if (maps[3 - r][c + 1]) cnt--;
}
if (cnt)
cout << "NO\n";
else
cout << "YES\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 9;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int c = 0;
int arr[2][N] = {};
int n, qq;
cin >> n >> qq;
while (qq--) {
int x, y;
cin >> x >> y;
x %= 2;
if (arr[x][y] != 0) {
arr[x % 2][y] = 0;
for (int i = -1; i <= 1; i++) {
if (y + i >= 0 && arr[(x + 1) % 2][y + i] == 1) {
c--;
}
}
} else {
arr[x % 2][y] = 1;
for (int i = -1; i <= 1; i++) {
if (y + i >= 0 && arr[(x + 1) % 2][y + i] == 1) {
c++;
}
}
}
if (c == 0)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> b;
void build(vector<pair<int, int>> &a,
vector<pair<int, vector<pair<int, int>>>> &t, int u, int lt,
int rt) {
if (lt == rt) {
t[u].first = 1;
t[u].second.resize(1);
t[u].second[0] = a[lt];
b[lt] = u;
} else {
int med = (lt + rt) / 2;
build(a, t, 2 * u, lt, med);
build(a, t, 2 * u + 1, med + 1, rt);
t[u].first = 1;
t[u].second.resize(rt - lt + 1);
int i;
for (i = 0; i < rt - lt + 1; ++i) t[u].second[i] = make_pair(1, 1);
}
}
int main() {
int n, q, i, j;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> q;
b.resize(n);
vector<pair<int, int>> a(n, make_pair(1, 1));
vector<pair<int, vector<pair<int, int>>>> t(4 * n);
build(a, t, 1, 0, n - 1);
for (j = 0; j < q; ++j) {
int x, y, it = 0, it2;
cin >> y >> x;
y--;
x--;
it2 = y;
if (y == 0)
a[x].first = !a[x].first;
else
a[x].second = !a[x].second;
int u = b[x];
t[u].second[0] = a[x];
if (t[u].second[0].first == t[u].second[0].second &&
t[u].second[0].first == 0)
t[u].first = 0;
else
t[u].first = 1;
while (u > 1) {
if (u % 2 == 0) {
if (t[u].first == 0 || t[u + 1].first == 0) {
t[u / 2].first = 0;
} else {
if ((t[u].second[t[u].second.size() - 1].first == 1 &&
t[u + 1].second[0].first == 1) ||
(t[u].second[t[u].second.size() - 1].second == 1 &&
t[u + 1].second[0].second == 1))
t[u / 2].first = 1;
else
t[u / 2].first = 0;
}
t[u / 2].second[it] = a[x];
u /= 2;
} else {
if (t[u].first == 0 || t[u - 1].first == 0) {
t[(u - 1) / 2].first = 0;
} else {
if ((t[u - 1].second[t[u - 1].second.size() - 1].first == 1 &&
t[u].second[0].first == 1) ||
(t[u - 1].second[t[u - 1].second.size() - 1].second == 1 &&
t[u].second[0].second == 1))
t[(u - 1) / 2].first = 1;
else
t[(u - 1) / 2].first = 0;
}
it += t[u - 1].second.size();
t[(u - 1) / 2].second[it] = a[x];
u = (u - 1) / 2;
}
}
if (t[1].first == 1)
cout << "YES"
<< "\n";
else
cout << "NO"
<< "\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 100;
int bad[N][3];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
int obs = 0;
while (q--) {
int x, y;
cin >> x >> y;
swap(x, y);
if (y == 1) {
if (bad[x][y]) {
if (bad[x][2]) obs--;
if (x + 1 <= n && bad[x + 1][2]) obs--;
if (x - 1 >= 1 && bad[x - 1][2]) obs--;
} else {
if (bad[x][2]) obs++;
if (x + 1 <= n && bad[x + 1][2]) obs++;
if (x - 1 >= 1 && bad[x - 1][2]) obs++;
}
} else {
if (bad[x][y]) {
if (bad[x][1]) obs--;
if (x + 1 <= n && bad[x + 1][1]) obs--;
if (x - 1 >= 1 && bad[x - 1][1]) obs--;
} else {
if (bad[x][1]) obs++;
if (x + 1 <= n && bad[x + 1][1]) obs++;
if (x - 1 >= 1 && bad[x - 1][1]) obs++;
}
}
bad[x][y] ^= 1;
if (obs == 0)
cout << "Yes"
<< "\n";
else
cout << "No"
<< "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, q;
int ok[3][100005];
int conf;
void upd(int x, int y) {
int sgn = ok[x][y] ? -1 : 1;
conf += sgn * (ok[3 - x][y - 1] + ok[3 - x][y] + ok[3 - x][y + 1]);
ok[x][y] ^= 1;
}
int main(void) {
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cin >> n >> q;
while (q--) {
int x, y;
cin >> x >> y;
upd(x, y);
cout << (conf ? "No" : "Yes") << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, x, y, z, k, sol, sum, ans, l, r, xx, yy, b[1000000], m,
a[4][200000];
vector<long long> v1;
vector<long long> v2;
pair<long long, pair<long long, long long> > pp[1000000];
pair<long long, long long> p[1000000];
string s1, s2, s;
char c;
int main() {
cin >> n >> m;
long long no = 0;
for (int i = 0; i < m; i++) {
cin >> x >> y;
xx = 3 - x;
if ((a[x][y] == 1 && a[xx][y] == 1)) no--;
if ((y > 1 && (a[x][y] == 1 && a[xx][y - 1] == 1))) no--;
if ((a[x][y] == 1 && a[xx][y + 1] == 1)) no--;
a[x][y] ^= 1;
if ((a[x][y] == 1 && a[xx][y] == 1)) no++;
if ((y > 1 && (a[x][y] == 1 && a[xx][y - 1] == 1))) no++;
if ((a[x][y] == 1 && a[xx][y + 1] == 1)) no++;
if (no)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
bool blc[4][(int)1e5 + 70];
int main() {
int n, q;
scanf("%d%d", &n, &q);
int bad = 0;
while (q--) {
int r, c;
scanf("%d%d", &r, &c);
blc[r][c] ^= 1;
int dr = r ^ 3;
for (int j : {1, -1, 0}) {
if (blc[dr][c + j]) bad += (blc[r][c] ? 1 : -1);
}
puts((!bad ? "Yes" : "No"));
}
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, k, bp = 0, x, xx, y;
cin >> n >> k;
long long a[2][n];
for (long long i = 0; i < n; i++) {
a[0][i] = 1;
a[1][i] = 1;
}
for (long long i = 0; i < k; i++) {
cin >> x >> y;
x--;
y--;
xx = 1;
if (x == 1) xx = 0;
a[x][y] = !a[x][y];
if (a[x][y] == 0) {
if (y && a[xx][y - 1] == 0) bp++;
if (y != n - 1 && a[xx][y + 1] == 0) bp++;
if (a[xx][y] == 0) bp++;
} else {
if (y && a[xx][y - 1] == 0) bp--;
if (y != n - 1 && a[xx][y + 1] == 0) bp--;
if (a[xx][y] == 0) bp--;
}
if (bp == 0)
cout << "Yes\n";
else
cout << "No\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t = 1;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, k;
scanf("%d %d", &n, &k);
int blocked[2][100005] = {0};
int flag = 0;
while (k--) {
int x, y;
scanf("%d %d", &x, &y);
x--;
if (blocked[x][y]) {
blocked[x][y] = 0;
if (blocked[(x + 1) % 2][y - 1]) {
flag--;
}
if (blocked[(x + 1) % 2][y + 1]) {
flag--;
}
if (blocked[(x + 1) % 2][y]) {
flag--;
}
} else {
blocked[x][y] = 1;
if (blocked[(x + 1) % 2][y - 1]) {
flag++;
}
if (blocked[(x + 1) % 2][y + 1]) {
flag++;
}
if (blocked[(x + 1) % 2][y]) {
flag++;
}
}
if (flag == 0) {
printf("Yes\n");
} else {
printf("No\n");
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vv = vector<vector<T>>;
template <class T>
inline bool MX(T &l, const T &r) {
return l < r ? l = r, 1 : 0;
}
template <class T>
inline bool MN(T &l, const T &r) {
return l > r ? l = r, 1 : 0;
}
const ll MOD = 1e9 + 7;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout << fixed << setprecision(0);
int n, q;
cin >> n >> q;
vv<int> bd(2, vector<int>(n));
auto check = [&](int x) {
if (x < 0 || x + 1 >= n) return 0;
if ((bd[0][x] || bd[0][x + 1]) && (bd[1][x] || bd[1][x + 1])) return 1;
return 0;
};
int cnt = 0;
while (q--) {
int r, c;
cin >> r >> c;
--r;
--c;
for (int(d) = -2; (d) < (3); ++(d)) cnt -= check(c + d);
bd[r][c] ^= 1;
for (int(d) = -2; (d) < (3); ++(d)) cnt += check(c + d);
;
cout << (cnt ? "No" : "Yes") << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, q, blocks = 0;
cin >> n >> q;
bool flag = 1;
set<int> s;
while (q--) {
int r, c, l;
cin >> r >> c;
r--;
c--;
l = 2 * c + r;
if (s.count(2 * c + r)) {
s.erase(2 * c + r);
if (r == 0 && s.count(l + 1)) blocks--;
if (r == 0 && s.count(l - 1)) blocks--;
if (r == 0 && s.count(l + 3)) blocks--;
if (r == 1 && s.count(l - 1)) blocks--;
if (r == 1 && s.count(l - 3)) blocks--;
if (r == 1 && s.count(l + 1)) blocks--;
if (!blocks) {
flag = 1;
} else
flag = 0;
} else {
s.insert(2 * c + r);
if (r == 0 && s.count(l + 1)) blocks++;
if (r == 0 && s.count(l - 1)) blocks++;
if (r == 0 && s.count(l + 3)) blocks++;
if (r == 1 && s.count(l - 1)) blocks++;
if (r == 1 && s.count(l - 3)) blocks++;
if (r == 1 && s.count(l + 1)) blocks++;
if (blocks) {
flag = 0;
} else
flag = 1;
}
if (flag)
cout << "yes" << endl;
else
cout << "no" << endl;
}
}
|
#include <bits/stdc++.h>
const int N = (int)1e5;
int arr[2][N];
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
int n, q, bad = 0;
std::cin >> n >> q;
while (q--) {
int x, y;
std::cin >> x >> y;
--x, --y;
arr[x][y] ^= 1;
for (int j = std::max(0, y - 1); j <= std::min(n - 1, y + 1); j++)
if (arr[x ^ 1][j]) bad += arr[x][y] ? 1 : -1;
std::cout << (bad ? "No\n" : "Yes\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, q;
int b[100000][2];
int a[100000];
int c[5];
int main() {
cin >> n >> q;
for (int i = 0; i < n; i++) {
b[i][0] = 0;
b[i][1] = 0;
a[i] = 0;
}
c[0] = n - 1;
int s = 0;
for (int i = 0; i < q; i++) {
int y, x;
cin >> x >> y;
x--;
y--;
if (b[y][x] == 1) {
if (y == 0) {
if (b[y + 1][x] == 1) s--;
c[a[y]]--;
a[y]--;
c[a[y]]++;
} else if (y == n - 1) {
if (b[y - 1][x] == 1) s--;
c[a[y - 1]]--;
a[y - 1]--;
c[a[y - 1]]++;
} else {
if (b[y - 1][x] == 1) s--;
if (b[y + 1][x] == 1) s--;
c[a[y - 1]]--;
a[y - 1]--;
c[a[y - 1]]++;
c[a[y]]--;
a[y]--;
c[a[y]]++;
}
b[y][x] = 0;
} else {
if (y == 0) {
if (b[y + 1][x] == 1) s++;
c[a[y]]--;
a[y]++;
c[a[y]]++;
} else if (y == n - 1) {
if (b[y - 1][x] == 1) s++;
c[a[y - 1]]--;
a[y - 1]++;
c[a[y - 1]]++;
} else {
if (b[y + 1][x] == 1) s++;
if (b[y - 1][x] == 1) s++;
c[a[y - 1]]--;
a[y - 1]++;
c[a[y - 1]]++;
c[a[y]]--;
a[y]++;
c[a[y]]++;
}
b[y][x] = 1;
}
if (c[4] == 0 && c[3] == 0 && c[2] - s <= 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.