text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
int f = 1;
map<pair<int, int>, int> mp;
int cnt = 0;
for (int i = 0; i < q; i++) {
int r, c;
cin >> r >> c;
if (mp.find({r, c}) != mp.end()) {
mp.erase({r, c});
if (r == 1) {
if (mp.find({2, c}) != mp.end()) {
cnt--;
}
if (mp.find({2, c + 1}) != mp.end()) {
cnt--;
}
if (mp.find({2, c - 1}) != mp.end()) {
cnt--;
}
} else if (r == 2) {
if (mp.find({1, c}) != mp.end()) {
cnt--;
}
if (mp.find({1, c + 1}) != mp.end()) {
cnt--;
}
if (mp.find({1, c - 1}) != mp.end()) {
cnt--;
}
}
} else {
int x1, y1, x2, y2, x3, y3;
if (r == 2) {
x1 = 1;
x2 = 1;
x3 = 1;
y3 = c;
y1 = c - 1;
y2 = c + 1;
} else if (r == 1) {
x1 = 2;
x2 = 2;
x3 = 2;
y3 = c;
y1 = c - 1;
y2 = c + 1;
}
auto it1 = mp.find({x1, y1});
auto it2 = mp.find({x2, y2});
auto it3 = mp.find({x3, y3});
if (it1 != mp.end()) {
cnt++;
}
if (it2 != mp.end()) {
cnt++;
}
if (it3 != mp.end()) {
cnt++;
}
mp[{r, c}]++;
}
if (cnt > 0) {
cout << "No" << endl;
} else
cout << "Yes" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool compare(const pair<long long, long long>& a,
const pair<long long, long long>& b) {
if (a.first == b.first) return a.second < b.second;
return a.first < b.first;
}
bool sortbysec(const pair<long long, long long>& a,
const pair<long long, long long>& b) {
return a.second < b.second;
}
bool isprime(long long n) {
for (long long i = 2; i * i <= n; i++)
if (n % i == 0) return false;
return true;
}
signed main() {
long long t;
t = 1;
while (t--) {
long long n, q;
cin >> n >> q;
long long a[2][n];
for (long long i = 0; i < n; i++) {
a[0][i] = 0;
a[1][i] = 0;
}
long long bp = 0;
while (q--) {
long long x, y;
cin >> x >> y;
x--;
y--;
if (a[x][y] == 1) {
a[x][y] = 0;
for (long long i = -1; i <= 1; i++) {
if (y + i < 0 || y + i >= n) continue;
if (a[1 - x][y + i] == 1) bp--;
}
} else {
a[x][y] = 1;
for (long long i = -1; i <= 1; i++) {
if (y + i < 0 || y + i >= n) continue;
if (a[1 - x][y + i] == 1) bp++;
}
}
if (bp != 0)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[3][maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
int cnt = 0;
for (int i = 1; i <= q; i++) {
int fa = 1;
int r, c;
cin >> r >> c;
a[r][c] ^= 1;
if (a[r][c] == 1) {
if (r == 1) {
if (a[2][c] == 1) {
fa = 0;
cnt++;
}
if (a[2][c - 1] == 1) {
fa = 0;
cnt++;
}
if (a[2][c + 1] == 1) {
fa = 0;
cnt++;
}
}
if (r == 2) {
if (a[1][c] == 1) {
fa = 0;
cnt++;
}
if (a[1][c - 1] == 1) {
fa = 0;
cnt++;
}
if (a[1][c + 1] == 1) {
fa = 0;
cnt++;
}
}
} else {
if (r == 1) {
if (a[2][c] == 1) {
cnt--;
}
if (a[2][c - 1] == 1) {
cnt--;
}
if (a[2][c + 1] == 1) {
cnt--;
}
}
if (r == 2) {
if (a[1][c] == 1) {
cnt--;
}
if (a[1][c - 1] == 1) {
cnt--;
}
if (a[1][c + 1] == 1) {
cnt--;
}
}
}
if (!fa || cnt) {
cout << "NO" << endl;
} else
cout << "YES" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
cin >> n >> q;
set<pair<int, int>> s;
map<pair<int, int>, set<pair<int, int>>> prob;
pair<int, int> x = make_pair(2, n);
for (int i = 0; i < q; i++) {
int r, c;
cin >> r >> c;
pair<int, int> p = make_pair(r, c);
if (s.count(p)) {
s.erase(p);
if (r == 1) {
prob.erase(p);
} else {
auto it = prob.find(make_pair(1, c));
if (it != prob.end()) {
it->second.erase(p);
if (it->second.empty()) {
prob.erase(it);
}
}
it = prob.find(make_pair(1, c + 1));
if (it != prob.end()) {
it->second.erase(p);
if (it->second.empty()) {
prob.erase(it);
}
}
it = prob.find(make_pair(1, c - 1));
if (it != prob.end()) {
it->second.erase(p);
if (it->second.empty()) {
prob.erase(it);
}
}
}
} else {
s.insert(p);
if (r == 1) {
if (s.count(make_pair(2, c))) {
prob[p].insert(make_pair(2, c));
}
if (s.count(make_pair(2, c - 1))) {
prob[p].insert(make_pair(2, c - 1));
}
if (s.count(make_pair(2, c + 1))) {
prob[p].insert(make_pair(2, c + 1));
}
} else {
if (s.count(make_pair(1, c))) {
prob[make_pair(1, c)].insert(p);
}
if (s.count(make_pair(1, c - 1))) {
prob[make_pair(1, c - 1)].insert(p);
}
if (s.count(make_pair(1, c + 1))) {
prob[make_pair(1, c + 1)].insert(p);
}
}
}
if (prob.empty() && !s.count(x)) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
long long exp(long long x, long long y) {
long long res = 1;
while (y) {
if (y & 1) res = res * x;
x = x * x;
y >>= 1;
}
return res;
}
long long gcd(long long a, long long b) {
if (b == 0) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); }
bool prime(long long n) {
if (n < 2) return 0;
for (int i = 2; i * i <= n; i++)
if (n % i == 0) return 0;
return 1;
}
int const MAXN = 1e5 + 5;
int fx[MAXN], fy[MAXN];
vector<vector<int>> v(2, vector<int>(MAXN));
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
;
int T = 1;
while (T--) {
int n, q;
cin >> n >> q;
set<pair<int, int>> s1, s2;
int p = 0;
while (q--) {
int r, c;
cin >> r >> c;
if (r == 1) {
if (s1.find({r, c}) == s1.end()) {
s1.insert({r, c});
if (s2.find({2, c - 1}) != s2.end() && c > 1) p++;
if (s2.find({2, c + 1}) != s2.end() && c < n) p++;
if (s2.find({2, c}) != s2.end()) p++;
} else {
s1.erase({r, c});
if (s2.find({2, c - 1}) != s2.end() && c > 1) p--;
if (s2.find({2, c + 1}) != s2.end() && c < n) p--;
if (s2.find({2, c}) != s2.end()) p--;
}
} else {
if (s2.find({r, c}) == s2.end()) {
s2.insert({r, c});
if (s1.find({1, c - 1}) != s1.end() && c > 1) p++;
if (s1.find({1, c + 1}) != s1.end() && c < n) p++;
if (s1.find({1, c}) != s1.end()) p++;
} else {
s2.erase({r, c});
if (s1.find({1, c - 1}) != s1.end() && c > 1) p--;
if (s1.find({1, c + 1}) != s1.end() && c < n) p--;
if (s1.find({1, c}) != s1.end()) p--;
}
}
if (p)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target( \
"sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("fast-math")
using namespace std;
const long long MOD = (long long)1e9 + 7;
const long long MOD1 = 2286661337;
const long long MOD2 = 998244353;
const int INF = (int)1e9 + 7;
const double EPS = 1e-7;
const int N = (int)1e5;
int n, q, cnt_and, cnt_or;
bool used[2][N], and_[N];
signed main() {
scanf("%d%d", &n, &q);
for (int i = 0; i < q; ++i) {
int r, c;
scanf("%d%d", &r, &c);
--r, --c;
if (used[r][c]) {
used[r][c] = false;
if (and_[c]) {
--cnt_and;
and_[c] = false;
}
if (c) {
if (used[r ^ 1][c - 1]) {
--cnt_or;
}
}
if (c < n - 1) {
if (used[r ^ 1][c + 1]) {
--cnt_or;
}
}
} else {
used[r][c] = true;
if (used[r ^ 1][c]) {
++cnt_and;
and_[c] = true;
}
if (c) {
if (used[r ^ 1][c - 1]) {
++cnt_or;
}
}
if (c < n - 1) {
if (used[r ^ 1][c + 1]) {
++cnt_or;
}
}
}
if (cnt_and || used[0][0] || used[1][n - 1] || cnt_or) {
printf("No\n");
} else {
printf("Yes\n");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000 * 100 + 5;
const long long inf = 9223372036854775807;
int n, q, cnt, mark[3][maxn];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
;
cin >> n >> q;
for (int i = 1; i <= q; i++) {
int x, y;
cin >> x >> y;
if (mark[x][y] == 0) {
mark[x][y] = 1;
if (mark[3 - x][y] == 1) cnt++;
if (mark[3 - x][y - 1] == 1) cnt++;
if (mark[3 - x][y + 1] == 1) cnt++;
} else {
mark[x][y] = 0;
if (mark[3 - x][y] == 1) cnt--;
if (mark[3 - x][y - 1] == 1) cnt--;
if (mark[3 - x][y + 1] == 1) cnt--;
}
if (cnt > 0)
cout << "No";
else
cout << "Yes";
cout << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int vis[3][100005];
int main() {
int t = 1;
while (t--) {
int n, q, r, c;
cin >> n >> q;
int ans = 0;
while (q--) {
cin >> r >> c;
if (r == 1) {
if (vis[r][c] == 0) {
vis[r][c] = 1;
if (vis[2][c - 1]) {
ans += 2;
}
if (vis[2][c]) {
ans += 2;
}
if (vis[2][c + 1]) {
ans += 2;
}
} else {
vis[r][c] = 0;
if (vis[2][c - 1]) {
ans -= 2;
}
if (vis[2][c]) {
ans -= 2;
}
if (vis[2][c + 1]) {
ans -= 2;
}
}
} else {
if (vis[r][c] == 0) {
vis[r][c] = 1;
if (vis[1][c - 1]) {
ans += 2;
}
if (vis[1][c]) {
ans += 2;
}
if (vis[1][c + 1]) {
ans += 2;
}
} else {
vis[r][c] = 0;
if (vis[1][c - 1]) {
ans -= 2;
}
if (vis[1][c]) {
ans -= 2;
}
if (vis[1][c + 1]) {
ans -= 2;
}
}
}
cout << (ans ? "No\n" : "Yes\n");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, q, counter, x, y;
bool lava[5][100005];
int main() {
cin >> n >> q;
while (q--) {
cin >> x >> y;
if (lava[x][y]) {
if (lava[3 - x][y]) counter--;
if (lava[3 - x][y - 1]) counter--;
if (lava[3 - x][y + 1]) counter--;
} else {
if (lava[3 - x][y]) counter++;
if (lava[3 - x][y - 1]) counter++;
if (lava[3 - x][y + 1]) counter++;
}
lava[x][y] = !lava[x][y];
if (counter == 0)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
int blc = 0;
map<int, bool> up;
map<int, bool> dow;
while (q--) {
int r, c;
cin >> r >> c;
if (r == 1) {
if (dow.count(c)) {
dow.erase(c);
for (int b = c - 1; b <= c + 1; b++) {
if (up.count(b)) {
blc--;
}
}
if (blc) {
cout << "No\n";
} else {
cout << "Yes\n";
}
} else {
dow[c] = true;
for (int b = c - 1; b <= c + 1; b++) {
if (up.count(b)) {
blc++;
}
}
if (blc) {
cout << "No\n";
} else {
cout << "Yes\n";
}
}
} else {
if (up.count(c)) {
up.erase(c);
for (int b = c - 1; b <= c + 1; b++) {
if (dow.count(b)) {
blc--;
}
}
if (blc) {
cout << "No\n";
} else {
cout << "Yes\n";
}
} else {
up[c] = true;
for (int b = c - 1; b <= c + 1; b++) {
if (dow.count(b)) {
blc++;
}
}
if (blc) {
cout << "No\n";
} else {
cout << "Yes\n";
}
}
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
int a[2][n];
memset(a, 0, sizeof a);
int beta = 0;
while (q--) {
int x, y;
cin >> x >> y;
x--;
y--;
if (a[x][y]) {
a[x][y] = !a[x][y];
for (int i = -1; i <= 1; i++) {
if (y + i >= 0 && y + i < n && a[!x][y + i]) {
beta--;
}
}
} else {
a[x][y] = !a[x][y];
for (int i = -1; i <= 1; i++) {
if (y + i >= 0 && y + i < n && a[!x][y + i]) {
beta++;
}
}
}
if (!beta) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long unsigned int blockedPaths = 0;
void checkBlocks(vector<vector<bool> > matrix, int row, int col, int size,
int incdec) {
if (row == 1) {
if (col - 1 >= 0 && matrix[row + 1][col - 1]) blockedPaths += incdec;
if (col + 1 >= 0 && matrix[row + 1][col + 1]) blockedPaths += incdec;
if (matrix[row + 1][col]) blockedPaths += incdec;
} else {
if (col - 1 >= 0 && matrix[row - 1][col - 1]) blockedPaths += incdec;
if (col + 1 >= 0 && matrix[row - 1][col + 1]) blockedPaths += incdec;
if (matrix[row - 1][col]) blockedPaths += incdec;
}
}
int main() {
int n, q, x, y;
cin >> n >> q;
vector<vector<bool> > grid(4, vector<bool>(n + 2, 0));
for (int qitr = 0; qitr < q; qitr++) {
cin >> x >> y;
grid[x][y] = !grid[x][y];
if (grid[x][y]) {
checkBlocks(grid, x, y, n, 1);
} else {
checkBlocks(grid, x, y, n, -1);
}
blockedPaths >= 1 ? cout << "No\n" : cout << "Yes\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
int n, qu;
bool a[2][N + 1];
set<pair<int, int> > s;
void erase(pair<int, int> x) {
set<pair<int, int> >::iterator fd = s.find(x);
if (fd != s.end()) s.erase(fd);
}
int main() {
cin >> n >> qu;
while (qu--) {
int x, y;
cin >> x >> y;
a[x - 1][y] ^= 1;
x = y;
if (a[0][x] && a[1][x]) s.insert(make_pair(x, 0));
if (x > 1 && (a[0][x - 1] && a[1][x] || a[1][x - 1] && a[0][x]))
s.insert(make_pair(x - 1, x));
if (x < n && (a[0][x + 1] && a[1][x] || a[1][x + 1] && a[0][x]))
s.insert(make_pair(x, x + 1));
if (!(a[0][x] && a[1][x])) erase(make_pair(x, 0));
if (!(x > 1 && (a[0][x - 1] && a[1][x] || a[1][x - 1] && a[0][x])))
erase(make_pair(x - 1, x));
if (!(x < n && (a[0][x + 1] && a[1][x] || a[1][x + 1] && a[0][x])))
erase(make_pair(x, x + 1));
puts(s.size() ? "No" : "Yes");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 2e5 + 7;
void my_dbg() { cout << endl; }
template <typename Arg, typename... Args>
void my_dbg(Arg A, Args... B) {
cout << ' ' << A;
my_dbg(B...);
}
int main() {
int n, q;
scanf("%d", &n), scanf("%d", &q);
int a[2][n + 2], b = 0;
for (int i = 0; i < (int)n + 2; i++) a[0][i] = a[1][i] = 0;
for (int i = 0; i < (int)q; i++) {
int r, c;
scanf("%d", &r), scanf("%d", &c);
r--;
if (a[r][c]) {
b -= (a[1 - r][c - 1] + a[1 - r][c] + a[1 - r][c + 1]);
a[r][c] = 0;
} else {
b += a[1 - r][c - 1] + a[1 - r][c] + a[1 - r][c + 1];
a[r][c] = 1;
}
if (b)
printf("NO\n");
else
printf("YES\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(0);
;
long long n;
cin >> n;
long long query;
cin >> query;
long long stop = 0;
map<pair<long long, long long>, long long> mp;
set<pair<long long, long long> > st;
while (query--) {
long long x, y;
cin >> x >> y;
if (st.count({x, y})) {
if (x == 1 && st.count({x + 1, y - 1})) stop--;
if (x == 1 && st.count({x + 1, y})) stop--;
if (x == 1 && st.count({x + 1, y + 1})) stop--;
if (x == 2 && st.count({x - 1, y - 1})) stop--;
if (x == 2 && st.count({x - 1, y})) stop--;
if (x == 2 && st.count({x - 1, y + 1})) stop--;
st.erase({x, y});
} else if (x == 1) {
if (st.count({x + 1, y})) stop++;
if (st.count({x + 1, y - 1})) stop++;
if (st.count({x + 1, y + 1})) stop++;
st.insert({x, y});
} else if (x == 2) {
if (st.count({x - 1, y})) stop++;
if (st.count({x - 1, y - 1})) stop++;
if (st.count({x - 1, y + 1})) stop++;
st.insert({x, y});
}
if (stop == 0)
cout << "YES\n";
else
cout << "NO\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 50;
int a1[maxn];
int a2[maxn];
int n, q;
int main() {
scanf("%d%d", &n, &q);
int cnt = 0;
for (int i = 1; i <= q; i++) {
int x, y;
scanf("%d%d", &x, &y);
if (x == 1) {
if (a1[y] == 0) {
if (a2[y - 1]) cnt++;
if (a2[y]) cnt++;
if (a2[y + 1]) cnt++;
a1[y] = 1;
} else {
if (a2[y - 1]) cnt--;
if (a2[y]) cnt--;
if (a2[y + 1]) cnt--;
a1[y] = 0;
}
}
if (x == 2) {
if (a2[y] == 0) {
if (a1[y - 1]) cnt++;
if (a1[y]) cnt++;
if (a1[y + 1]) cnt++;
a2[y] = 1;
} else {
if (a1[y - 1]) cnt--;
if (a1[y]) cnt--;
if (a1[y + 1]) cnt--;
a2[y] = 0;
}
}
if (cnt)
printf("No\n");
else
printf("Yes\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using std::cerr;
using std::cin;
using std::cout;
using std::pair;
using std::string;
using std::vector;
using ll = long long;
using ld = long double;
const int INF = 1e9 + 1;
signed main() {
std::ios_base::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int n, q;
cin >> n >> q;
vector<vector<int>> v(2, vector<int>(n));
int cur = 0;
vector<pair<int, int>> move = {{1, 1}, {1, 0}, {1, -1}};
for (int i = 0; i < q; ++i) {
int r, c;
cin >> r >> c;
--r, --c;
for (auto p : move) {
int nr = (r + p.first) % 2;
int nc = c + p.second;
if (nc < 0 || nc >= n) continue;
if (!v[r][c])
cur += v[nr][nc];
else
cur -= v[nr][nc];
}
v[r][c] ^= 1;
if (cur == 0)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int mod = (long long int)1e9 + 7;
int main() {
set<pair<long long int, long long int> > lava;
set<pair<pair<long long int, long long int>,
pair<long long int, long long int> > >
block;
long long int i, j, n, q, r, c;
cin >> n >> q;
for (i = 0; i < q; i++) {
cin >> r >> c;
if (lava.find({r, c}) == lava.end()) {
lava.insert({r, c});
if (lava.find({r + 1, c - 1}) != lava.end())
block.insert({{r, c}, {r + 1, c - 1}});
if (lava.find({r + 1, c}) != lava.end())
block.insert({{r, c}, {r + 1, c}});
if (lava.find({r + 1, c + 1}) != lava.end())
block.insert({{r, c}, {r + 1, c + 1}});
if (lava.find({r - 1, c - 1}) != lava.end())
block.insert({{r - 1, c - 1}, {r, c}});
if (lava.find({r - 1, c}) != lava.end())
block.insert({{r - 1, c}, {r, c}});
if (lava.find({r - 1, c + 1}) != lava.end())
block.insert({{r - 1, c + 1}, {r, c}});
} else {
lava.erase({r, c});
block.erase({{r, c}, {r + 1, c - 1}});
block.erase({{r, c}, {r + 1, c}});
block.erase({{r, c}, {r + 1, c + 1}});
block.erase({{r - 1, c - 1}, {r, c}});
block.erase({{r - 1, c}, {r, c}});
block.erase({{r - 1, c + 1}, {r, c}});
}
if (block.size() == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, T, r, c, cnt, a[2][100005];
int main() {
scanf("%d %d", &n, &T);
while (T--) {
scanf("%d %d", &r, &c);
--r;
if (!a[r][c]) {
a[r][c] = 1;
cnt += a[r ^ 1][c - 1] + a[r ^ 1][c] + a[r ^ 1][c + 1];
} else {
cnt -= a[r ^ 1][c - 1] + a[r ^ 1][c] + a[r ^ 1][c + 1];
a[r][c] = 0;
}
puts(cnt ? "No" : "Yes");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool blocks[4][100005];
int n, q, blocking = 0;
void change(int x, int y) {
blocks[x][y] = !blocks[x][y];
if (!blocks[x][y] && blocks[x - 1][y]) blocking--;
if (!blocks[x][y] && blocks[x + 1][y]) blocking--;
if (!blocks[x][y] && blocks[x + 1][y + 1]) blocking--;
if (!blocks[x][y] && blocks[x - 1][y + 1]) blocking--;
if (!blocks[x][y] && blocks[x + 1][y - 1]) blocking--;
if (!blocks[x][y] && blocks[x - 1][y - 1]) blocking--;
if (blocks[x][y] && blocks[x - 1][y]) blocking++;
if (blocks[x][y] && blocks[x + 1][y]) blocking++;
if (blocks[x][y] && blocks[x + 1][y + 1]) blocking++;
if (blocks[x][y] && blocks[x - 1][y + 1]) blocking++;
if (blocks[x][y] && blocks[x + 1][y - 1]) blocking++;
if (blocks[x][y] && blocks[x - 1][y - 1]) blocking++;
}
int main() {
cin >> n >> q;
int x, y;
while (q--) {
cin >> x >> y;
change(x, y);
if (blocking == 0)
cout << "YES" << '\n';
else
cout << "NO" << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, q, r, c, j, k = 0;
cin >> n >> q;
vector<vector<int> > a(2, vector<int>(n, 1));
for (i = 0; i < q; i++) {
cin >> r >> c;
r--;
c--;
if (a[r][c] == 0)
a[r][c] = 1;
else
a[r][c] = 0;
bool p = 1;
if (a[r][c] == 0) {
if (r == 0) {
if (c - 1 >= 0 && a[1][c - 1] == 0) k++;
if (a[1][c] == 0) k++;
if (c + 1 < n && a[1][c + 1] == 0) k++;
} else {
if ((c - 1 >= 0 && a[0][c - 1] == 0)) k++;
if (a[0][c] == 0) k++;
if (c + 1 < n && a[0][c + 1] == 0) k++;
}
} else {
if (r == 0) {
if ((c - 1 >= 0 && a[1][c - 1] == 0)) k--;
if (a[1][c] == 0) k--;
if (c + 1 < n && a[1][c + 1] == 0) k--;
} else {
if ((c - 1 >= 0 && a[0][c - 1] == 0)) k--;
if (a[0][c] == 0) k--;
if (c + 1 < n && a[0][c + 1] == 0) k--;
}
}
if (k == 0)
cout << "Yes" << '\n';
else
cout << "No" << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int MOD1 = 1000000007;
long long int MOD2 = 998244353;
void yes() { cout << "YES" << endl; }
void no() { cout << "NO" << endl; }
long long int gcd(long long int a, long long int b) {
if (a == 0) return b;
return gcd(b % a, a);
}
long long int lcm(long long int a, long long int b) {
return (a * b / (gcd(a, b)));
}
void solve() {
long long int n, q;
cin >> n >> q;
set<pair<long long int, long long int> > st;
long long int count = 0;
while (q--) {
long long int r, c;
cin >> r >> c;
if (!st.count({r, c})) {
st.insert({r, c});
long long int rw = (r == 1) ? 2 : 1;
if (st.count({rw, c})) count++;
if (st.count({rw, c - 1})) count++;
if (st.count({rw, c + 1})) count++;
} else {
st.erase({r, c});
long long int rw = (r == 1) ? 2 : 1;
if (st.count({rw, c})) count--;
if (st.count({rw, c - 1})) count--;
if (st.count({rw, c + 1})) count--;
}
if (count == 0)
yes();
else
no();
}
}
int main(int argc, const char* argv[]) {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long int tests = 1;
while (tests--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int st[2][100005];
int main() {
int n, q, r, c;
scanf("%d%d", &n, &q);
int cur = 0;
for (int i = 0; i < q; i++) {
scanf("%d%d", &r, &c);
r %= 2;
if (st[r][c] == 0) {
st[r][c] = 1;
if (st[r ^ 1][c] == 1) cur++;
if (st[r ^ 1][c - 1] == 1) cur++;
if (st[r ^ 1][c + 1] == 1) cur++;
} else {
st[r][c] = 0;
if (st[r ^ 1][c] == 1) cur--;
if (st[r ^ 1][c - 1] == 1) cur--;
if (st[r ^ 1][c + 1] == 1) cur--;
}
printf("%s\n", (cur ? "No" : "Yes"));
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void oj() {}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
;
oj();
long long x, y, n, q;
map<pair<long long, long long>, bool> mp;
long long cnt = 0;
cin >> n >> q;
for (long long i = 0; i < q; i++) {
cin >> x >> y;
x--;
y--;
if (mp[{x, y}])
mp[{x, y}] = false;
else
mp[{x, y}] = true;
for (long long i = -1; i <= 1; i++) {
if (mp[{1 - x, y + i}]) {
if (mp[{x, y}])
cnt++;
else
cnt--;
}
}
(cnt <= 0 ? cout << "Yes" : cout << "No");
cout << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int mk[2][100100];
int main() {
int n, q;
scanf("%d%d", &n, &q);
int ans = 0;
while (q--) {
int x, y;
scanf("%d%d", &x, &y);
x--;
int cnt = 0;
for (int i = 0; i < 3; i++) {
if (y + i - 1 >= 1 && y + i - 1 <= n) {
if (mk[x ^ 1][y + i - 1]) cnt++;
}
}
if (mk[x][y])
ans -= cnt;
else
ans += cnt;
mk[x][y] ^= 1;
if (!ans)
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int m[3][200005], l[200005];
int main() {
int n, q, i, j, h = 0, r, c;
cin >> n >> q;
for (i = 1; i <= n; i++) {
m[1][i] = 0;
m[2][i] = 0;
l[i] = 0;
}
while (q--) {
cin >> r >> c;
if (m[r][c] == 0)
m[r][c] = 1;
else
m[r][c] = 0;
if (c == 1) c++;
if (c == n) c--;
if ((m[1][c] == 0 && m[1][c - 1] == 0) ||
(m[2][c] == 0 && m[2][c - 1] == 0)) {
if (l[c] == 1) {
l[c] = 0;
h--;
}
} else {
if (l[c] == 0) {
l[c] = 1;
h++;
}
}
if ((m[1][c] == 0 && m[1][c + 1] == 0) ||
(m[2][c] == 0 && m[2][c + 1] == 0)) {
if (l[c + 1] == 1) {
l[c + 1] = 0;
h--;
}
} else {
if (l[c + 1] == 0) {
l[c + 1] = 1;
h++;
}
}
if (h == 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int read() {
char x = getchar();
int ans = 0, flag = 1;
while (!isdigit(x))
if (x == '-')
flag = -1, x = getchar();
else
x = getchar();
while (isdigit(x)) ans = ans * 10 + x - '0', x = getchar();
return ans * flag;
}
int n, q, a[100005], b[100005];
bool vis[10][110005], cnt = 0;
signed main() {
cin >> n >> q;
for (int i = 1; i <= q; i++) cin >> a[i] >> b[i];
int cnt = 0;
for (int i = 1; i <= q; i++) {
int x = a[i] - 1, y = b[i];
if (!vis[x][y]) {
cnt += vis[x ^ 1][y - 1] + vis[x ^ 1][y] + vis[x ^ 1][y + 1];
vis[x][y] = 1;
} else {
cnt -= vis[x ^ 1][y - 1] + vis[x ^ 1][y] + vis[x ^ 1][y + 1];
vis[x][y] = 0;
}
if (cnt >= 1)
puts("No");
else
puts("Yes");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long powermodm(long long x, long long n, long long M) {
long long result = 1;
while (n > 0) {
if (n % 2 == 1) result = (result * x) % M;
x = (x * x) % M;
n = n / 2;
}
return result;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long n, q;
cin >> n >> q;
long long arr[2][n];
for (long long i = 0; i < n; i++) {
for (long long j = 0; j < 2; j++) {
arr[j][i] = 0;
}
}
set<pair<pair<long long, long long>, pair<long long, long long>>> st;
while (q--) {
long long r, c;
cin >> r >> c;
r--, c--;
if (arr[r][c] == 1) {
if (r == 0) {
if (st.count({{r, c}, {r + 1, c - 1}})) {
st.erase({{r, c}, {r + 1, c - 1}});
}
if (st.count({{r, c}, {r + 1, c}})) {
st.erase({{r, c}, {r + 1, c}});
}
if (st.count({{r, c}, {r + 1, c + 1}})) {
st.erase({{r, c}, {r + 1, c + 1}});
}
if (st.count({{r + 1, c - 1}, {r, c}})) {
st.erase({{r + 1, c - 1}, {r, c}});
}
if (st.count({{r + 1, c}, {r, c}})) {
st.erase({{r + 1, c}, {r, c}});
}
if (st.count({{r + 1, c + 1}, {r, c}})) {
st.erase({{r + 1, c + 1}, {r, c}});
}
} else {
if (st.count({{r, c}, {r - 1, c - 1}})) {
st.erase({{r, c}, {r - 1, c - 1}});
}
if (st.count({{r, c}, {r - 1, c}})) {
st.erase({{r, c}, {r - 1, c}});
}
if (st.count({{r, c}, {r - 1, c + 1}})) {
st.erase({{r, c}, {r - 1, c + 1}});
}
if (st.count({{r - 1, c - 1}, {r, c}})) {
st.erase({{r - 1, c - 1}, {r, c}});
}
if (st.count({{r - 1, c}, {r, c}})) {
st.erase({{r - 1, c}, {r, c}});
}
if (st.count({{r - 1, c + 1}, {r, c}})) {
st.erase({{r - 1, c + 1}, {r, c}});
}
}
arr[r][c] = 0;
} else {
if (r == 0) {
if (c - 1 >= 0 && arr[r + 1][c - 1] == 1) {
st.insert({{r, c}, {r + 1, c - 1}});
}
if (arr[r + 1][c] == 1) {
st.insert({{r, c}, {r + 1, c}});
}
if (c + 1 < n && arr[r + 1][c + 1] == 1) {
st.insert({{r, c}, {r + 1, c + 1}});
}
} else {
if (c - 1 >= 0 && arr[r - 1][c - 1] == 1) {
st.insert({{r, c}, {r - 1, c - 1}});
}
if (arr[r - 1][c] == 1) {
st.insert({{r, c}, {r - 1, c}});
}
if (c + 1 < n && arr[r - 1][c + 1] == 1) {
st.insert({{r, c}, {r - 1, c + 1}});
}
}
arr[r][c] = 1;
}
cout << ((st.size() == 0) ? "Yes" : "No") << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int LEN = 100000;
struct fastio {
int it, len;
char s[LEN + 5];
fastio() { it = len = 0; }
char get() {
if (it < len) return s[it++];
it = 0, len = fread(s, 1, LEN, stdin);
return len ? s[it++] : EOF;
}
bool notend() {
char c;
for (c = get(); c == ' ' || c == '\n'; c = get())
;
if (it) it--;
return c != EOF;
}
void put(char c) {
if (it == LEN) fwrite(s, 1, LEN, stdout), it = 0;
s[it++] = c;
}
void flush() { fwrite(s, 1, it, stdout); }
} buff, bufo;
inline int getint() {
char c;
int res = 0, sig = 1;
for (c = buff.get(); c < '0' || c > '9'; c = buff.get())
if (c == '-') sig = -1;
for (; c >= '0' && c <= '9'; c = buff.get()) res = res * 10 + (c - '0');
return sig * res;
}
inline long long getll() {
char c;
long long res = 0, sig = 1;
for (c = buff.get(); c < '0' || c > '9'; c = buff.get())
if (c == '-') sig = -1;
for (; c >= '0' && c <= '9'; c = buff.get()) res = res * 10 + (c - '0');
return sig * res;
}
inline void putint(int x, char suf) {
if (!x)
bufo.put('0');
else {
if (x < 0) bufo.put('-'), x = -x;
int k = 0;
char s[15];
while (x) {
s[++k] = x % 10 + '0';
x /= 10;
}
for (; k; k--) bufo.put(s[k]);
}
bufo.put(suf);
}
inline void putll(long long x, char suf) {
if (!x)
bufo.put('0');
else {
if (x < 0) bufo.put('-'), x = -x;
int k = 0;
char s[25];
while (x) {
s[++k] = x % 10 + '0';
x /= 10;
}
for (; k; k--) bufo.put(s[k]);
}
bufo.put(suf);
}
inline char get_char() {
char c;
for (c = buff.get(); c == ' ' || c == '\n'; c = buff.get())
;
return c;
}
int n, q, cnt;
bool lava[2][100005];
int main() {
n = getint(), q = getint();
for (int i = 1; i <= q; i++) {
int r = getint() - 1, c = getint();
if (lava[r][c]) {
for (int j = c - 1; j <= c + 1; j++) cnt -= lava[r ^ 1][j];
} else {
for (int j = c - 1; j <= c + 1; j++) cnt += lava[r ^ 1][j];
}
lava[r][c] ^= 1;
puts(cnt ? "No" : "Yes");
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long a[2][100000] = {};
long problem(long x, long y) {
int z = 0;
x = (x + 1) % 2;
if (a[x][y - 1] == 1) {
z++;
}
if (a[x][y + 1] == 1) {
z++;
}
if (a[x][y] == 1) {
z++;
}
return z;
}
int main() {
long long int t, n, q, x, y, i, ii, proble = 0, z;
cin >> n >> q;
while (q--) {
cin >> x >> y;
x--;
if (a[x][y] == 1) {
proble -= problem(x, y);
a[x][y] = 0;
} else {
a[x][y] = 1;
proble += problem(x, y);
}
if (proble == 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q, a, b;
cin >> n >> q;
vector<vector<int>> v(2, vector<int>(n));
int bl = 0;
for (int i = 0; i < q; ++i) {
cin >> a >> b;
--a, --b;
v[a][b] = !v[a][b];
int d = v[a][b];
if (d == 0) --d;
for (int j = -1; j <= 1; ++j) {
if (b + j >= 0 && b + j < n && v[!a][b + j]) bl += d;
}
if (bl)
cout << "No\n";
else
cout << "Yes\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &t) {
t = 0;
char ch = getchar();
int f = 1;
while (ch < '0' || ch > '9') {
if (ch == '-') f = -1;
ch = getchar();
}
do {
(t *= 10) += ch - '0';
ch = getchar();
} while ('0' <= ch && ch <= '9');
t *= f;
}
const int maxn = (1e5) + 10;
int n, q, ans;
bool d[2][maxn];
int main() {
read(n);
read(q);
int x, y, delta;
while (q--) {
read(x);
read(y);
x--;
if (d[x][y])
delta = -1;
else
delta = 1;
d[x][y] ^= 1;
for (int i = -1; i <= 1; i++)
if (d[x ^ 1][y + i]) ans += delta;
if (!ans)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<vector<int>> v(3, vector<int>(n + 1, -1));
int now = 0;
while (q--) {
int r, c;
cin >> r >> c;
v[r][c] = -v[r][c];
for (int i = max(1, c - 1); i <= min(n, c + 1); i++)
if (v[3 - r][i] == 1) now += v[r][c];
if (now == 0)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long n, q, cnt, visited[3][100009], i, row, r, c;
int main() {
cin >> n >> q;
cnt = 0;
memset(visited, 0, sizeof visited);
for (i = 0; i < q; i++) {
cin >> r >> c;
row = (r % 2) + 1;
if (!visited[r][c]) {
if (c > 1 && visited[row][c - 1]) {
cnt++;
}
if (visited[row][c]) cnt++;
if (c < n && visited[row][c + 1]) cnt++;
visited[r][c] = 1;
} else if (visited[r][c]) {
if (c > 1 && visited[row][c - 1]) cnt--;
if (visited[row][c]) cnt--;
if (c < n && visited[row][c + 1]) cnt--;
visited[r][c] = 0;
}
if (cnt == 0)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
vector<vector<int>> g;
vector<vector<int>> dir = {{1, -1}, {1, 0}, {1, 1}, {-1, -1}, {-1, 0}, {-1, 1}};
int n, q;
int get(int r, int c) {
int res = 0;
for (vector<int> x : dir) {
int nr = r + x[0];
int nc = c + x[1];
if (nr < 0 || nr == 2 || nc < 0 || nc == n) continue;
res += g[nr][nc];
}
return res;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cin >> n >> q;
g.resize(2, vector<int>(n));
int blocked = 0;
for (int i = 0; i < q; i++) {
int r, c;
cin >> r >> c;
r--;
c--;
if (g[r][c]) {
blocked -= get(r, c);
} else {
blocked += get(r, c);
}
g[r][c] = !g[r][c];
cout << (blocked ? "No\n" : "Yes\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long int n, q;
cin >> n >> q;
vector<bool> sasta_minecraft[2];
for (long long int i = 0; i < n; i++) {
sasta_minecraft[1].push_back(false);
sasta_minecraft[0].push_back(false);
}
long long int forbidden_cell = 0;
while (q--) {
long long int r, c;
cin >> r >> c;
r--;
c--;
bool forbidden_hto = sasta_minecraft[r][c];
for (long long int i = 0; i <= 1; i++) {
for (long long int j = c - 1; j <= c + 1; j++) {
if (i == r) continue;
if (i < 0 or j >= n or i >= n or j < 0) continue;
if (sasta_minecraft[i][j] == true) {
if (forbidden_hto) {
forbidden_cell--;
} else
forbidden_cell++;
}
}
}
if (sasta_minecraft[r][c])
sasta_minecraft[r][c] = false;
else
sasta_minecraft[r][c] = true;
if (forbidden_cell >= 1)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
int32_t main() {
ios_base ::sync_with_stdio(false), cin.tie(NULL);
solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int n, q;
cin >> n >> q;
vector<vector<int>> grid(2, vector<int>(n, 0));
int cc = 0;
for (int qi = 0; qi < q; qi++) {
int r, c;
cin >> r >> c;
r--, c--;
if (grid[r][c] == 0) {
grid[r][c] = 1;
for (int i = max(0, c - 1); i <= min(n - 1, c + 1); i++) {
if (grid[1 - r][i] == 1) {
cc++;
}
}
} else {
grid[r][c] = 0;
for (int i = max(0, c - 1); i <= min(n - 1, c + 1); i++) {
if (grid[1 - r][i] == 1) {
cc--;
}
}
}
if (cc == 0) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool Map[3][1000000];
int main(void) {
int n, q;
cin >> n >> q;
int wall = 0;
for (int i = 1; i <= q; i++) {
int x, y;
scanf("%d %d", &x, &y);
Map[x][y] = !Map[x][y];
int flag = -1;
if (Map[x][y]) flag = 1;
if (x == 1)
x = 2;
else
x = 1;
if (Map[x][y - 1]) wall += flag;
if (Map[x][y]) wall += flag;
if (Map[x][y + 1]) wall += flag;
if (wall)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q, i, aa, bb, ans = 0, j;
cin >> n >> q;
vector<pair<int, int>> v(q);
for (i = 0; i < q; i++) cin >> v[i].first >> v[i].second;
int a[2][n];
for (i = 0; i < 2; i++) {
for (j = 0; j < n; j++) a[i][j] = 0;
}
for (i = 0; i < q; i++) {
aa = (v[i].first) - 1;
bb = (v[i].second) - 1;
if (a[aa][bb] == 0) {
a[aa][bb] = 1;
if (aa == 1) {
if (a[0][bb] == 1) ans++;
if (bb > 0 && a[0][bb - 1] == 1) ans++;
if (bb < n - 1 && a[0][bb + 1] == 1) ans++;
}
if (aa == 0) {
if (a[1][bb] == 1) ans++;
if (bb > 0 && a[1][bb - 1] == 1) ans++;
if (bb < n - 1 && a[1][bb + 1] == 1) ans++;
}
} else {
a[aa][bb] = 0;
if (aa == 1) {
if (a[0][bb] == 1) ans--;
if (bb > 0 && a[0][bb - 1] == 1) ans--;
if (bb < n - 1 && a[0][bb + 1] == 1) ans--;
}
if (aa == 0) {
if (a[1][bb] == 1) ans--;
if (bb > 0 && a[1][bb - 1] == 1) ans--;
if (bb < n - 1 && a[1][bb + 1] == 1) ans--;
}
}
if (ans > 0)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 400100;
int n, m, x, y, d[N];
bool a[2][N];
void update(int col, int &cnt) {
if (col < 0 || col + 1 == n) {
return;
}
if (!a[0][col] && !a[1][col]) {
cnt += 1 - d[col];
d[col] = 1;
return;
}
if (a[0][col] && a[1][col] && !a[0][col + 1] && !a[1][col + 1]) {
cnt += 1 - d[col];
d[col] = 1;
return;
}
if (a[0][col] && a[1][col]) {
cnt -= d[col];
d[col] = 0;
return;
}
if (a[0][col] && !a[0][col + 1]) {
cnt += 1 - d[col];
d[col] = 1;
return;
}
if (a[1][col] && !a[1][col + 1]) {
cnt += 1 - d[col];
d[col] = 1;
return;
}
cnt -= d[col];
d[col] = 0;
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) {
d[j] = 0;
a[i][j] = true;
}
}
int cnt = 0;
for (int i = 0; i < m; i++) {
scanf("%d %d", &x, &y);
x--;
y--;
a[x][y] ^= true;
update(y - 1, cnt);
update(y, cnt);
if (cnt == 0) {
puts("Yes");
} else {
puts("No");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
bool maze[2][n + 2];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n + 2; j++) {
maze[i][j] = true;
}
}
int row, col;
int blocks = 0;
while (q--) {
cin >> row >> col;
maze[row - 1][col] = !maze[row - 1][col];
for (int i = -1; i < 2; i++) {
if (!maze[2 - row][col + i]) {
if (!maze[row - 1][col]) {
blocks++;
} else {
blocks--;
}
}
}
cout << (blocks == 0 ? "YES" : "NO") << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int cnt = 0;
int a[100001];
int n, q;
int main() {
ios::sync_with_stdio(false);
cin >> n >> q;
for (int i = 1; i <= q; i++) {
int x, y;
cin >> x >> y;
if (a[y] == 3)
cnt--;
else if (a[y] != 0) {
if (y != 1 && a[y] + a[y - 1] == 3) cnt--;
if (y != n && a[y] + a[y + 1] == 3) cnt--;
}
a[y] ^= 1 << (x - 1);
if (a[y] == 3)
cnt++;
else if (a[y] != 0) {
if (y != 1 && a[y] + a[y - 1] == 3) cnt++;
if (y != n && a[y] + a[y + 1] == 3) cnt++;
}
if (cnt == 0)
cout << "Yes\n";
else
cout << "No\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
int a[N][2], x, y;
void pull(int r) {
if (a[r][0] == 1 && a[r][1] == 1) x--;
if (a[r][0] == 1 && a[r - 1][1] == 1) y--;
if (a[r - 1][0] == 1 && a[r][1] == 1) y--;
if (a[r][0] == 1 && a[r + 1][1] == 1) y--;
if (a[r + 1][0] == 1 && a[r][1] == 1) y--;
}
void push(int r) {
if (a[r][0] == 1 && a[r][1] == 1) x++;
if (a[r][0] == 1 && a[r - 1][1] == 1) y++;
if (a[r - 1][0] == 1 && a[r][1] == 1) y++;
if (a[r][0] == 1 && a[r + 1][1] == 1) y++;
if (a[r + 1][0] == 1 && a[r][1] == 1) y++;
}
int main() {
int n, q;
cin >> n >> q;
while (q--) {
int r, c;
cin >> r >> c;
swap(r, c);
c--;
pull(r);
a[r][c] ^= 1;
push(r);
if (x == 0 && y == 0)
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
if (b == 0) {
return a;
}
return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
long long g = gcd(a, b);
return a / g * b;
}
long long ncr(long long n, long long r) {
if (n - r < r) {
r = n - r;
}
long long ret = 1;
for (long long i = 1; i <= r; ++i) {
ret *= (n - r + i);
ret /= i;
}
return ret;
}
vector<vector<int>> grid(3, vector<int>(100001, 1));
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
set<pair<pair<int, int>, pair<int, int>>> blocked;
for (int i = 0; i < q; ++i) {
int r, c;
cin >> r >> c;
grid[r][c] *= -1;
if (grid[r][c] == -1) {
if (r == 1) {
if (grid[r + 1][c] == -1) {
blocked.insert({{r, c}, {r + 1, c}});
}
if (c + 1 <= n && grid[r + 1][c + 1] == -1) {
blocked.insert({{r, c}, {r + 1, c + 1}});
}
if (c - 1 >= 1 && grid[r + 1][c - 1] == -1) {
blocked.insert({{r, c}, {r + 1, c - 1}});
}
} else if (r == 2) {
if (grid[r - 1][c] == -1) {
blocked.insert({{r - 1, c}, {r, c}});
}
if (c + 1 <= n && grid[r - 1][c + 1] == -1) {
blocked.insert({{r - 1, c + 1}, {r, c}});
}
if (c - 1 >= 1 && grid[r - 1][c - 1] == -1) {
blocked.insert({{r - 1, c - 1}, {r, c}});
}
}
} else {
if (r == 1) {
blocked.erase({{r, c}, {r + 1, c}});
if (c + 1 <= n) {
blocked.erase({{r, c}, {r + 1, c + 1}});
}
if (c - 1 >= 1) {
blocked.erase({{r, c}, {r + 1, c - 1}});
}
} else if (r == 2) {
blocked.erase({{r - 1, c}, {r, c}});
if (c + 1 <= n) {
blocked.erase({{r - 1, c + 1}, {r, c}});
}
if (c - 1 >= 1) {
blocked.erase({{r - 1, c - 1}, {r, c}});
}
}
}
if (!blocked.empty()) {
cout << "NO" << endl;
} else {
cout << "YES" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
set<pair<int, int> > cell;
int blocked = 0;
while (q--) {
int r, c, i, j;
cin >> r >> c;
if (cell.count({r, c}) == 0) {
for (int i = r - 1; i <= r + 1; i++) {
for (j = c - 1; j <= c + 1; j++) {
if (i == r) continue;
if (cell.count({i, j}) == 1) {
blocked++;
}
}
}
cell.insert({r, c});
} else {
for (int i = r - 1; i <= r + 1; i++) {
for (j = c - 1; j <= c + 1; j++) {
if (r == i) continue;
if (cell.count({i, j}) == 1) {
blocked--;
}
}
}
cell.erase({r, c});
}
if (blocked > 0)
cout << "NO\n";
else
cout << "YES\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
const long long N = 100011;
long long binpow(long long x, long long y) {
if (y == 0) return 1;
if (y == 1)
return x % mod;
else if (y % 2 == 0) {
long long w = binpow(x, y / 2) % mod;
return (w * w) % mod;
} else
return ((x % mod) * (binpow(x, y - 1) % mod)) % mod;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long t = 1;
while (t--) {
long long n, q;
cin >> n >> q;
long long r[q + 17];
long long c[q + 17];
map<pair<long long, long long>, long long> us;
long long cnt = 0;
for (long long i = 1; i <= q; i++) cin >> r[i] >> c[i];
for (long long i = 1; i <= q; i++) {
us[{r[i], c[i]}] += 1;
us[{r[i], c[i]}] %= 2;
if (us[{r[i], c[i]}] == 0) {
if (r[i] == 2) {
if (us[{r[i] - 1, c[i]}] == 1) cnt--;
if (us[{r[i] - 1, c[i] - 1}] == 1 && c[i] >= 2) cnt--;
if (us[{r[i] - 1, c[i] + 1}] == 1 && c[i] < n) cnt--;
} else {
if (us[{r[i] + 1, c[i]}] == 1) cnt--;
if (us[{r[i] + 1, c[i] - 1}] == 1 && c[i] >= 2) cnt--;
if (us[{r[i] + 1, c[i] + 1}] == 1 && c[i] < n) cnt--;
}
} else {
if (r[i] == 2) {
if (us[{r[i] - 1, c[i]}] == 1) cnt++;
if (us[{r[i] - 1, c[i] - 1}] == 1 && c[i] >= 2) cnt++;
if (us[{r[i] - 1, c[i] + 1}] == 1 && c[i] < n) cnt++;
} else {
if (us[{r[i] + 1, c[i]}] == 1) cnt++;
if (us[{r[i] + 1, c[i] - 1}] == 1 && c[i] >= 2) cnt++;
if (us[{r[i] + 1, c[i] + 1}] == 1 && c[i] < n) cnt++;
}
}
if (!cnt && us[{2, n}] == 0 && us[{1, 1}] == 0)
cout << "YES\n";
else
cout << "NO\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void __read(T &a) {
cin >> a;
}
template <typename T, typename... Args>
void __read(T &a, Args &...args) {
cin >> a;
__read(args...);
}
constexpr long long M7 = 1000000007ll;
constexpr long long M9 = 1000000009ll;
constexpr long long MFFT = 998244353ll;
template <class T>
void outv(T &a) {
for (auto &x : a) cout << x << ' ';
}
static mt19937 rnd(static_cast<unsigned>(
chrono::steady_clock::now().time_since_epoch().count()));
template <class T>
static auto __super_speed__ = (ios_base::sync_with_stdio(0), cin.tie(0));
int32_t main() {
long long n, q;
__read(n, q);
vector<long long> a(n - 1);
set<long long> b;
auto update = [&](long long i) {
if ((a[i] & 10) == 10 || (a[i] & 5) == 5 || (a[i] & 9) == 9 ||
(a[i] & 6) == 6) {
b.insert(i);
} else {
b.erase(i);
}
};
for (long long i = 0; i < q; ++i) {
long long x, y;
__read(x, y);
x--, y--;
if (y > 0) {
long long j = y - 1;
if (x == 0)
a[j] ^= 2;
else
a[j] ^= 8;
update(j);
}
if (y != a.size()) {
long long j = y;
if (x == 0)
a[j] ^= 1;
else
a[j] ^= 4;
update(j);
}
if (b.empty())
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void solve() {
long long n, q;
cin >> n >> q;
bool arr[2][n];
memset(arr, 0, sizeof(arr));
map<long long, set<long long> > m;
while (q--) {
long long r, c;
cin >> r >> c;
r--;
c--;
if (r == 0) {
if (arr[r][c]) {
if (m.find(c) != m.end()) m.erase(c);
} else {
if (c - 1 >= 0 and arr[1][c - 1]) m[c].insert(c - 1);
if (c < n and arr[1][c]) m[c].insert(c);
if (c + 1 < n and arr[1][c + 1]) m[c].insert(c + 1);
}
} else {
if (arr[r][c]) {
if (m[c - 1].find(c) != m[c - 1].end()) m[c - 1].erase(c);
if (m[c].find(c) != m[c].end()) m[c].erase(c);
if (m[c + 1].find(c) != m[c + 1].end()) m[c + 1].erase(c);
if (m[c - 1].size() == 0) m.erase(c - 1);
if (m[c].size() == 0) m.erase(c);
if (m[c + 1].size() == 0) m.erase(c + 1);
} else {
if (c - 1 >= 0 and arr[0][c - 1]) m[c - 1].insert(c);
if (c < n and arr[0][c]) m[c].insert(c);
if (c + 1 < n and arr[0][c + 1]) m[c + 1].insert(c);
}
}
arr[r][c] = !arr[r][c];
if (m.size() == 0)
cout << "YES";
else
cout << "NO";
cout << "\n";
}
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
long long t = 1;
while (t--) solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6;
int arr[2][N];
int main() {
int n;
cin >> n;
int q;
cin >> q;
int x, y;
int v = 0, c1 = 0, c2 = 0;
while (q--) {
cin >> x >> y;
x--;
if (arr[x][y] && arr[1 - x][y]) v--;
if (x == 0 && arr[0][y] && arr[1][y + 1]) c1--;
if (x == 1 && arr[1][y] && arr[0][y - 1]) c1--;
if (x == 0 && arr[0][y] && arr[1][y - 1]) c2--;
if (x == 1 && arr[1][y] && arr[0][y + 1]) c2--;
arr[x][y] = 1 - arr[x][y];
if (arr[x][y] && arr[1 - x][y]) v++;
if (x == 0 && arr[0][y] && arr[1][y + 1]) c1++;
if (x == 1 && arr[1][y] && arr[0][y - 1]) c1++;
if (x == 0 && arr[0][y] && arr[1][y - 1]) c2++;
if (x == 1 && arr[1][y] && arr[0][y + 1]) c2++;
if (v || c1 || c2) {
cout << "No" << endl;
} else {
cout << "Yes" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, Q;
int vis[2][100005];
int ans;
void UPD(int x, int y, int v) {
if (vis[x][y] && vis[x ^ 1][y]) ans += v;
if (vis[x][y] && vis[x ^ 1][y - 1]) ans += v;
if (vis[x][y] && vis[x ^ 1][y + 1]) ans += v;
}
int main() {
scanf("%d%d", &n, &Q);
for (int i = (int)(1); i <= (int)(Q); i++) {
int x, y;
scanf("%d%d", &x, &y);
x--;
UPD(x, y, -1);
vis[x][y] ^= 1;
UPD(x, y, 1);
if (!ans)
puts("Yes");
else
puts("No");
}
}
|
#include <bits/stdc++.h>
using namespace std;
void solve();
mt19937 rnd(2007);
signed main() {
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
swap(rng, rnd);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
}
void solve() {
long long n;
cin >> n;
vector<vector<long long>> a(2, vector<long long>(n));
long long q;
cin >> q;
long long cnt = 0;
for (long long(qwe) = 0; (qwe) < (q); ++(qwe)) {
long long x, y;
cin >> x >> y;
x--;
y--;
long long oldcnt = 0;
for (long long ny = y - 1; ny <= y + 1; ++ny) {
if (0 <= ny && ny + 1 < n) {
oldcnt += (a[0][ny] | a[0][ny + 1]) & (a[1][ny] | a[1][ny + 1]);
}
}
a[x][y] = a[x][y] ^ 1;
long long ncnt = 0;
for (long long ny = y - 1; ny <= y + 1; ++ny) {
if (0 <= ny && ny + 1 < n) {
ncnt += (a[0][ny] | a[0][ny + 1]) & (a[1][ny] | a[1][ny + 1]);
}
}
cnt -= oldcnt;
cnt += ncnt;
if (cnt == 0)
cout << "Yes" << '\n';
else
cout << "No" << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
const double eps = 1e-6;
const int inf = 0x3f3f3f3f;
const int mod = 7 + 1e9;
const int N = 10 + 4e5;
const int M = 10 + 2e5;
int n, q;
int vis[N][2];
int buok;
int main() {
int u, v;
scanf("%d%d", &n, &q);
while (q--) {
scanf("%d%d", &v, &u);
vis[u][v] = !vis[u][v];
if (vis[u][v]) {
for (int i = -1; i <= 1; ++i) {
buok += vis[u + i][3 - v];
}
} else {
for (int i = -1; i <= 1; ++i) {
buok -= vis[u + i][3 - v];
}
}
if (buok || vis[1][1] || vis[n][2])
printf("No\n");
else
printf("Yes\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline int Chkmax(T &a, T b) {
return a < b ? a = b, 1 : 0;
}
template <typename T>
inline int Chkmin(T &a, T b) {
return a > b ? a = b, 1 : 0;
}
template <typename T>
inline T read() {
T sum = 0;
int fl = 1, ch = getchar();
for (; !isdigit(ch); ch = getchar())
if (ch == '-') fl = -1;
for (; isdigit(ch); ch = getchar()) sum = (sum << 3) + (sum << 1) + ch - '0';
return sum * fl;
}
const int maxn = 1e5 + 5;
int n, q;
int a[3][maxn], cnt;
inline void Solve() {
for (int i = 1; i <= q; i++) {
int x, y;
x = read<int>();
y = read<int>();
a[x][y] ^= 1;
if (!a[x][y]) {
cnt -= a[3 - x][y - 1] + a[3 - x][y] + a[3 - x][y + 1];
} else {
cnt += a[3 - x][y - 1] + a[3 - x][y] + a[3 - x][y + 1];
}
if (cnt) {
printf("No\n");
} else
printf("Yes\n");
}
}
inline void Input() {
n = read<int>();
q = read<int>();
}
int main() {
Input();
Solve();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n, q;
cin >> n >> q;
vector<vector<long long>> a(3, vector<long long>(n + 1, 0));
long long p = 0;
bool prev = true;
while (q--) {
long long x, y;
cin >> x >> y;
if (a[x][y] == 0) {
a[x][y] = 1;
long long i = (x == 1) ? 2 : 1;
if (y > 0 and a[i][y - 1] == 1) p++;
if (a[i][y] == 1) p++;
if (y < n and a[i][y + 1] == 1) p++;
} else {
a[x][y] = 0;
long long i = (x == 1) ? 2 : 1;
if (y > 0 and a[i][y - 1] == 1) p--;
if (a[i][y] == 1) p--;
if (y < n and a[i][y + 1] == 1) p--;
}
if (p)
cout << "No"
<< "\n";
else
cout << "yEs"
<< "\n";
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long t = 1;
while (t--) {
solve();
}
}
|
#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
map<pair<int, int>, bool> m;
bool row[3][100010];
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n, q, cnt = 0;
cin >> n >> q;
while (q--) {
long long r, c;
cin >> r >> c;
if (!row[r][c]) {
row[r][c] = 1;
if (r == 1) {
if (row[2][c]) m[make_pair(c, c)] = 1, cnt++;
if (row[2][c - 1]) m[make_pair(c, c - 1)] = 1, cnt++;
if (row[2][c + 1]) m[make_pair(c, c + 1)] = 1, cnt++;
} else {
if (row[1][c]) m[make_pair(c, c)] = 1, cnt++;
if (row[1][c - 1]) m[make_pair(c - 1, c)] = 1, cnt++;
if (row[1][c + 1]) m[make_pair(c + 1, c)] = 1, cnt++;
}
} else {
row[r][c] = 0;
if (r == 1) {
if (row[2][c]) m[make_pair(c, c)] = 0, cnt--;
if (row[2][c - 1]) m[make_pair(c, c - 1)] = 0, cnt--;
if (row[2][c + 1]) m[make_pair(c, c + 1)] = 0, cnt--;
} else {
if (row[1][c]) m[make_pair(c, c)] = 0, cnt--;
if (row[1][c - 1]) m[make_pair(c - 1, c)] = 0, cnt--;
if (row[1][c + 1]) m[make_pair(c + 1, c)] = 0, cnt--;
}
}
if (cnt)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int n, q, a[3][100009];
int main() {
cin >> n >> q;
int cnt = 0;
while (q--) {
int x, y;
cin >> x >> y;
if (!a[x][y]) {
for (int i = -1; i <= 1; ++i)
if (a[3 - x][y + i] == 1) ++cnt;
a[x][y] = 1;
} else {
for (int i = -1; i <= 1; ++i)
if (a[3 - x][y + i] == 1) --cnt;
a[x][y] = 0;
}
if (cnt)
cout << "NO\n";
else
cout << "YES\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int mapp[2][100010];
int main() {
int n, q, sum = 0, x, y;
cin >> n >> q;
for (int i = 0; i < q; i++) {
cin >> x >> y;
x--;
if (mapp[x][y] == 1) {
if (mapp[1 - x][y] == 1) sum--;
if (y - 1 >= 1) {
if (mapp[1 - x][y - 1] == 1) sum--;
}
if (y + 1 <= n) {
if (mapp[1 - x][y + 1] == 1) sum--;
}
mapp[x][y] = 0;
} else if (mapp[x][y] == 0) {
if (mapp[1 - x][y] == 1) sum++;
if (y - 1 >= 1) {
if (mapp[1 - x][y - 1] == 1) sum++;
}
if (y + 1 <= n) {
if (mapp[1 - x][y + 1] == 1) sum++;
}
mapp[x][y] = 1;
}
if (sum == 0)
cout << "yes" << endl;
else
cout << "no" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n, q, i;
cin >> n >> q;
bool used[2][n];
memset(used, false, sizeof(used));
int ct = 0;
while (q > 0) {
q--;
int a, b;
cin >> a >> b;
a--;
b--;
if (used[a][b]) {
if (a - 1 == 0) {
if (used[a - 1][b]) ct--;
if (b - 1 >= 0 && used[a - 1][b - 1]) ct--;
if (b + 1 < n && used[a - 1][b + 1]) ct--;
} else {
if (used[a + 1][b]) ct--;
if (b - 1 >= 0 && used[a + 1][b - 1]) ct--;
if (b + 1 < n && used[a + 1][b + 1]) ct--;
}
used[a][b] = false;
} else {
if (a - 1 == 0) {
if (used[a - 1][b]) ct++;
if (b - 1 >= 0 && used[a - 1][b - 1]) ct++;
if (b + 1 < n && used[a - 1][b + 1]) ct++;
} else {
if (used[a + 1][b]) ct++;
if (b - 1 >= 0 && used[a + 1][b - 1]) ct++;
if (b + 1 < n && used[a + 1][b + 1]) ct++;
}
used[a][b] = true;
}
if (ct <= 0) {
cout << "Yes\n";
} else
cout << "No\n";
}
}
int main() {
ios_base ::sync_with_stdio(0);
cin.tie(NULL);
int t;
t = 1;
while (t > 0) {
t--;
solve();
}
}
|
#include <bits/stdc++.h>
using namespace std;
template <typename T>
void rd(T& x) {
long long f = 0, c;
while (!isdigit(c = getchar())) f ^= !(c ^ 45);
x = (c & 15);
while (isdigit(c = getchar())) x = x * 10 + (c & 15);
if (f) x = -x;
}
template <typename T>
void pt(T x, long long c = -1) {
if (x < 0) putchar('-'), x = -x;
if (x > 9) pt(x / 10);
putchar(x % 10 + 48);
if (c != -1) putchar(c);
}
const long long N = 100005;
long long n, Q, a[3][N];
long long count(long long k1, long long i) {
if (k1 == 1) {
return a[2][i - 1] + a[2][i] + a[2][i + 1];
} else
return a[1][i - 1] + a[1][i] + a[1][i + 1];
}
signed main() {
rd(n), rd(Q);
long long ans = 0;
while (Q--) {
long long k1, k2;
rd(k1), rd(k2);
if (a[k1][k2] == 0)
ans += count(k1, k2);
else
ans -= count(k1, k2);
a[k1][k2] ^= 1;
if (ans == 0)
puts("Yes");
else
puts("No");
}
return 0;
}
|
#include <bits/stdc++.h>
int pi[3][233333];
bool pf[3][233333];
int main() {
int n, q, k = 0;
scanf("%d%d", &n, &q);
for (int i = 1; i <= q; i++) {
int x, y;
scanf("%d%d", &x, &y);
if (pf[x][y] == false) {
pf[x][y] = true;
pi[3 - x][y - 1]++;
pi[3 - x][y]++;
pi[3 - x][y + 1]++;
k += pi[x][y];
} else {
pf[x][y] = false;
pi[3 - x][y - 1]--;
pi[3 - x][y]--;
pi[3 - x][y + 1]--;
k -= pi[x][y];
}
if (k > 0)
printf("No\n");
else
printf("Yes\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool sortBySecond(const pair<long long, long long> &a,
const pair<long long, long long> b) {
return a.second > b.second;
}
int ncr[1001][1001];
bool vis_ncr[1001][1001];
long long NCR(int n, int r) {
if (n < r) return 0;
if (vis_ncr[n][r]) return ncr[n][r];
if (r == 0) return 1;
if (r == 1) return n;
if (n == 0) return 0;
ncr[n][r] = NCR(n - 1, r) + NCR(n - 1, r - 1);
vis_ncr[n][r] = true;
return ncr[n][r];
}
struct segmentTree {
int N;
vector<long long> tree;
void init(int n) {
N = n;
tree.resize(4 * n + 1, 0);
}
void assemble(vector<long long> &v, int l, int r, int node) {
if (l > r) return;
if (l == r) {
tree[node] = v[l];
return;
}
int mid = (l + r) / 2;
assemble(v, l, mid, 2 * node + 1);
assemble(v, mid + 1, r, 2 * node + 2);
tree[node] = tree[2 * node + 1] + tree[2 * node + 2];
}
void update(int idx, int node, int l, int r, long long val) {
if (l > r) return;
if (l == r) {
tree[node] = val;
return;
}
int mid = (l + r) / 2;
if (idx <= mid)
update(idx, 2 * node + 1, l, mid, val);
else
update(idx, 2 * node + 2, mid + 1, r, val);
tree[node] = tree[2 * node + 1] + tree[2 * node + 2];
}
long long rangeQuery(int node, int l, int r, int ql, int qr) {
if (l > r || l > qr || r < ql || ql > qr) return 0;
if (l >= ql && r <= qr) return tree[node];
int mid = (l + r) / 2;
return rangeQuery(2 * node + 1, l, mid, ql, qr) +
rangeQuery(2 * node + 2, mid + 1, r, ql, qr);
}
void changeTree(int idx, long long val) {
idx--;
update(idx, 0, 0, N - 1, val);
}
long long getSum(int l, int r) {
l--, r--;
return rangeQuery(0, 0, N - 1, l, r);
}
};
template <typename K, typename V>
void printMapMultipleValue(map<K, V> const &mp, string name) {
cout << name << ":\n";
for (auto const &pa : mp) {
cout << pa.first << " : ";
cout << "{";
for (auto const &x : pa.second) cout << x << ',';
cout << "}\n";
}
}
template <typename K, typename V>
void printMap(map<K, V> const &mp, string name) {
cout << name << ":" << endl;
for (auto const &pa : mp)
cout << "{" << pa.first << " : " << pa.second << "}" << endl;
}
bool isPrime[100006];
void _seive() {
memset(isPrime, true, sizeof(isPrime));
isPrime[1] = false;
isPrime[0] = false;
for (int i = 2; i * i <= 100005; i++) {
for (int j = i * i; j <= 100005; j += i) {
isPrime[j] = false;
}
}
}
long long expo(int a, int b) {
if (b == 0)
return 1;
else if (b == 1)
return a;
else if (b % 2 == 0) {
long long ret = expo(a, b / 2);
ret = (ret % 1000000007 * ret % 1000000007) % 1000000007;
return ret;
} else {
long long ret = expo(a, b / 2);
ret = (ret % 1000000007 * ret % 1000000007) % 1000000007;
ret = (ret % 1000000007 * a % 1000000007) % 1000000007;
return ret;
}
}
long long inverseMod(long long a, long long m) { return expo(a, m - 2) % m; }
long long fact[100005];
void factorial() {
fact[0] = fact[1] = 1;
for (int i = 2; i < 100005; i++)
fact[i] = (fact[i - 1] % 1000000007 * i % 1000000007) % 1000000007;
}
long long GCD(long long a, long long b) {
if (a == 0) return b;
return GCD(b % a, a);
}
long long mult(long long a, long long b) {
return (a % 1000000007 * b % 1000000007) % 1000000007;
}
long long add(long long a, long long b) {
a += b;
if (a >= 1000000007) return a - 1000000007;
return a;
}
long long sub(long long a, long long b) {
a -= b;
if (a < 0) return a + 1000000007;
return a;
}
void _run(int test) {
int n, q;
cin >> n >> q;
bool forbidden[2][n];
memset(forbidden, false, sizeof(forbidden));
int bad_counter = 0;
for (int i = 0; i < q; i++) {
int row, col;
cin >> row >> col;
row--, col--;
if (forbidden[row][col]) {
int opp_row = (row + 1) % 2;
bool found_forb = false;
for (int d = -1; d <= 1; d++) {
if (col + d >= 0 && col + d < n) {
if (forbidden[opp_row][col + d]) bad_counter--;
}
}
} else {
int opp_row = (row + 1) % 2;
bool found_forb = false;
for (int d = -1; d <= 1; d++) {
if (col + d >= 0 && col + d < n) {
if (forbidden[opp_row][col + d]) bad_counter++;
}
}
}
forbidden[row][col] = !forbidden[row][col];
if (bad_counter)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int test = 1;
for (int i = 1; i <= test; i++) _run(i);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
using pll = pair<long long, long long>;
using vl = vector<long long>;
using vpll = vector<pll>;
using mll = map<long long, long long>;
using mcl = map<char, long long>;
using sl = set<long long>;
using sc = set<char>;
using dl = deque<long long>;
const int N = 1e6 + 5;
long long mod = 1e9 + 7;
vl adj[N];
vpll adjc[N];
long long vis[N];
long long arr[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long a, b, c, d, sz, n, m, p, x, y, z, i, j, k,
f = 0, tc, cnt = 0, sum = 0, mul = 1, mi = 1e18, ma = -1e18;
string str;
char ch;
double db;
long long l, r, q;
cnt = 0;
map<pll, long long> mp;
cin >> n >> q;
while (q--) {
cin >> i >> j;
f = 0;
if (mp[{i, j}] == 1) {
f = 1;
}
if (i == 2) {
a = j - 1;
b = j;
c = j + 1;
if (mp[{1, a}])
if (!f)
cnt++;
else
cnt--;
if (mp[{1, b}])
if (!f)
cnt++;
else
cnt--;
if (mp[{1, c}])
if (!f)
cnt++;
else
cnt--;
} else {
a = j - 1;
b = j;
c = j + 1;
if (mp[{2, a}])
if (!f)
cnt++;
else
cnt--;
if (mp[{2, b}])
if (!f)
cnt++;
else
cnt--;
if (mp[{2, c}])
if (!f)
cnt++;
else
cnt--;
}
if (mp[{i, j}] == 0)
mp[{i, j}] = 1;
else
mp[{i, j}] = 0;
if (cnt == 0)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
set<pair<pair<int, int>, pair<int, int> > > s;
vector<vector<bool> > v(2, vector<bool>(n, false));
for (int i = 0, x, y; i < q; i++) {
cin >> x >> y;
if (v[x - 1][y - 1])
v[x - 1][y - 1] = 0;
else
v[x - 1][y - 1] = 1;
if (v[x - 1][y - 1]) {
if (x - 1 == 0) {
if (v[x][y - 1]) {
s.insert({{x - 1, y - 1}, {x, y - 1}});
}
if (y - 2 >= 0 && v[x][y - 2]) {
s.insert({{x - 1, y - 1}, {x, y - 2}});
}
if (y <= n - 1 && v[x][y]) {
s.insert({{x - 1, y - 1}, {x, y}});
}
} else {
if (v[x - 2][y - 1]) {
s.insert({{x - 1, y - 1}, {x - 2, y - 1}});
}
if (y - 2 >= 0 && v[x - 2][y - 2]) {
s.insert({{x - 1, y - 1}, {x - 2, y - 2}});
}
if (y <= n - 1 && v[x - 2][y]) {
s.insert({{x - 1, y - 1}, {x - 2, y}});
}
}
} else {
if (x - 1 == 0) {
auto it = s.find({{x - 1, y - 1}, {x, y - 1}});
if (it != s.end()) s.erase(it);
it = s.find({{x, y - 1}, {x - 1, y - 1}});
if (it != s.end()) s.erase(it);
if (y - 2 >= 0) {
it = s.find({{x - 1, y - 1}, {x, y - 2}});
if (it != s.end()) s.erase(it);
it = s.find({{x, y - 2}, {x - 1, y - 1}});
if (it != s.end()) s.erase(it);
}
if (y <= n - 1) {
it = s.find({{x - 1, y - 1}, {x, y}});
if (it != s.end()) s.erase(it);
it = s.find({{x, y}, {x - 1, y - 1}});
if (it != s.end()) s.erase(it);
}
} else {
auto it = s.find({{x - 1, y - 1}, {x - 2, y - 1}});
if (it != s.end()) s.erase(it);
it = s.find({{x - 2, y - 1}, {x - 1, y - 1}});
if (it != s.end()) s.erase(it);
if (y - 2 >= 0) {
it = s.find({{x - 1, y - 1}, {x - 2, y - 2}});
if (it != s.end()) s.erase(it);
it = s.find({{x - 2, y - 2}, {x - 1, y - 1}});
if (it != s.end()) s.erase(it);
}
if (y <= n - 1) {
it = s.find({{x - 1, y - 1}, {x - 2, y}});
if (it != s.end()) s.erase(it);
it = s.find({{x - 2, y}, {x - 1, y - 1}});
if (it != s.end()) s.erase(it);
}
}
}
if (s.empty())
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
struct node {
int x1, y1;
};
int visit1[3][200010];
int visit2[3][200005];
bool operator<(node a, node b) {
return std::make_pair(a.x1, a.y1) < std::make_pair(b.x1, b.y1);
}
int main() {
int n, q, x, y, cnt = 0;
cin >> n >> q;
map<node, node> arr;
for (int i = 0; i < q; i++) {
cin >> x >> y;
if (x == 2 and y == n) {
if (visit1[x][y] == 1) {
if (cnt == 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
visit1[x][y] = 0;
} else {
cout << "NO" << endl;
visit1[x][y] = 1;
}
continue;
}
if (visit1[x][y] == 1) {
visit1[x][y] = 0;
} else if (visit1[x][y] == 0 and visit2[x][y] == 0) {
if (x == 1) {
int chk = 0;
for (int j = -1; j <= 1; j++) {
if (y + j != 0 and y + j <= n) {
if (visit1[2][y + j] == 1) {
arr[{2, y + j}] = {1, y};
arr[{1, y}] = {2, y + j};
cnt++;
visit2[1][y] = visit2[2][y + j] = 1;
visit1[2][y + j] = 0;
chk = 1;
break;
}
}
}
if (chk == 0) {
visit1[x][y] = 1;
}
} else {
int chk = 0;
for (int j = -1; j <= 1; j++) {
if (y + j != 0 and y + j <= n) {
if (visit1[1][y + j] == 1) {
arr[{1, y + j}] = {2, y};
arr[{2, y}] = {1, y + j};
cnt++;
visit2[2][y] = visit2[1][y + j] = 1;
visit1[1][y + j] = 0;
chk = 1;
break;
}
}
}
if (chk == 0) visit1[x][y] = 1;
}
} else if (visit2[x][y] == 1) {
visit2[x][y] = 0;
node temp = arr[{x, y}];
x = temp.x1;
y = temp.y1;
if (x == 1) {
int chk = 0;
for (int j = -1; j <= 1; j++) {
if (y + j != 0 and y + j <= n) {
if (visit1[2][y + j] == 1) {
arr[{2, y + j}] = {1, y};
arr[{1, y}] = {2, y + j};
cnt++;
visit2[1][y] = visit2[2][y + j] = 1;
visit1[2][y + j] = 0;
chk = 1;
break;
}
}
}
if (chk == 0) {
visit2[x][y] = 0;
visit1[x][y] = 1;
}
} else {
int chk = 0;
for (int j = -1; j <= 1; j++) {
if (y + j != 0 and y + j <= n) {
if (visit1[1][y + j] == 1) {
arr[{1, y + j}] = {2, y};
arr[{2, y}] = {1, y + j};
cnt++;
visit2[2][y] = visit2[1][y + j] = 1;
visit1[1][y + j] = 0;
chk = 1;
break;
}
}
}
if (chk == 0) {
visit2[x][y] = 0;
visit1[x][y] = 1;
}
}
cnt--;
}
if (cnt == 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[3][maxn];
int main() {
int n, q;
int num1 = 0, num2 = 0;
scanf("%d%d", &n, &q);
while (q--) {
int r, c;
scanf("%d%d", &r, &c);
if (a[r][c] == 0) {
a[r][c] = 1;
} else {
a[r][c] = 0;
}
if (a[r][c] == 1) {
if (r == 1) {
if (a[2][c] == 1) {
num1++;
}
if (c >= 2 && c < n) {
if (a[2][c - 1] == 1) {
num2++;
}
if (a[2][c + 1] == 1) {
num2++;
}
}
if (c == 1) {
if (a[2][c + 1] == 1) {
num2++;
}
}
if (c == n) {
if (a[2][c - 1] == 1) {
num2++;
}
}
} else {
if (a[1][c] == 1) {
num1++;
}
if (c >= 2 && c < n) {
if (a[1][c - 1] == 1) {
num2++;
}
if (a[1][c + 1] == 1) {
num2++;
}
}
if (c == 1) {
if (a[1][c + 1] == 1) {
num2++;
}
}
if (c == n) {
if (a[1][c - 1] == 1) {
num2++;
}
}
}
} else {
if (r == 1) {
if (a[2][c] == 1) {
num1--;
}
if (c >= 2 && c < n) {
if (a[2][c - 1] == 1) {
num2--;
}
if (a[2][c + 1] == 1) {
num2--;
}
}
if (c == 1) {
if (a[2][c + 1] == 1) {
num2--;
}
}
if (c == n) {
if (a[2][c - 1] == 1) {
num2--;
}
}
} else {
if (a[1][c] == 1) {
num1--;
}
if (c >= 2 && c < n) {
if (a[1][c - 1] == 1) {
num2--;
}
if (a[1][c + 1] == 1) {
num2--;
}
}
if (c == 1) {
if (a[1][c + 1] == 1) {
num2--;
}
}
if (c == n) {
if (a[1][c - 1] == 1) {
num2--;
}
}
}
}
if (a[1][1] == 1 || a[2][n] == 1) {
puts("No");
continue;
}
if (num1 == 0 && num2 == 0) {
puts("Yes");
} else {
puts("No");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
bool a[2][100005];
int main() {
int n, q;
cin >> n >> q;
int constraints_violated = 0;
for (int i = 0; i < q; i++) {
int r, c;
cin >> r >> c;
r--;
c--;
a[r][c] = !a[r][c];
if (a[r][c]) {
if (c > 0) {
if (a[1 - r][c - 1]) {
constraints_violated++;
}
}
if (a[1 - r][c]) {
constraints_violated++;
}
if (c < n - 1) {
if (a[1 - r][c + 1]) {
constraints_violated++;
}
}
}
if (!a[r][c]) {
if (c > 0) {
if (a[1 - r][c - 1]) {
constraints_violated--;
}
}
if (a[1 - r][c]) {
constraints_violated--;
}
if (c < n - 1) {
if (a[1 - r][c + 1]) {
constraints_violated--;
}
}
}
if (constraints_violated == 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
int n_problems = 0;
vector<vector<int>> arr(2, vector<int>(n));
for (int i = 0; i < q; ++i) {
int r, c;
cin >> r >> c;
--r, --c;
if (arr[r][c]) {
int issues_here = 0;
issues_here += arr[1 ^ r][c];
if (c) issues_here += arr[1 ^ r][c - 1];
if (c != n - 1) issues_here += arr[1 ^ r][c + 1];
n_problems -= issues_here;
} else {
int issues_here = 0;
issues_here += arr[1 ^ r][c];
if (c) issues_here += arr[1 ^ r][c - 1];
if (c != n - 1) issues_here += arr[1 ^ r][c + 1];
n_problems += issues_here;
}
arr[r][c] ^= 1;
cout << (n_problems ? "no" : "yes") << '\n';
}
}
|
#include <bits/stdc++.h>
using namespace std;
int a[2][100003];
int main() {
int n, q;
cin >> n >> q;
int f = 0;
while (q--) {
int x, y;
cin >> x >> y;
int b = a[x - 1][y - 1] ? -1 : 1;
f += b * (a[2 - x][y - 2] + a[2 - x][y - 1] + a[2 - x][y]);
a[x - 1][y - 1] ^= 1;
cout << (f ? "No" : "Yes") << "\n";
}
return 0;
}
|
#include <bits/stdc++.h>
#pragma GCC optimize("no-stack-protector")
#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
using namespace std;
const int maxn = 2e6 + 1;
int n, q;
bool v[2][maxn];
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
int cnt = 0;
for (int i = 0; i < q; i++) {
int second, c;
cin >> second >> c;
--second;
--c;
if (!v[second][c]) {
if (c && v[second ^ 1][c - 1]) ++cnt;
if (c < n - 1 && v[second ^ 1][c + 1]) ++cnt;
if (v[second ^ 1][c]) ++cnt;
} else {
if (c && v[second ^ 1][c - 1]) --cnt;
if (c < n - 1 && v[second ^ 1][c + 1]) --cnt;
if (v[second ^ 1][c]) --cnt;
}
v[second][c] ^= 1;
cout << (cnt ? "No" : "Yes") << '\n';
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, t, x, y, z;
long long int mn = 8675435789, mx = -8675868757, PI = 3.14159265359,
md = 1000000007, aa = 0, bb = 0, cc = 0;
string r, s, u, v, w;
long long int a[3][100010] = {0}, b[250002];
map<long long int, long long int> mp, mq, m1, m2;
queue<long long int> qu, qe;
pair<long long int, long long int> pp[30030];
set<string> se, sa;
int main() {
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
cin >> n >> q;
while (q--) {
cin >> x >> y;
if (x == 1) {
if (a[x][y]) {
cc = cc - a[2][y - 1] - a[2][y] - a[2][y + 1];
a[x][y] = 0;
} else {
cc = cc + a[2][y - 1] + a[2][y] + a[2][y + 1];
a[x][y] = 1;
}
} else {
if (a[x][y]) {
cc = cc - a[1][y - 1] - a[1][y] - a[1][y + 1];
a[x][y] = 0;
} else {
cc = cc + a[1][y - 1] + a[1][y] + a[1][y + 1];
a[x][y] = 1;
}
}
if (cc)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, q;
set<int> s[2];
int main() {
scanf("%d%d", &n, &q);
s[0].clear();
s[1].clear();
int x, y;
int block = 0;
while (q--) {
scanf("%d%d", &x, &y);
x--;
int cha;
if (s[x].lower_bound(y) != s[x].end() && *(s[x].lower_bound(y)) == y)
cha = -1;
else
cha = 1;
if (cha == -1)
s[x].erase(y);
else
s[x].insert(y);
set<int>::iterator it = s[x ^ 1].lower_bound(y);
if (it != s[x ^ 1].end()) {
if ((*it) == y) {
block += cha;
it++;
if (it != s[x ^ 1].end() && (*it) == y + 1) block += cha;
it--;
} else if ((*it) == y + 1)
block += cha;
}
if (it != s[x ^ 1].begin()) {
it--;
if ((*it) == y - 1) block += cha;
}
if (block > 0)
puts("NO");
else
puts("YES");
assert(block >= 0);
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
long long int modadd(long long int n, long long int m, long long int mod) {
long long int sum = ((n + m) % mod + mod) % mod;
return sum;
}
long long int modsub(long long int n, long long int m, long long int mod) {
long long int diff = ((n - m + mod) % mod + mod) % mod;
return diff;
}
long long int modpro(long long int n, long long int m, long long int mod) {
long long int pro = ((n * m) % mod + mod) % mod;
return pro;
}
long long int powmod(long long int x, long long int y, long long int mod) {
long long int res = 1;
while (y > 0) {
if (y & 1) res = modpro(res, x, mod);
y = y >> 1;
x = modpro(x, x, mod);
}
return res;
}
long long int moddiv(long long int n, long long int m, long long int mod) {
long long int a = powmod(m, mod - 2, mod);
long long int res = modpro(a, n, mod);
return res;
}
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
long long int n, q;
cin >> n >> q;
long long int f = 0;
long long int a[2][n];
for (long long int j = 0; j < n; j++) {
a[0][j] = 0;
a[1][j] = 0;
}
long long int b, c;
for (long long int j = 0; j < q; j++) {
cin >> b >> c;
a[b - 1][c - 1] = 1 - a[b - 1][c - 1];
long long int d = 0;
b--;
c--;
for (long long int i = min(n - 1, c + 1); i >= max((long long int)0, c - 1);
i--) {
if (a[1 - b][i] == 1) {
d++;
}
}
if (a[b][c] == 1) {
f += d;
} else {
f -= d;
};
if (f == 0) {
cout << "YES"
<< "\n";
} else {
cout << "NO"
<< "\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
const double eps = 1e-8;
const long long mx = 1e7 + 10;
const double PI = acos(-1);
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
bool isprime(int n) {
if (n <= 1) return 0;
for (int i = 2; i * i <= n; i++)
if (n % i == 0) return 0;
return 1;
}
inline long long qpow(long long a, long long b) {
return b ? ((b & 1) ? a * qpow(a * a % mod, b >> 1) % mod
: qpow(a * a % mod, b >> 1)) %
mod
: 1;
}
inline long long qpow(long long a, long long b, long long c) {
return b ? ((b & 1) ? a * qpow(a * a % c, b >> 1) % c
: qpow(a * a % c, b >> 1)) %
c
: 1;
}
void ca(int kase, int ans) { cout << "Case #" << kase << ": " << ans << endl; }
long long t, m, n, k;
long long sum = 0, cnt = 0;
string s;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> t;
set<pair<long long, long long>> cell;
long long bad_nei = 0;
while (t--) {
long long row, col;
cin >> row >> col;
bool is_forbidden = cell.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 (cell.count({r, c})) {
if (is_forbidden) {
bad_nei--;
} else {
bad_nei++;
}
}
}
}
if (cell.count({row, col})) {
cell.erase({row, col});
} else {
cell.insert({row, col});
}
if (bad_nei >= 1) {
puts("NO");
} else {
puts("YES");
}
}
return 0;
}
|
#include <bits/stdc++.h>
int main() {
int n, q;
std::cin >> n;
std::cin >> q;
std::vector<std::vector<int>> arr(2);
arr[0].resize(n + 2);
arr[1].resize(n + 2);
std::fill(arr[0].begin(), arr[0].end(), 1);
std::fill(arr[1].begin(), arr[1].end(), 1);
int numPairs = 0;
while (q--) {
int r, c;
std::cin >> r;
std::cin >> c;
arr[r - 1][c] = !arr[r - 1][c];
if (arr[r - 1][c] == 0) {
numPairs += (arr[r % 2][c] == 0) + (arr[r % 2][c - 1] == 0) +
(arr[r % 2][c + 1] == 0);
} else {
numPairs -= (arr[r % 2][c] == 0) + (arr[r % 2][c - 1] == 0) +
(arr[r % 2][c + 1] == 0);
}
if (numPairs > 0)
std::cout << "NO\n";
else
std::cout << "YES\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
map<pair<int, int>, int> mp;
int n, q;
int num;
int main() {
cin >> n >> q;
for (int i = 1, x, y; i <= q; i++) {
scanf("%d%d", &x, &y);
if (x == 2) x = 0;
mp[{x, y}]++;
if (mp[{x, y}] % 2 == 1) {
if (mp[{x ^ 1, y - 1}] % 2 || mp[{x ^ 1, y}] % 2 ||
mp[{x ^ 1, y + 1}] % 2) {
puts("NO");
if (mp[{x ^ 1, y - 1}] % 2) num++;
if (mp[{x ^ 1, y}] % 2) num++;
if (mp[{x ^ 1, y + 1}] % 2) num++;
} else {
if (num)
puts("NO");
else
puts("YES");
}
} else {
if (mp[{x ^ 1, y + 1}] % 2 || mp[{x ^ 1, y}] % 2 ||
mp[{x ^ 1, y - 1}] % 2) {
if (mp[{x ^ 1, y + 1}] % 2) num--;
if (mp[{x ^ 1, y}] % 2) num--;
if (mp[{x ^ 1, y - 1}] % 2) num--;
}
if (num == 0)
puts("YES");
else
puts("NO");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int dx[] = {-1, -1, -1, 1, 1, 1};
const int dy[] = {-1, 0, 1, -1, 0, 1};
const int maxn = 1e5 + 5;
bool vis[3][maxn];
int n, q, num, x, y;
bool is_point_in(const int &x, const int &y) {
if (x <= 0 || y <= 0 || x > 2 || y > n) return false;
return true;
}
int get_points(const int &x, const int &y) {
int res = 0;
for (int i = 0; i < 6; i++) {
int xx = x + dx[i];
int yy = y + dy[i];
if (!is_point_in(xx, yy)) continue;
if (vis[xx][yy]) res++;
}
return res;
}
int main() {
scanf("%d%d", &n, &q);
for (int i = 0; i < q; i++) {
scanf("%d%d", &x, &y);
if (!vis[x][y])
num += get_points(x, y);
else
num -= get_points(x, y);
vis[x][y] = !vis[x][y];
if (num == 0)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
vector<int> v;
vector<vector<int> > m;
set<int> lava;
set<pair<int, int> > bloqueios;
int main() {
int n, q;
cin >> n >> q;
for (int i = 0; i < q; i++) {
int x, y, pos;
cin >> y >> x;
y--;
x--;
pos = n * y + x;
int posBlock = (pos + n) % (2 * n);
if (lava.count(pos) == 0) {
lava.insert(pos);
if (lava.count(posBlock) == 1) {
bloqueios.insert({min(pos, posBlock), max(pos, posBlock)});
}
if (x != n - 1 && lava.count(posBlock + 1) == 1) {
bloqueios.insert({min(pos, posBlock + 1), max(pos, posBlock + 1)});
}
if (x != 0 && lava.count(posBlock - 1) == 1) {
bloqueios.insert({min(pos, posBlock - 1), max(pos, posBlock - 1)});
}
} else {
lava.erase(pos);
if (lava.count(posBlock) == 1) {
if (bloqueios.count({min(pos, posBlock), max(pos, posBlock)})) {
bloqueios.erase({min(pos, posBlock), max(pos, posBlock)});
}
}
if (x != n - 1 && lava.count(posBlock + 1) == 1) {
if (bloqueios.count({min(pos, posBlock + 1), max(pos, posBlock + 1)})) {
bloqueios.erase({min(pos, posBlock + 1), max(pos, posBlock + 1)});
}
}
if (x != 0 && lava.count(posBlock - 1) == 1) {
if (bloqueios.count({min(pos, posBlock - 1), max(pos, posBlock - 1)})) {
bloqueios.erase({min(pos, posBlock - 1), max(pos, posBlock - 1)});
}
}
}
if (bloqueios.size() == 0) {
cout << "Yes\n";
} else {
cout << "No\n";
}
}
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
size_t n, q;
cin >> n >> q;
int64_t tot = 0;
vector<int64_t> v1(n + 10), v2(n + 10), v3(n + 10);
for (size_t i = 0; i < q; i++) {
int64_t a, b;
cin >> a >> b;
b += 2;
tot -= (v1[b] == 3);
v1[b] ^= a;
tot += (v1[b] == 3);
int64_t c = b + (a == 1 ? 1 : 0);
tot -= (v2[c] == 3);
v2[c] ^= a;
tot += (v2[c] == 3);
c = b + (a == 1 ? -1 : 0);
tot -= (v3[c] == 3);
v3[c] ^= a;
tot += (v3[c] == 3);
if (tot == 0) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int mk[2][100005];
set<pair<int, int> > S;
int main() {
int n, q;
scanf("%d%d", &n, &q);
while (q--) {
int r, c;
scanf("%d%d", &r, &c);
r--;
if (!mk[r][c]) {
mk[r][c] = 1;
if (mk[r ^ 1][c - 1]) r ? S.insert({c - 1, c}) : S.insert({c, c - 1});
if (mk[r ^ 1][c]) r ? S.insert({c, c}) : S.insert({c, c});
if (mk[r ^ 1][c + 1]) r ? S.insert({c + 1, c}) : S.insert({c, c + 1});
} else {
mk[r][c] = 0;
if (mk[r ^ 1][c - 1])
r ? S.erase(S.find({c - 1, c})) : S.erase(S.find({c, c - 1}));
if (mk[r ^ 1][c]) r ? S.erase(S.find({c, c})) : S.erase(S.find({c, c}));
if (mk[r ^ 1][c + 1])
r ? S.erase(S.find({c + 1, c})) : S.erase(S.find({c, c + 1}));
}
if (S.size())
printf("No\n");
else
printf("Yes\n");
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1000000007;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int n, q;
cin >> n >> q;
vector<pair<int, int> > rc(q);
for (auto &x : rc) {
cin >> x.first >> x.second;
x.first--;
x.second--;
}
vector<string> ans(q);
vector<vector<bool> > board(2, vector<bool>(n));
int block = 0;
for (int i = 0; i < q; i++) {
if (!board[rc[i].first][rc[i].second]) {
board[rc[i].first][rc[i].second] = true;
int r = rc[i].first ^ 1;
for (int c = rc[i].second - 1; c <= rc[i].second + 1; c++) {
if (c < 0 || c >= n) continue;
if (board[r][c]) block++;
}
} else {
board[rc[i].first][rc[i].second] = false;
int r = rc[i].first ^ 1;
for (int c = rc[i].second - 1; c <= rc[i].second + 1; c++) {
if (c < 0 || c >= n) continue;
if (board[r][c]) block--;
}
}
if (block == 0)
ans[i] = "Yes";
else
ans[i] = "No";
}
for (auto &x : ans) cout << x << endl;
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long t, n;
cin >> n >> t;
long long arr[4][n + 2];
memset(arr, 0, sizeof(arr));
set<pair<pair<long long, long long>, pair<long long, long long>>> s;
while (t--) {
long long i, j, k;
long long x, y;
cin >> x >> y;
arr[x][y] = 1 - arr[x][y];
if (arr[x][y] == 1) {
for (j = x - 1; j <= x + 1; j = j + 2) {
for (k = y - 1; k <= y + 1; k++) {
if (arr[j][k] == 1) {
s.insert(make_pair(make_pair(x, y), make_pair(j, k)));
s.insert(make_pair(make_pair(j, k), make_pair(x, y)));
}
}
}
} else {
for (j = x - 1; j <= x + 1; j += 2) {
for (k = y - 1; k <= y + 1; k++) {
if (arr[j][k] == 1) {
s.erase(make_pair(make_pair(x, y), make_pair(j, k)));
s.erase(make_pair(make_pair(j, k), make_pair(x, y)));
}
}
}
}
if (s.size() > 0)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
|
#include <bits/stdc++.h>
using namespace std;
namespace IO {
void setIn(string s) { freopen(s.c_str(), "r", stdin); }
void setOut(string s) { freopen(s.c_str(), "w", stdout); }
void setIO(string s = "") {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin.exceptions(cin.failbit);
if (s.size()) {
setIn(s + ".inp");
setOut(s + ".out");
} else {
}
}
} // namespace IO
using namespace IO;
namespace Function {
template <typename T1, typename T2>
void amax(T1 &a, T2 b) {
if (typeid(a).name() == typeid(int).name() &&
typeid(b).name() == typeid(long long).name()) {
cout << "Error on amax";
exit(0);
}
if (a < b) a = b;
}
template <typename T1, typename T2>
void amin(T1 &a, T2 b) {
if (a > b) a = b;
}
template <typename T>
void compress(vector<T> &a) {
sort(a.begin(), a.end());
a.resize(unique(a.begin(), a.end()) - a.begin());
}
template <typename T>
long long sqr(T x) {
return 1LL * x * x;
}
template <typename T1, typename T2>
long long gcd(T1 a, T2 b) {
return (b == 0 ? a : gcd(b, a % b));
}
template <typename T1, typename T2>
long long lcm(T1 a, T2 b) {
return 1LL * a / gcd(a, b) * b;
}
} // namespace Function
using namespace Function;
namespace Output {
void print(int x) { cout << x << "\n"; }
void print(unsigned int x) { cout << x << "\n"; }
void print(long unsigned int x) { cout << x << "\n"; }
void print(long long x) { cout << x << "\n"; }
void print(unsigned long long x) { cout << x << "\n"; }
void print(float x) { cout << x << "\n"; }
void print(double x) { cout << x << "\n"; }
void print(long double x) { cout << x << "\n"; }
void print(char x) { cout << x << "\n"; }
void print(const char *x) { cout << x << "\n"; }
void print(string x) { cout << x << "\n"; }
void print(bool x) { cout << x << "\n"; }
template <class T, class... Ts>
void print(T t, Ts... ts) {
cout << t << " ";
print(ts...);
}
template <typename T1, typename T2>
void print(pair<T1, T2> a) {
print(a.first, a.second);
}
template <typename T>
void print(T a) {
for (auto it : a) {
print(it);
}
}
template <class T, class... Ts>
void prine(T t, Ts... ts) {
print(t, ts...);
exit(0);
}
} // namespace Output
using namespace Output;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
const int INF = 1e9;
const long long INFL = 1e18;
const int MOD = 1e9 + 7;
const int N = 1e5 + 10;
bool cur[10][N];
map<pair<int, int>, set<pair<int, int> > > t;
int main() {
setIO();
int n, q;
cin >> n >> q;
int cnt = 0;
for (int i = 0; i < q; i++) {
int x, y;
cin >> x >> y;
cur[x][y] ^= 1;
if (cur[x][y] == 0) {
cnt -= t[{x, y}].size();
for (auto it : t[{x, y}]) {
t[it].erase({x, y});
}
t[{x, y}].clear();
} else {
if (x == 1) {
for (int j = -1; j <= 1; j++) {
if (cur[2][y + j]) {
t[{2, y + j}].insert({x, y});
t[{x, y}].insert({2, y + j});
cnt++;
}
}
} else {
for (int j = -1; j <= 1; j++) {
if (cur[1][y + j]) {
t[{1, y + j}].insert({x, y});
t[{x, y}].insert({1, y + j});
cnt++;
}
}
}
}
print((cnt == 0 ? "YES" : "NO"));
}
return 0;
}
|
#include <bits/stdc++.h>
const int N = 1e5 + 51;
int n, x, y, a[3][N], cnt;
int main() {
for (scanf("%d%*d", &n); ~scanf("%d%d", &x, &y);) {
a[x][y] ^= 1;
if (!a[x][y])
cnt -= a[3 - x][y - 1] + a[3 - x][y] + a[3 - x][y + 1];
else
cnt += a[3 - x][y - 1] + a[3 - x][y] + a[3 - x][y + 1];
puts(cnt ? "No" : "Yes");
}
}
|
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int INF = 1e9;
const int N = 1e5 + 1;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, i, q, a, b, ans = 0;
cin >> n >> q;
vector<int> one(n + 1);
vector<int> two(n + 1);
while (q--) {
cin >> a >> b;
if (a == 1) {
if (one[b] == 0) {
one[b] = 1;
if (two[b] == 1) ans++;
if (two[b + 1] == 1) ans++;
if (two[b - 1] == 1) ans++;
} else {
one[b] = 0;
if (two[b] == 1) ans--;
if (two[b + 1] == 1) ans--;
if (two[b - 1] == 1) ans--;
}
} else {
if (two[b] == 0) {
two[b] = 1;
if (one[b] == 1) ans++;
if (one[b + 1] == 1) ans++;
if (one[b - 1] == 1) ans++;
} else {
two[b] = 0;
if (one[b] == 1) ans--;
if (one[b + 1] == 1) ans--;
if (one[b - 1] == 1) ans--;
}
}
if (ans == 0)
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000020;
const int K = 60;
const int MOd = 1e9 + 7;
int a, ar[3][maxn], q;
void solve(int n) {
scanf("%d %d", &a, &q);
int num = 0;
for (int i = 1, x, y; i <= q; i++) {
scanf("%d %d", &x, &y);
x--;
if (ar[x][y] == 1) {
num -= ar[!x][y - 1];
num -= ar[!x][y];
num -= ar[!x][y + 1];
} else {
num += ar[!x][y - 1];
num += ar[!x][y];
num += ar[!x][y + 1];
}
ar[x][y] ^= 1;
if (num)
printf("No\n");
else
printf("Yes\n");
}
}
int main() {
int n = 1;
for (int i = 1; i <= n; i++) solve(i);
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const long long dx[4] = {-1, 1, 0, 0};
const long long dy[4] = {0, 0, -1, 1};
long long XX[] = {-1, -1, -1, 0, 0, 1, 1, 1};
long long YY[] = {-1, 0, 1, -1, 1, -1, 0, 1};
const long long N = (long long)(6 * 1e5 + 10);
const long long M = 1e9 + 7;
long long fact[N], invfact[N];
long long pow(long long a, long long b, long long m) {
long long ans = 1;
while (b) {
if (b & 1) ans = (ans * a) % m;
b /= 2;
a = (a * a) % m;
}
return ans;
}
long long modinv(long long k) {
return pow(k, (long long)998244353 - 2, (long long)998244353);
}
void precompute() {
fact[0] = fact[1] = 1;
for (long long i = 2; i < N; i++)
fact[i] = fact[i - 1] * i, fact[i] %= (long long)998244353;
invfact[N - 1] = modinv(fact[N - 1]);
for (long long i = N - 2; i >= 0; i--)
invfact[i] = invfact[i + 1] * (i + 1), invfact[i] %= (long long)998244353;
}
long long nCr(long long x, long long y) {
if (y > x) return 0;
long long num = fact[x];
num *= invfact[y];
num %= (long long)998244353;
num *= invfact[x - y];
num %= (long long)998244353;
return num;
}
int32_t main() {
;
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
long long n, q;
cin >> n >> q;
set<pair<long long, long long> > rec;
long long bad_neig = 0;
for (long long i = 0; i < q; i++) {
long long row, col;
cin >> row >> col;
row--, col--;
bool was_forbidden = rec.count({row, col});
for (long long i = row - 1; i <= row + 1; i++)
for (long long j = col - 1; j <= col + 1; j++) {
if (i >= 0 and i < 2 and j >= 0 and j < n)
if (i != row and rec.count({i, j}) == 1)
if (was_forbidden)
bad_neig--;
else
bad_neig++;
}
if (rec.count({row, col}))
rec.erase({row, col});
else
rec.insert({row, col});
if (bad_neig >= 1)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
}
|
#include <bits/stdc++.h>
template <typename Tp>
void read(Tp &res) {
static char ch;
ch = getchar(), res = 0;
static bool flag;
flag = 0;
while (ch < '0' || ch > '9') flag = (ch == '-'), ch = getchar();
while (ch >= '0' && ch <= '9') res = res * 10 + ch - 48, ch = getchar();
if (flag) res = -res;
}
void read(char *s) {
static char ch;
ch = getchar();
while (ch < 'a' || ch > 'z') ch = getchar();
while (ch >= 'a' && ch <= 'z') *(s++) = ch, ch = getchar();
*s = '\0';
}
const int maxn = 1e5 + 19;
int n, q, d;
bool ok[maxn][2];
int main() {
read(n), read(q);
for (int i = 1; i <= n; ++i) ok[i][0] = ok[i][1] = true;
while (q--) {
int u, v;
read(u), read(v), --u;
if (!ok[v][0] && !ok[v][1])
--d;
else {
if (v < n && !ok[v][0] && !ok[v + 1][1] && ok[v + 1][0]) --d;
if (v < n && !ok[v][1] && !ok[v + 1][0] && ok[v + 1][1]) --d;
if (v > 1 && !ok[v][0] && !ok[v - 1][1] && ok[v - 1][0]) --d;
if (v > 1 && !ok[v][1] && !ok[v - 1][0] && ok[v - 1][1]) --d;
}
ok[v][u] ^= 1;
if (!ok[v][0] && !ok[v][1])
++d;
else {
if (v < n && !ok[v][0] && !ok[v + 1][1] && ok[v + 1][0]) ++d;
if (v < n && !ok[v][1] && !ok[v + 1][0] && ok[v + 1][1]) ++d;
if (v > 1 && !ok[v][0] && !ok[v - 1][1] && ok[v - 1][0]) ++d;
if (v > 1 && !ok[v][1] && !ok[v - 1][0] && ok[v - 1][1]) ++d;
}
puts(d ? "No" : "Yes");
}
}
|
#include <bits/stdc++.h>
using namespace std;
mt19937_64 rang(
chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
uniform_int_distribution<int> uid(0, lim - 1);
return uid(rang);
}
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + 7;
void solve() {
int n, q;
cin >> n >> q;
int a[2][n];
for (int i = 0; i < 2; i++) {
for (int j = 0; j < n; j++) a[i][j] = 1;
}
int cnt = 0;
while (q--) {
int x, y;
cin >> x >> y;
x -= 1, y -= 1;
a[x][y] ^= 1;
if (a[x][y] == 0) {
if (y - 1 >= 0 and a[x ^ 1][y - 1] == 0) cnt++;
if (a[x ^ 1][y] == 0) cnt++;
if (y + 1 < n and a[x ^ 1][y + 1] == 0) cnt++;
} else {
if (y - 1 >= 0 and a[x ^ 1][y - 1] == 0) cnt--;
if (a[x ^ 1][y] == 0) cnt--;
if (y + 1 < n and a[x ^ 1][y + 1] == 0) cnt--;
}
if (cnt >= 1)
cout << "No\n";
else
cout << "Yes\n";
}
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
srand(chrono::high_resolution_clock::now().time_since_epoch().count());
int t = 1;
while (t--) {
solve();
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int n, q;
bool f[100005];
bool a[3][100005];
void init() {
cin >> n >> q;
memset(f, 1, sizeof(f));
memset(a, 1, sizeof(a));
}
bool chk(int k) {
if (a[1][k] && a[1][k + 1]) return true;
if (a[2][k] && a[2][k + 1]) return true;
return false;
}
void exeCute() {
int nopass = 0;
for (int i = 1; i <= q; i++) {
int r, c;
cin >> r >> c;
if (a[r][c]) {
a[r][c] = !a[r][c];
if (c > 1) {
bool now = chk(c - 1);
if (!now && f[c - 1]) nopass++;
f[c - 1] = now;
}
if (c < n) {
bool now = chk(c);
if (!now && f[c]) nopass++;
f[c] = now;
}
} else {
a[r][c] = !a[r][c];
if (c > 1) {
bool now = chk(c - 1);
if (now && !f[c - 1]) nopass--;
f[c - 1] = now;
}
if (c < n) {
bool now = chk(c);
if (now && !f[c]) nopass--;
f[c] = now;
}
}
if (nopass == 0)
cout << "YES" << endl;
else
cout << "NO" << endl;
}
}
int main(int argc, char* argv[]) {
init();
exeCute();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
long long n, q, l, r;
cin >> n >> q;
long long arr[3][n + 2];
memset(arr, 0, sizeof(arr));
long long lock = 0;
while (q--) {
cin >> l >> r;
if (arr[l][r] == 0) {
arr[l][r] = 1;
if (l == 1) {
if (arr[l + 1][r] == 1) {
lock++;
}
if (arr[l + 1][r - 1] == 1) {
lock++;
}
if (arr[l + 1][r + 1] == 1) {
lock++;
}
} else {
if (arr[l - 1][r] == 1) {
lock++;
}
if (arr[l - 1][r - 1] == 1) {
lock++;
}
if (arr[l - 1][r + 1] == 1) {
lock++;
}
}
} else {
arr[l][r] = 0;
if (l == 1) {
if (arr[l + 1][r] == 1) {
lock--;
}
if (arr[l + 1][r - 1] == 1) {
lock--;
}
if (arr[l + 1][r + 1] == 1) {
lock--;
}
} else {
if (arr[l - 1][r] == 1) {
lock--;
}
if (arr[l - 1][r - 1] == 1) {
lock--;
}
if (arr[l - 1][r + 1] == 1) {
lock--;
}
}
}
if (lock)
cout << "No\n";
else
cout << "Yes\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
bool rc[3][100010];
int sum = 0, r, c;
inline int read() {
int s = 0, w = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') w = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
int main() {
int n, q;
n = read();
q = read();
for (int i = 1; i <= q; i++) {
r = read();
c = read();
if (rc[r][c]) {
for (int i = c - 1; i <= c + 1; i++) {
if (rc[3 - r][i]) sum--;
}
} else {
for (int i = c - 1; i <= c + 1; i++) {
if (rc[3 - r][i]) sum++;
}
}
rc[r][c] = !rc[r][c];
if (sum)
printf("NO\n");
else
printf("YES\n");
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 5;
const long long INF = 1e18;
const long long MOD = 1e9 + 7;
map<pair<int, int>, bool> mp;
int main() {
time_t START = clock();
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q;
scanf("%d%d", &n, &q);
int cnt = 0;
while (q--) {
int r, c;
scanf("%d%d", &r, &c);
r--;
int x = (mp[make_pair(r, c)] ? -1 : +1);
cnt += x * mp[make_pair(1 - r, c - 1)];
cnt += x * mp[make_pair(1 - r, c + 0)];
cnt += x * mp[make_pair(1 - r, c + 1)];
mp[make_pair(r, c)] = 1 - mp[make_pair(r, c)];
cout << (cnt == 0 ? "Yes" : "No") << "\n";
}
time_t FINISH = clock();
cerr << "Execution time: "
<< (long double)(FINISH - START) / CLOCKS_PER_SEC * 1000.0
<< " milliseconds.\n";
return 0;
}
|
#include <bits/stdc++.h>
const int N = 200010;
bool a[2][N];
int n, q;
int ans;
int main(void) {
std::cin >> n >> q;
for (register int i = 1, x, y; i <= q; ++i) {
std::cin >> x >> y;
--x;
a[x][y] = !a[x][y];
if (a[x][y]) {
for (register int j = std::max(1, y - 1); j <= std::min(n, y + 1); ++j) {
if (a[x ^ 1][j]) {
++ans;
}
}
} else {
for (register int j = std::max(1, y - 1); j <= std::min(n, y + 1); ++j) {
if (a[x ^ 1][j]) {
--ans;
}
}
}
if (!ans) {
puts("Yes");
} else {
puts("No");
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 5;
bool a[3][maxn];
int n, q;
int main() {
ios::sync_with_stdio(false);
cin >> n >> q;
int ans = 0;
for (int i = 1; i <= q; i++) {
int x, y;
cin >> x >> y;
if (x == 1) {
if (a[x][y]) {
a[x][y] = 0;
if (a[2][y]) ans--;
if (a[2][y + 1]) ans--;
if (a[2][y - 1]) ans--;
} else {
a[x][y] = 1;
if (a[2][y]) ans++;
if (a[2][y + 1]) ans++;
if (a[2][y - 1]) ans++;
}
} else {
if (a[x][y]) {
a[x][y] = 0;
if (a[1][y]) ans--;
if (a[1][y + 1]) ans--;
if (a[1][y - 1]) ans--;
} else {
a[x][y] = 1;
if (a[1][y]) ans++;
if (a[1][y + 1]) ans++;
if (a[1][y - 1]) ans++;
}
}
if (ans)
cout << "No" << endl;
else
cout << "Yes" << endl;
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
int n, q;
cin >> n >> q;
int blc = 0;
map<int, bool> up;
map<int, bool> dow;
while (q--) {
int r, c;
cin >> r >> c;
if (r == 1) {
if (dow.count(c)) {
dow.erase(c);
for (int b = c - 1; b <= c + 1; b++) {
if (up.count(b)) {
blc--;
}
}
} else {
dow[c] = true;
for (int b = c - 1; b <= c + 1; b++) {
if (up.count(b)) {
blc++;
}
}
}
} else {
if (up.count(c)) {
up.erase(c);
for (int b = c - 1; b <= c + 1; b++) {
if (dow.count(b)) {
blc--;
}
}
} else {
up[c] = true;
for (int b = c - 1; b <= c + 1; b++) {
if (dow.count(b)) {
blc++;
}
}
}
}
if (blc) {
cout << "No\n";
} else {
cout << "Yes\n";
}
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int a[3][100020];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, q, no = 0;
cin >> n >> q;
for (int i = 1; i <= q; i++) {
int x, y;
cin >> x >> y;
a[x][y] = 1 - a[x][y];
if (a[x][y] == 1) {
if (a[3 - x][y] == 1) no++;
if (a[3 - x][y - 1] == 1) no++;
if (a[3 - x][y + 1] == 1) no++;
} else if (a[x][y] == 0) {
if (a[3 - x][y] == 1) no--;
if (a[3 - x][y - 1] == 1) no--;
if (a[3 - x][y + 1] == 1) no--;
}
if (no == 0)
cout << "YES\n";
else
cout << "NO\n";
}
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e9;
const int MOD = 1e9 + 7;
const long long INF = 1e18;
const long double PI = 3.14159265358979323846;
template <typename T>
void read(vector<T>& a) {
for (int i = 0; i < a.size(); ++i) cin >> a[i];
}
template <typename T>
void print(vector<T>& a) {
for (int i = 0; i < a.size(); ++i) cout << a[i] << " ";
cout << endl;
}
template <typename T>
void print2(vector<vector<T> >& a) {
for (int i = 0; i < a.size(); ++i) {
for (int j = 0; j < a[i].size(); ++j) cout << a[i][j] << " ";
cout << endl;
}
}
template <typename T>
void read2(vector<vector<T> >& a) {
for (int i = 0; i < a.size(); ++i)
for (int j = 0; j < a[i].size(); ++j) cin >> a[i][j];
}
void func(set<int>& st_layer1, set<int>& st_layer2, int v, int& cnt_blocks,
int increment) {
if (st_layer2.find(v - 1) != st_layer2.end()) {
cnt_blocks += increment;
}
if (st_layer2.find(v + 1) != st_layer2.end()) {
cnt_blocks += increment;
}
if (st_layer2.find(v) != st_layer2.end()) {
cnt_blocks += increment;
}
if (increment == -1) {
st_layer1.erase(v);
} else {
st_layer1.insert(v);
}
}
void write() {
int n, q;
cin >> n >> q;
vector<pair<int, int> > a(q);
for (int i = 0; i < q; ++i) {
cin >> a[i].first >> a[i].second;
}
set<int> st_layer1, st_layer2;
int cnt_blocks = 0;
for (int i = 0; i < q; ++i) {
if (a[i].first == 1) {
if (st_layer1.find(a[i].second) != st_layer1.end()) {
func(st_layer1, st_layer2, a[i].second, cnt_blocks, -1);
} else {
func(st_layer1, st_layer2, a[i].second, cnt_blocks, 1);
}
} else {
if (st_layer2.find(a[i].second) != st_layer2.end()) {
func(st_layer2, st_layer1, a[i].second, cnt_blocks, -1);
} else {
func(st_layer2, st_layer1, a[i].second, cnt_blocks, 1);
}
}
if (cnt_blocks == 0) {
cout << "YES" << endl;
} else {
cout << "NO" << endl;
}
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
T = 1;
for (int t = 0; t < T; ++t) write();
return 0;
}
|
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, q;
cin >> n >> q;
vector<vector<bool>> maze(2);
maze[0].resize(n, false);
maze[1].resize(n, false);
int r, c;
int deadEnd = 0;
while (q--) {
cin >> r >> c;
--r, --c;
int change = 1;
if (maze[r][c]) change = -1;
maze[r][c] = !maze[r][c];
for (int i = -1; i <= 1; ++i)
if (c + i > -1 && c + i < n && maze[1 - r][c + i]) deadEnd += change;
if (!deadEnd)
cout << "YES\n";
else
cout << "NO\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 100;
int mp[3][maxn];
int a[maxn];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, q, r, c;
cin >> n >> q;
int flag1 = 1, flag2 = 1, cnt = 0;
for (int i = 1; i <= q; i++) {
cin >> r >> c;
if (r == 1 && c == 1) flag1 = !flag1;
if (r == 2 && c == n) flag2 = !flag2;
if (!mp[r][c]) {
mp[r][c] = 1;
if (r == 1) {
if (mp[2][c]) cnt++;
if (mp[2][c - 1] && c - 1 >= 1) cnt++;
if (mp[2][c + 1] && c + 1 <= n) cnt++;
} else if (r == 2) {
if (mp[1][c]) cnt++;
if (mp[1][c - 1] && c - 1 >= 1) cnt++;
if (mp[1][c + 1] && c + 1 <= n) cnt++;
}
} else {
mp[r][c] = 0;
if (r == 1) {
if (mp[2][c]) cnt--;
if (mp[2][c - 1] && c - 1 >= 1) cnt--;
if (mp[2][c + 1] && c + 1 <= n) cnt--;
} else if (r == 2) {
if (mp[1][c]) cnt--;
if (mp[1][c - 1] && c - 1 >= 1) cnt--;
if (mp[1][c + 1] && c + 1 <= n) cnt--;
}
}
if (flag1 && flag2 && cnt == 0)
cout << "Yes\n";
else
cout << "No\n";
}
}
|
#include <bits/stdc++.h>
using namespace std;
int n, m, i, j, x, y, cur, a[3][100100], fin[100100], c[100100];
vector<int> r[100100];
int main() {
scanf("%d%d", &n, &m);
for (i = 1; i <= m; i++) {
scanf("%d%d", &x, &y);
if (a[x][y] == 0) {
a[x][y] = i;
for (j = y - 1; j < y + 2; j++)
if (j > 0 && j <= n && a[3 - x][j]) r[i].push_back(a[3 - x][j]);
} else {
fin[a[x][y]] = i;
a[x][y] = 0;
}
}
for (i = 1; i <= m; i++)
if (fin[i] == 0) fin[i] = m + 1;
for (i = 1; i <= m; i++)
for (j = 0; j < r[i].size(); j++) {
c[max(i, r[i][j])]++;
c[min(fin[i], fin[r[i][j]])]--;
}
for (i = 1; i <= m; i++) {
cur += c[i];
puts(cur ? "No" : "Yes");
}
return 0;
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.