text
stringlengths
49
983k
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma comment(linker, "/STACK:2759095000") using namespace std; const long long MOD = 998244353; const long long MOD1 = 7340033; const long long BAS = 2500; const long long dy[] = {1, -1, 0, 0, 1, -1}; const long long dx[] = {1, 1, 1, -1, -1, -1}; const long long INF = 1e9; const double EPS = 1e-9; const long double PI = 3.14159265358979323846; const int SZ = 2000; const long long MAXN = 1e6 + 10; long long bp(long long x, long long st) { if (st == 0) return 1; if (st & 1) return x * bp(x, st - 1) % MOD; return bp(x * x % MOD, st >> 1); } long long x, y, z, n, m, k, a[2][MAXN], b[MAXN], c[MAXN]; string s, t; bool inp(int x, int y) { return x >= 0 && x < 2 && y >= 0 && y < n; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(6); srand(89398); cin >> n >> m; for (int i = 0; i < n; i++) { a[0][i] = 0; a[1][i] = 0; } set<pair<pair<long long, long long>, pair<long long, long long>>> us; for (int i = 0; i < m; i++) { cin >> x >> y; x--, y--; a[x][y] ^= 1; for (int j = 0; j < 6; j++) { int nx = x + dx[j], ny = y + dy[j]; if (!inp(nx, ny)) continue; if (a[nx][ny] == 1) { if (a[x][y] == 0) { us.erase({{x, y}, {nx, ny}}); us.erase({{nx, ny}, {x, y}}); } else { us.insert({{x, y}, {nx, ny}}); us.insert({{nx, ny}, {x, y}}); } } } if (us.size() == 0) cout << "Yes\n"; else cout << "No\n"; } }
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, q, check[3][N], cnt, a, b; int main() { cin >> n >> q; for (int i = 1; i <= q; i++) { cin >> a >> b; a--; check[a][b] = !check[a][b]; if (check[a][b]) { if (check[!a][b - 1]) cnt++; if (check[!a][b]) cnt++; if (check[!a][b + 1]) cnt++; } else { if (check[!a][b - 1]) cnt--; if (check[!a][b]) cnt--; if (check[!a][b + 1]) cnt--; } if (cnt) cout << "No\n"; else cout << "Yes\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; bool lava[2][n]; for (int i = 0; i < 2; i++) { for (int j = 0; j < n; j++) lava[i][j] = false; } set<int> blocked1; set<int> blocked2; for (int i = 0; i < q; i++) { int r, c; cin >> r >> c; r--; c--; if (lava[r][c]) { blocked2.erase(c); if (c < n - 1 && !lava[r][c + 1]) { blocked1.erase(c); } if (c > 0 && !lava[r][c - 1]) { blocked1.erase(c - 1); } } else { if (lava[(r + 1) % 2][c]) { blocked2.insert(c); } if (c < n - 1 && lava[(r + 1) % 2][c + 1]) { blocked1.insert(c); } if (c > 0 && lava[(r + 1) % 2][c - 1]) { blocked1.insert(c - 1); } } lava[r][c] = !lava[r][c]; if (blocked1.empty() && blocked2.empty() && !lava[0][0] && !lava[1][n - 1]) { cout << "Yes" << endl; } else { cout << "No" << endl; } } }
#include <bits/stdc++.h> using namespace std; float PHI = 1.6180339; const float PI_F = 3.14159265358979f; bool isPrime(long long n) { if (n <= 1) return true; for (long long i = 2; i < n; i++) if (n % i == 0) return false; return true; } long long modpow(long long x, long long n, long long m) { if (n == 0) return 1 % m; long long u = modpow(x, n / 2, m); u = (u * u) % m; if (n % 2 == 1) u = (u * x) % m; return u; } bool sortinrev(const pair<long long, long long> &a, const pair<long long, long long> &b) { return (a.first > b.first); } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(); cout.tie(); cout << fixed << setprecision(12); long long n, q; cin >> n >> q; long long arr1[n + 10]; long long arr2[n + 10]; for (long long i = 1; i <= n; i++) { arr1[i] = 0; arr2[i] = 0; } long long shock = 0; for (long long i = 0; i < q; i++) { long long a, b; cin >> a >> b; if (a == 1) { if (arr1[b] == 0) { arr1[b] = 1; if (arr2[b] == 1) { ++shock; } if (arr2[b - 1] == 1) { ++shock; } if (arr2[b + 1] == 1) { ++shock; } } else { arr1[b] = 0; if (arr2[b] == 1) { --shock; } if (arr2[b - 1] == 1) { --shock; } if (arr2[b + 1] == 1) { --shock; } } } else if (a == 2) { if (arr2[b] == 0) { arr2[b] = 1; if (arr1[b] == 1) { ++shock; } if (arr1[b - 1] == 1) { ++shock; } if (arr1[b + 1] == 1) { ++shock; } } else { arr2[b] = 0; if (arr1[b] == 1) { --shock; } if (arr1[b - 1] == 1) { --shock; } if (arr1[b + 1] == 1) { --shock; } } } if (shock == 0) cout << "Yes" << "\n"; else cout << "No" << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long n, q; cin >> n >> q; long i, j; int** a = new int*[2]; for (i = 0; i < 2; ++i) { a[i] = new int[n + 2]; for (j = 0; j < n + 2; j++) { a[i][j] = 0; } } long res = 0; long x, y; while (q--) { cin >> x >> y; if (a[x - 1][y] == 0) { a[x - 1][y] = 1; for (i = -1; i <= 1; i++) { if (a[2 - x][y + i] == 1) res++; } } else { a[x - 1][y] = 0; for (i = -1; i <= 1; i++) { if (a[2 - x][y + i] == 1) { res--; } } } if (res == 0) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, q; int a[5][100005]; void mo() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); } void nhap() { cin >> n >> q; int yeuto = 0; for (int i = 1; i <= q; i++) { int u, v; cin >> u >> v; if (a[u][v] == 0) { a[u][v] = 1; if (u == 1) { if (a[2][v] == 1) yeuto += 2; if (v > 1 && a[2][v - 1] == 1) yeuto += 2; if (v < n && a[2][v + 1] == 1) yeuto += 2; } else { if (a[1][v] == 1) yeuto += 2; if (v > 1 && a[1][v - 1] == 1) yeuto += 2; if (v < n && a[1][v + 1] == 1) yeuto += 2; } } else { a[u][v] = 0; if (u == 1) { if (a[2][v] == 1) yeuto -= 2; if (v > 1 && a[2][v - 1] == 1) yeuto -= 2; if (v < n && a[2][v + 1] == 1) yeuto -= 2; } else { if (a[1][v] == 1) yeuto -= 2; if (v > 1 && a[1][v - 1] == 1) yeuto -= 2; if (v < n && a[1][v + 1] == 1) yeuto -= 2; } } if (a[1][1] == 0 && a[2][n] == 0 && yeuto == 0) cout << "YES\n"; else cout << "NO\n"; } } int main() { mo(); nhap(); }
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5, MOD = 1e9 + 7; long long n, q, cnt[4][N]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> q; long long val = 0; while (q--) { long long r, c; cin >> r >> c; r--, c--; if (cnt[r][c]) { cnt[r][c] = 0; if (cnt[r ^ 1][c] == 1) val++; if (c - 1 >= 0 && cnt[r ^ 1][c - 1] == 1) val++; if (c + 1 < n && cnt[r ^ 1][c + 1] == 1) val++; } else { cnt[r][c] = 1; if (cnt[r ^ 1][c] == 1) val--; if (c - 1 >= 0 && cnt[r ^ 1][c - 1] == 1) val--; if (c + 1 < n && cnt[r ^ 1][c + 1] == 1) val--; } if (val == 0) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout.precision(20); int x, y, n, q, ch; cin >> n >> q; int a[3][n + 1]; for (int i = (0), i_end_ = (3); i < i_end_; ++i) for (int j = (0), j_end_ = (n + 1); j < j_end_; ++j) a[i][j] = 0; map<pair<int, int>, int> m; pair<int, int> p; bool possible = true; while (q--) { cin >> x >> y; a[x][y] = 1 - a[x][y]; if (a[x][y]) { if (x == 1) ch = 2; else ch = 1; if (a[ch][y]) { m[make_pair(ch, y)]++; m[make_pair(x, y)]++; } if (y > 1 && a[ch][y - 1]) { m[make_pair(ch, y - 1)]++; m[make_pair(x, y)]++; } if (y < n && a[ch][y + 1]) { m[make_pair(ch, y + 1)]++; m[make_pair(x, y)]++; } } else { if (x == 1) ch = 2; else ch = 1; if (a[ch][y]) { m[make_pair(ch, y)]--; m[make_pair(x, y)]--; if (m[make_pair(ch, y)] == 0) m.erase(make_pair(ch, y)); if (m[make_pair(x, y)] == 0) m.erase(make_pair(x, y)); } if (y > 1 && a[ch][y - 1]) { m[make_pair(ch, y - 1)]--; m[make_pair(x, y)]--; if (m[make_pair(ch, y - 1)] == 0) m.erase(make_pair(ch, y - 1)); if (m[make_pair(x, y)] == 0) m.erase(make_pair(x, y)); } if (y < n && a[ch][y + 1]) { m[make_pair(ch, y + 1)]--; m[make_pair(x, y)]--; if (m[make_pair(ch, y + 1)] == 0) m.erase(make_pair(ch, y + 1)); if (m[make_pair(x, y)] == 0) m.erase(make_pair(x, y)); } } if (m.size() == 0) cout << "YES\n"; else cout << "NO\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; int main() { ll n, q; cin >> n >> q; vector<vector<int>> v(2, vector<int>(n + 2, 0)); ll block = 0; while (q-- > 0) { int r, c; cin >> r >> c; r--; if (v[!r][c]) block += 1 - 2 * v[r][c]; if (v[!r][c + 1]) block += 1 - 2 * v[r][c]; if (v[!r][c - 1]) block += 1 - 2 * v[r][c]; v[r][c] ^= 1; cout << (block == 0 ? "Yes" : "No") << "\n"; } }
#include <bits/stdc++.h> using namespace std; struct TP {}; int maze[3][100005]; int n, q, x, y; int block() { int b = 0; if (x == 1 and maze[2][y]) b++; if (x == 2 and maze[1][y]) b++; if (x == 1 and y > 1 and maze[2][y - 1]) b++; if (x == 1 and y < n and maze[2][y + 1]) b++; if (x == 2 and y > 1 and maze[1][y - 1]) b++; if (x == 2 and y < n and maze[1][y + 1]) b++; return b; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); scanf("%d %d", &n, &q); int blocks = 0; while (q--) { scanf("%d %d", &x, &y); if (maze[x][y]) { maze[x][y] = false; blocks -= block(); } else { maze[x][y] = true; blocks += block(); } puts(blocks == 0 ? "YES" : "NO"); } return 0; }
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; const long long int MOD = 1e9 + 7; const int N = 100005; long long int fact[N]; int dr[] = {0, +1, -1}; int dc[] = {+1, 0, 0}; int G[4][N]; int vis[2][N]; int n; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); read: int q; cin >> n >> q; for (int i = 0; i < 4; i++) { for (int j = 0; j <= n; j++) G[i][j] = 0; } int r, c, x = 0, t = 0; while (q--) { t++; cin >> r >> c; if (G[r][c] == 1) { G[r][c] = 0; if (G[r - 1][c]) { if (x > 0) x--; } if (G[r - 1][c - 1]) { if (x > 0) x--; } if (G[r - 1][c + 1]) { if (x > 0) x--; } if (G[r + 1][c]) { if (x > 0) x--; } if (G[r + 1][c - 1]) { if (x > 0) x--; } if (G[r + 1][c + 1]) { if (x > 0) x--; } } else { G[r][c] = 1; if (G[r - 1][c]) { x++; } if (G[r - 1][c - 1]) { x++; } if (G[r - 1][c + 1]) { x++; } if (G[r + 1][c]) { x++; } if (G[r + 1][c - 1]) { x++; } if (G[r + 1][c + 1]) { x++; } } if (x) cout << "NO" << endl; else cout << "YES" << endl; } }
#include <bits/stdc++.h> using namespace std; struct SegTree { int size; vector<long long> seg; SegTree() {} SegTree(int size) { this->size = size; seg.resize(1 << (size + 1)); } void init() { for (int i = 0; i < (1 << (size + 1)); i++) seg[i] = 1e18; } void update(int i, long long val) { i += (1 << size); seg[i] = val; while (i > 1) { i /= 2; seg[i] = min(seg[i * 2], seg[i * 2 + 1]); } } long long query(int a, int b, int k, int l, int r) { if (b < l || r < a) return 1e18; if (a <= l && r <= b) return seg[k]; long long lval = query(a, b, k * 2, l, (l + r) / 2); long long rval = query(a, b, k * 2 + 1, (l + r) / 2 + 1, r); return min(lval, rval); } long long query(int a, int b) { return query(a, b, 1, 0, (1 << size) - 1); } }; long long n, Q; bool used[2][100005]; long long cover[2][100005]; long long val[100005]; SegTree seg(17); int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> Q; seg.init(); for (int i = 1; i <= n; i++) seg.update(i, 0); long long x, y; for (int i = 1; i <= Q; i++) { cin >> x >> y; x--; long long add; if (used[x][y]) add = -1; else add = 1; if (x == 0) cover[x][y] += add; else { for (int i = -1; i <= 1; i++) cover[x][y + i] += add; } for (int i = -1; i <= 1; i++) { val[y + i] = 0; if (cover[0][y + i] > 0) val[y + i]--; if (cover[1][y + i] > 0) val[y + i]--; seg.update(y + i, val[y + i]); } used[x][y] = !used[x][y]; if (seg.query(1, n) <= -2) cout << "No" << "\n"; else cout << "Yes" << "\n"; } flush(cout); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n, q, k = 0; cin >> n >> q; int arr[3][n + 1]; for (int i = 0; i < 3; i++) { for (int j = 0; j <= n; j++) arr[i][j] = 1; } while (q--) { int a, b; cin >> a >> b; if (arr[a][b] == 1) { arr[a][b] = 0; if (a == 2 && arr[a - 1][b - 1] == 0 && b > 1) k++; if (a == 1 && arr[a + 1][b - 1] == 0) k++; if (a == 2 && arr[a - 1][b + 1] == 0) k++; if (a == 1 && arr[a + 1][b + 1] == 0 && b < n) k++; if (a == 2 && arr[a - 1][b] == 0) k++; if (a == 1 && arr[a + 1][b] == 0) k++; } else { arr[a][b] = 1; if (a == 2 && arr[a - 1][b - 1] == 0 && b > 1) k--; if (a == 1 && arr[a + 1][b - 1] == 0) k--; if (a == 2 && arr[a - 1][b + 1] == 0) k--; if (a == 1 && arr[a + 1][b + 1] == 0 && b < n) k--; if (a == 2 && arr[a - 1][b] == 0) k--; if (a == 1 && arr[a + 1][b] == 0) k--; } if (k == 0) cout << "Yes" << endl; else cout << "No" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; using vll = vector<ll>; using pairll = pair<ll, ll>; using vvll = vector<vll>; using vint = vector<int>; using pint = pair<int, int>; using vvint = vector<vint>; int main() { ios::sync_with_stdio(false); cin.tie(NULL); set<tuple<int, int, int, int> > bad; int n, q, x, y; cin >> n >> q; vector<vector<bool> > good(n); for (int i = 0; i < n; i++) { good[i].resize(2, 0); } for (int i = 0; i < q; i++) { cin >> x >> y; x--; y--; if (good[y][x]) { bad.erase(make_tuple(y, x, y, !x)); bad.erase(make_tuple(y, !x, y, x)); bad.erase(make_tuple(max(y - 1, 0), !x, y, x)); bad.erase(make_tuple(y, x, max(y - 1, 0), !x)); bad.erase(make_tuple(min(n - 1, y + 1), !x, y, x)); bad.erase(make_tuple(y, x, min(n - 1, y + 1), !x)); } else { if (good[y][!x]) { bad.insert(make_tuple(y, x, y, !x)); } if (good[max(y - 1, 0)][!x]) { bad.insert(make_tuple(max(y - 1, 0), !x, y, x)); } if (good[min(n - 1, y + 1)][!x]) { bad.insert(make_tuple(min(n - 1, y + 1), !x, y, x)); } } if (bad.empty()) { puts("yes"); } else { puts("no"); } good[y][x] = !good[y][x]; } }
#include <bits/stdc++.h> using namespace std; int main() { int n, q; cin >> n >> q; int table[2][n]; memset(table, 0, sizeof table); set<pair<pair<int, int>, pair<int, int> > > parede; while (q--) { int r, c; cin >> r >> c; r--; c--; table[r][c] = 1 - table[r][c]; if (table[r][c]) { int raux = 1 - r; for (int i = c - 1; i <= c + 1; i++) { if (i >= 0 && i < n && table[raux][i]) { pair<int, int> a, b; a.first = r; a.second = c; b.first = raux; b.second = i; parede.insert(make_pair(a, b)); parede.insert(make_pair(b, a)); } } } else { int raux = 1 - r; for (int i = c - 1; i <= c + 1; i++) { if (i >= 0 && table[raux][i]) { pair<int, int> a, b; a.first = r; a.second = c; b.first = raux; b.second = i; parede.erase(make_pair(a, b)); parede.erase(make_pair(b, a)); } } } if (parede.empty()) { cout << "Yes\n"; } else { cout << "No\n"; } } return 0; }
#include <bits/stdc++.h> using namespace std; long long n, q; int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> q; set<pair<long long, long long>> b; long long c = 0; while (q--) { long long x, y; cin >> x >> y; x--; y--; if (b.find({x, y}) != b.end()) { if (b.find({(x + 1) % 2, y}) != b.end()) c--; if (y + 1 < n && b.find({(x + 1) % 2, y + 1}) != b.end()) c--; if (y - 1 >= 0 && b.find({(x + 1) % 2, y - 1}) != b.end()) c--; b.erase({x, y}); } else { b.insert({x, y}); if (b.find({(x + 1) % 2, y}) != b.end()) c++; if (y + 1 < n && b.find({(x + 1) % 2, y + 1}) != b.end()) c++; if (y - 1 >= 0 && b.find({(x + 1) % 2, y - 1}) != b.end()) c++; } if (c > 0) cout << "No" << '\n'; else cout << "Yes" << '\n'; } }
#include <bits/stdc++.h> using namespace std; long long a[3][200009], b[200009], c[200009]; signed main() { long long n, i, m, c = 0; cin >> n >> m; set<pair<long long, long long> > v; while (m--) { long long x, y; cin >> x >> y; if (a[x][y]) { c -= (a[3 - x][y] + a[3 - x][y - 1] + a[3 - x][y + 1]); a[x][y] = 0; } else if (a[x][y] == 0) { c += (a[3 - x][y] + a[3 - x][y - 1] + a[3 - x][y + 1]); a[x][y] = 1; } if (c) cout << "No\n"; else cout << "Yes\n"; } }
#include <bits/stdc++.h> int min(int, int); int max(int, int); int cmp(const void *, const void *); long long cmpl(const void *, const void *); int _gcd(int, int); int lcm(int, int); int bSearch(int *, int, int, int); int main(int argc, char *argv[]) { int n, a[3][100000 + 5], i, j, k, b[100000 + 5][3], r, c, bl = 0; scanf("%d%d", &n, &k); for (i = 0; i < k; i++) scanf("%d%d", &b[i][0], &b[i][1]); for (i = 0; i < 3; i++) for (j = 0; j < n + 5; j++) a[i][j] = 1; for (i = 0; i < k; i++) { r = b[i][0]; c = b[i][1]; if (a[r][c] == 0) { if (!a[3 - r][c]) bl--; if (!a[3 - r][c - 1]) bl--; if (!a[3 - r][c + 1]) bl--; a[r][c] = 1; } else { if (!a[3 - r][c]) bl++; if (!a[3 - r][c - 1]) bl++; if (!a[3 - r][c + 1]) bl++; a[r][c] = 0; } if (!bl) printf("YES\n"); else printf("NO\n"); } } int min(int a, int b) { if (a < b) return a; return b; } int max(int a, int b) { if (a > b) return a; return b; } int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; } long long cmpl(const void *a, const void *b) { return *(long long *)a - *(long long *)b; } int _gcd(int a, int b) { while (b) a ^= b, b ^= a, a ^= b, b = b % a; return a; } int lcm(int a, int b) { return (a * b) / (_gcd(a, b)); } int bSearch(int *a, int l, int r, int item) { int mid; while (l <= r) { mid = (l + r) / 2; if (item > a[mid]) l = mid + 1; else if (item < a[mid]) r = mid - 1; else if (item == a[mid]) return mid; } return -1; }
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int v[4][100002], nr, n, q, x, y; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> q; while (q--) { cin >> x >> y; v[x][y] ^= 1; if (v[x][y] == 1) { if (v[x - 1][y - 1]) nr++; if (v[x - 1][y + 1]) nr++; if (v[x + 1][y - 1]) nr++; if (v[x + 1][y + 1]) nr++; if (v[x + 1][y]) nr++; if (v[x - 1][y]) nr++; } else { if (v[x - 1][y - 1]) nr--; if (v[x - 1][y + 1]) nr--; if (v[x + 1][y - 1]) nr--; if (v[x + 1][y + 1]) nr--; if (v[x + 1][y]) nr--; if (v[x - 1][y]) nr--; } if (nr) cout << "NO\n"; else cout << "YES\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; class pair_hash { public: long long operator()(const pair<long long, long long> &p) const { return (p.first << 16) + p.second; } }; using pset = unordered_set<pair<long long, long long>, pair_hash>; bool check(vector<vector<bool>> &ar, long long x, long long y) { if (ar[x][y] == false) { return false; } x = 1 - x; for (long long i : {y - 1, y, y + 1}) { if (i < 0 or ((long long)ar[0].size()) <= i) { continue; } if (ar[x][i] == true) { return true; } } return false; } bool update(vector<vector<bool>> &ar, pset &s, long long x, long long y) { if (check(ar, x, y)) { s.insert({x, y}); } else { s.erase({x, y}); } x = 1 - x; for (long long i : {y - 1, y, y + 1}) { if (i < 0 or ((long long)ar[0].size()) <= i) { continue; } if (check(ar, x, i)) { s.insert({x, i}); } else { s.erase({x, i}); } } return false; } signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); long long n, q; cin >> n >> q; vector<vector<bool>> ar(2, vector<bool>(n, false)); pset s; for (long long i = 0; i < q; ++i) { long long x, y; cin >> x >> y; x--; y--; ar[x][y] = ar[x][y] ^ true; update(ar, s, x, y); cout << (s.empty() ? "Yes" : "No") << "\n"; } }
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int n, v[N], cnt = 0, flg = 0; void cut(int y) { if (v[y] == 3) --cnt; else if (v[y]) { if (y + 1 <= n) { if ((v[y + 1] ^ v[y]) == 3) --flg; } if (y - 1 >= 1) { if ((v[y - 1] ^ v[y]) == 3) --flg; } } } void add(int y) { if (v[y] == 3) ++cnt; else if (v[y]) { if (y + 1 <= n) { if ((v[y + 1] ^ v[y]) == 3) ++flg; } if (y - 1 >= 1) { if ((v[y - 1] ^ v[y]) == 3) ++flg; } } } int main() { int q; cin >> n >> q; for (int o = 1; o <= q; ++o) { int x, y; cin >> x >> y; if (x == 1) { cut(y); v[y] ^= 1; add(y); } else { cut(y); v[y] ^= 2; add(y); } if (cnt || flg) puts("NO"); else puts("YES"); } return 0; }
#include <bits/stdc++.h> using namespace std; bool lava[5][100005]; int n, q; int main() { int up_down_cnt = 0; int full_block_cnt = 0; scanf("%d%d", &n, &q); for (int i = 1; i <= q; i++) { int r, c; scanf("%d%d", &r, &c); if (lava[r][c] && lava[3 - r][c]) full_block_cnt--; if (lava[r][c] && lava[3 - r][c - 1]) up_down_cnt--; if (lava[r][c] && lava[3 - r][c + 1]) up_down_cnt--; lava[r][c] = !lava[r][c]; if (lava[r][c] && lava[3 - r][c]) full_block_cnt++; if (lava[r][c] && lava[3 - r][c - 1]) up_down_cnt++; if (lava[r][c] && lava[3 - r][c + 1]) up_down_cnt++; printf("%s\n", up_down_cnt || full_block_cnt ? "No" : "Yes"); } return 0; }
#include <bits/stdc++.h> int c[4][100008] = {0}; int main() { int n, q, s = 0, a, b; scanf("%d%d", &n, &q); while (q--) { scanf("%d%d", &a, &b); if (c[a][b] == 0) c[a][b] = 1; else c[a][b] = 0; if (c[a][b] == 1) { if (a == 1) { if (c[a + 1][b] == 1) s++; if (c[a + 1][b - 1] == 1) s++; if (c[a + 1][b + 1] == 1) s++; } else { if (c[a - 1][b] == 1) s++; if (c[a - 1][b - 1] == 1) s++; if (c[a - 1][b + 1] == 1) s++; } } else { if (a == 1) { if (c[a + 1][b] == 1) s--; if (c[a + 1][b - 1] == 1) s--; if (c[a + 1][b + 1] == 1) s--; } else { if (c[a - 1][b] == 1) s--; if (c[a - 1][b - 1] == 1) s--; if (c[a - 1][b + 1] == 1) s--; } } if (s == 0) printf("Yes\n"); else printf("No\n"); } }
#include <bits/stdc++.h> using namespace std; using Int = long long; constexpr static int mod = 1e9 + 7; constexpr static int inf = (1 << 30) - 1; constexpr static Int infll = (1LL << 61) - 1; int Competitive_Programming = (ios_base::sync_with_stdio(false), cin.tie(nullptr), cout << fixed << setprecision(15), 0); #pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") int main() { int N, Q; cin >> N >> Q; vector<vector<int>> grid(2, vector<int>(N)); set<pair<int, int>> st; for (int i = 0; i < Q; i++) { int c, r; cin >> c >> r; c--, r--; for (int j = -1; j <= 1; j++) { if (r + j < 0 or r + j >= N) continue; if (grid[!c][r + j] == 1) { int x = r, y = r + j; if (c == 1) swap(x, y); if (grid[c][r] == 0) st.insert(make_pair(x, y)); else st.erase(make_pair(x, y)); } } cout << (st.size() == 0 ? "Yes" : "No") << "\n"; grid[c][r] = !grid[c][r]; } }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; long long quickmod(long long a, long long n) { long long s = 1; while (n) { if (n & 1) { s = s * a % mod; } a = (a * a) % mod; n = n / 2; } return s; } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } bool isPrime(long long x) { if (x <= 1) return false; if (x == 2) return true; if (x % 2 == 0) return false; long long i, m; m = sqrt(x); for (i = 2; i <= m; i++) { if (x % i == 0) return false; } return true; } const int N = 2e5 + 5; int t; int n, q, x, y, level; int a[3][N]; int main() { while (cin >> n >> q) { level = 0; for (register int i = 1; i <= q; ++i) { scanf("%d%d", &x, &y); if (x == 1) { if (a[x][y]) { if (a[x][y] && a[x + 1][y]) level--; if (a[x][y] && a[x + 1][y - 1]) level--; if (a[x][y] && a[x + 1][y + 1]) level--; a[x][y] ^= 1; } else { a[x][y] ^= 1; if (a[x][y] && a[x + 1][y]) level++; if (a[x][y] && a[x + 1][y - 1]) level++; if (a[x][y] && a[x + 1][y + 1]) level++; } } else if (x == 2) { if (a[x][y]) { if (a[x][y] && a[x - 1][y]) level--; if (a[x][y] && a[x - 1][y - 1]) level--; if (a[x][y] && a[x - 1][y + 1]) level--; a[x][y] ^= 1; } else { a[x][y] ^= 1; if (a[x][y] && a[x - 1][y]) level++; if (a[x][y] && a[x - 1][y - 1]) level++; if (a[x][y] && a[x - 1][y + 1]) level++; } } if (!level) puts("YES"); else puts("NO"); } } return 0; }
#include <bits/stdc++.h> using namespace std; const int Maxn = 1e5 + 5; int n, q, cnt, a[3][Maxn]; int main() { scanf("%d%d", &n, &q); while (q--) { int x, y; scanf("%d%d", &x, &y); if (a[x][y]) { if (a[3 - x][y - 1]) --cnt; if (a[3 - x][y]) --cnt; if (a[3 - x][y + 1]) --cnt; } else { if (a[3 - x][y - 1]) ++cnt; if (a[3 - x][y]) ++cnt; if (a[3 - x][y + 1]) ++cnt; } a[x][y] ^= 1; if (cnt) printf("NO\n"); else printf("YES\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; long long i, n, q, c1, c2, gr; bool m[3][100001]; int main() { cin >> n >> q; for (i = 1; i <= q; i++) { cin >> c1 >> c2; if (m[c1][c2] == true) { m[c1][c2] = false; if (c1 == 2) { if (m[1][c2 + 1] == true) gr--; if (m[1][c2 - 1] == true) gr--; if (m[1][c2] == true) gr--; } else { if (m[2][c2 + 1] == true) gr--; if (m[2][c2 - 1] == true) gr--; if (m[2][c2] == true) gr--; } } else { m[c1][c2] = true; if (c1 == 2) { if (m[1][c2 + 1] == true) gr++; if (m[1][c2 - 1] == true) gr++; if (m[1][c2] == true) gr++; } else { if (m[2][c2 + 1] == true) gr++; if (m[2][c2 - 1] == true) gr++; if (m[2][c2] == true) gr++; } } if (gr < 1) 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) no(); else yes(); } } 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; using ll = long long; ll mod = 1e9 + 7; ll a[3][100004]; int32_t main() { ll n, q, ans = 0; cin >> n >> q; while (q--) { ll l, r; cin >> l >> r; if (a[l][r]) { ll x = 1; if (l == 1) x = 2; if (a[x][r]) ans--; if (a[x][r - 1]) ans--; if (a[x][r + 1]) ans--; a[l][r] = 0; } else { ll x = 1; if (l == 1) x = 2; if (a[x][r]) ans++; if (a[x][r - 1]) ans++; if (a[x][r + 1]) ans++; a[l][r] = 1; } if (ans) 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; 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 main() { ios::sync_with_stdio(0); cin.tie(0); int n, q; cin >> n >> q; int closed = 0; vector<vector<int> > a(2, vector<int>(n, 1)); for (int i = 1; i <= q; i++) { int r; cin >> r; r--; int c; cin >> c; c--; a[r][c] = 1 - a[r][c]; int x = (!a[r][c] ? 1 : -1); if (!a[1 - r][c]) closed += x; if (c > 0 && !a[1 - r][c - 1]) closed += x; if (c + 1 < n && !a[1 - r][c + 1]) closed += x; if (!closed) cout << "Yes\n"; else cout << "No\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int t, n, a[100002], b[100002], c, q, x, y; int main() { cin >> n >> q; for (int i = 1; i <= q; ++i) { cin >> x >> y; if (x == 1) { if (a[y]) { if (b[y - 1]) --c; if (b[y]) --c; if (b[y + 1]) --c; a[y] = 1 - a[y]; } else { if (b[y + 1]) ++c; if (b[y - 1]) ++c; if (b[y]) ++c; a[y] = 1 - a[y]; } } else { if (b[y]) { if (a[y - 1]) --c; if (a[y + 1]) --c; if (a[y]) --c; b[y] = 1 - b[y]; } else { if (a[y - 1]) ++c; if (a[y + 1]) ++c; if (a[y]) ++c; b[y] = 1 - b[y]; } } if (c) puts("No"); else puts("Yes"); } }
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using pii = pair<long long, long long>; long long status[2][101010]; long long hl[101010], lh[101010], col[101010]; long long hls, lhs, cols; long long n, q; void print_status() { for (long long i = 1; i <= n; i++) { printf("%s", status[0][i] ? "X" : "O"); } printf("\n"); for (long long i = 1; i <= n; i++) { printf("%s", status[1][i] ? "X" : "O"); } printf("\n"); } int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q; while (q--) { long long r, c; cin >> r >> c; r--; if (status[r][c] == 0) { if (status[1 - r][c] == 1 && col[c] == 0) { col[c] = 1; cols++; } if (r == 1) { if (status[0][c - 1] == 1 && hl[c - 1] == 0) { hl[c - 1] = 1; hls++; } if (status[0][c + 1] == 1 && lh[c] == 0) { lh[c] = 1; lhs++; } } else { if (status[1][c + 1] == 1 && hl[c] == 0) { hl[c] = 1; hls++; } if (status[1][c - 1] == 1 && lh[c - 1] == 0) { lh[c - 1] = 1; lhs++; } } } else if (status[r][c] == 1) { if (col[c] == 1) { col[c] = 0; cols--; } if (r == 1) { if (c != 0 && hl[c - 1] == 1) { hl[c - 1] = 0; hls--; } if (c != n && lh[c] == 1) { lh[c] = 0; lhs--; } } else { if (c != n && hl[c] == 1) { hl[c] = 0; hls--; } if (c != 0 && lh[c - 1] == 1) { lh[c - 1] = 0; lhs--; } } } status[r][c] = 1 - status[r][c]; cout << ((lhs == 0 && hls == 0 && cols == 0) ? "Yes\n" : "No\n"); } }
#include <bits/stdc++.h> using namespace std; int main() { long long n, q; cin >> n >> q; vector<vector<bool> > mat(3, vector<bool>(n + 1, false)); long long front = 0, cross = 0, x, y; for (long long i = 0; i < q; ++i) { cin >> x >> y; if (mat[x][y] == false) { mat[x][y] = true; if (y == 1) { if (mat[1][y + 1] == true) ++cross; } else if (y == n) { if (mat[2][y - 1] == true) ++cross; } else { if (x == 1) { if (mat[2][y] == true) { ++front; } if (mat[2][y + 1] == true) { ++cross; } if (mat[2][y - 1] == true) { ++cross; } } else { if (mat[1][y] == true) { ++front; } if (mat[1][y + 1] == true) { ++cross; } if (mat[1][y - 1] == true) { ++cross; } } } } else { mat[x][y] = false; if (y == 1) { if (mat[1][y + 1] == true) --cross; } else if (y == n) { if (mat[2][y - 1] == true) --cross; } else { if (x == 1) { if (mat[2][y] == true) { --front; } if (mat[2][y + 1] == true) { --cross; } if (mat[2][y - 1] == true) { --cross; } } else { if (mat[1][y] == true) { --front; } if (mat[1][y + 1] == true) { --cross; } if (mat[1][y - 1] == true) { --cross; } } } } if (cross == 0 && front == 0) cout << "Yes"; else cout << "No"; cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int n, q, zakryt; bool a[3][100005]; const int dy[3] = {-1, 0, 1}; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> q; while (q--) { int r, c; cin >> r >> c; a[r][c] ^= 1; int cnt = a[r][c] ? -1 : 1; for (int i = 0; i < 3; ++i) zakryt += a[3 - r][c + dy[i]] ? cnt : 0; cout << (zakryt ? "No\n" : "Yes\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; int d; int a[100000][2]; void create(int l, int r, int n) { a[r - 1][l - 1] = 1; if (r - 2 >= 0 && a[r - 2][1 - (l - 1)]) d++; if (a[r - 1][1 - (l - 1)]) d++; if (r < n && a[r][1 - (l - 1)]) d++; } void rem(int l, int r, int n) { a[r - 1][l - 1] = 0; if (r - 2 >= 0 && a[r - 2][1 - (l - 1)]) d--; if (a[r - 1][1 - (l - 1)]) d--; if (r < n && a[r][1 - (l - 1)]) d--; } void solve() { int n, q; cin >> n >> q; for (int i = 0; i < q; i++) { int l, r; cin >> l >> r; if (a[r - 1][l - 1]) rem(l, r, n); else create(l, r, n); if (d > 0) cout << "No\n"; else cout << "Yes\n"; } } int main() { ios_base::sync_with_stdio(false); int t = 1; while (t--) solve(); }
#include <bits/stdc++.h> using namespace std; int n, q; vector<vector<int>> lava; void Input() { cin >> n >> q; lava.resize(2, vector<int>(n, 0)); } void Solve() { int blockedPair = 0; while (q--) { int x, y; cin >> x >> y; x--; y--; int delta = (lava[x][y] == 0) ? +1 : -1; lava[x][y] = 1 - lava[x][y]; for (int dy = -1; dy <= 1; dy++) { if (y + dy < 0 || y + dy >= n) continue; if (lava[1 - x][y + dy] == 1) blockedPair += delta; } cout << ((blockedPair == 0) ? "Yes\n" : "No\n"); } } int main(int argc, char* argv[]) { ios_base::sync_with_stdio(0); cin.tie(NULL); Input(); Solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { int n, q; cin >> n >> q; vector<bool> p1(n + 1, false); vector<bool> p2(n + 1, false); int cnt = 0; int x, y; for (int i = 0; i < q; i++) { cin >> x >> y; if (x == 1) { if (p1[y]) { p1[y] = false; if (p2[y]) cnt--; if (y != 1 && p2[y - 1]) cnt--; if (y != n && p2[y + 1]) cnt--; } else { p1[y] = true; if (p2[y]) cnt++; if (y != 1 && p2[y - 1]) cnt++; if (y != n && p2[y + 1]) cnt++; } } else { if (p2[y]) { p2[y] = false; if (p1[y]) cnt--; if (y != 1 && p1[y - 1]) cnt--; if (y != n && p1[y + 1]) cnt--; } else { p2[y] = true; if (p1[y]) cnt++; if (y != 1 && p1[y - 1]) cnt++; if (y != n && p1[y + 1]) cnt++; } } cout << ((!cnt) ? "Yes\n" : "No\n"); } return 0; }
#include <bits/stdc++.h> inline long long read() { long long sign = 1; long long x = 0; char ch; while (!isdigit(ch = getchar())) if (ch == '-') sign = -1; while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar(); return x * sign; } inline void ww(long long k) { if (k < 0) putchar('-'), k *= -1; char ch[20]; int num = 0; while (k) ch[++num] = k % 10, k /= 10; if (num == 0) ch[++num] = 0; while (num) putchar(ch[num--] + '0'); } using namespace std; const int N = 1e5 + 4; bool ar[2][N]; inline void wonl() { putchar('\n'); } template <typename T, typename... V> inline void wonl(T t, V... v) { ww(t); if (sizeof...(v)) putchar(' '); wonl(v...); } int main() { int n = read(), q = read(), pa = 0, a; while (q--) { a = read(); if (a == 1) { a = read(); if (ar[0][a]) { ar[0][a] = 0; if (a - 1 > 0 && ar[1][a - 1]) pa--; if (a + 1 <= n && ar[1][a + 1]) pa--; if (ar[1][a]) pa--; } else { ar[0][a] = 1; if (a - 1 > 0 && ar[1][a - 1]) pa++; if (a + 1 <= n && ar[1][a + 1]) pa++; if (ar[1][a]) pa++; } if (pa) printf("No\n"); else printf("Yes\n"); } else { a = read(); if (ar[1][a]) { ar[1][a] = 0; if (a - 1 > 0 && ar[0][a - 1]) pa--; if (a + 1 <= n && ar[0][a + 1]) pa--; if (ar[0][a]) pa--; } else { ar[1][a] = 1; if (a - 1 > 0 && ar[0][a - 1]) pa++; if (a + 1 <= n && ar[0][a + 1]) pa++; if (ar[0][a]) pa++; } if (pa) printf("No\n"); else printf("Yes\n"); } } return 0; }
#include <bits/stdc++.h> using namespace std; int f[2][100010]; int main() { int n, q, x, y, cnt = 0; scanf("%d%d", &n, &q); memset(f, 0, sizeof(f)); while (q--) { scanf("%d%d", &x, &y); x--; if (f[x][y]) { cnt -= f[x ^ 1][y - 1] + f[x ^ 1][y] + f[x ^ 1][y + 1]; f[x][y] = 0; } else { cnt += f[x ^ 1][y - 1] + f[x ^ 1][y] + f[x ^ 1][y + 1]; f[x][y] = 1; } if (cnt) puts("NO"); else puts("YES"); } }
#include <bits/stdc++.h> using namespace std; int N, Q, r, c, cnt; bool A[2][100020]; int main() { scanf("%d%d", &N, &Q); while (Q--) { scanf("%d%d", &r, &c); r--; if (A[r][c]) { cnt -= A[r ^ 1][c - 1]; cnt -= A[r ^ 1][c]; cnt -= A[r ^ 1][c + 1]; } else { cnt += A[r ^ 1][c - 1]; cnt += A[r ^ 1][c]; cnt += A[r ^ 1][c + 1]; } A[r][c] ^= 1; if (cnt > 0) printf("NO\n"); else printf("YES\n"); } return 0; }
#include <bits/stdc++.h> int vis[2][100010], n, q, num; int judge(int r, int c) { if (c == 0) return vis[r ^ 1][c] + vis[r ^ 1][c + 1]; else if (c == n - 1) return vis[r ^ 1][c - 1] + vis[r ^ 1][c]; else return vis[r ^ 1][c - 1] + vis[r ^ 1][c] + vis[r ^ 1][c + 1]; } int main() { int r, c; scanf("%d%d", &n, &q); while (q--) { scanf("%d%d", &r, &c), r--, c--; if (vis[r][c] == 0) num += judge(r, c); else num -= judge(r, c); vis[r][c] ^= 1; if (num == 0) printf("Yes\n"); else printf("No\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; const int N = 100010; int f[3][N]; int ans; void solve(int x, int y) { int res = f[x][y] ? -1 : 1; ans += res * (f[3 - x][y] + f[3 - x][y + 1] + f[3 - x][y - 1]); f[x][y] ^= 1; } int main() { int n, q; cin >> n >> q; while (q--) { int x, y; cin >> x >> y; solve(x, y); cout << (ans ? "NO" : "YES") << endl; } }
#include <bits/stdc++.h> using namespace std; void solve() { int n, q, i, a, r, c, b; map<int, int> m1, m2; cin >> n >> q; a = 0; b = 0; while (q--) { cin >> r >> c; if (r == 1) { if (m1[c] == 0) { m1[c] = 1; if (m2[c] == 1) { a++; } if (c - 1 >= 1 && m2[c - 1] == 1) { a++; } if (c + 1 <= n && m2[c + 1] == 1) { a++; } } else { m1[c] = 0; if (m2[c] == 1) { a--; } if (c - 1 >= 1 && m2[c - 1] == 1) { a--; } if (c + 1 <= n && m2[c + 1] == 1) { a--; } } } else { if (m2[c] == 0) { m2[c] = 1; if (m1[c] == 1) { a++; } if (c - 1 >= 1 && m1[c - 1] == 1) { a++; } if (c + 1 <= n && m1[c + 1] == 1) { a++; } } else { m2[c] = 0; if (m1[c] == 1) { a--; } if (c - 1 >= 1 && m1[c - 1] == 1) { a--; } if (c + 1 <= n && m1[c + 1] == 1) { a--; } } } if (a == 0) { cout << "YES" << endl; } else cout << "NO" << endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; solve(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, q, k, i, j; cin >> n >> q; bool possible = true; bool a[2][n]; for (i = 0; i < n; i++) a[0][i] = a[1][i] = false; i = 0; while (q--) { cin >> j >> k; j--; k--; if (a[j][k] == false) { a[j][k] = true; if (a[1 - j][k]) i++; if (k + 1 < n && a[1 - j][k + 1]) i++; if (k > 0 && a[1 - j][k - 1]) i++; } else { a[j][k] = false; if (a[1 - j][k]) i--; if (k + 1 < n && a[1 - j][k + 1]) i--; if (k > 0 && a[1 - j][k - 1]) i--; } if (i > 0) cout << "No\n"; else cout << "Yes\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; bool dp[3][100010]; set<int> total; void solve(int qq) { int n, q; cin >> n >> q; for (int i = 0; i < 100010; i++) { dp[1][i] = false; dp[2][i] = false; } for (int it = 0; it < q; it++) { int r, c; cin >> r >> c; if (dp[r][c] == true) { if (!(dp[3 - r][c] == true && dp[r][c + 1] == true)) { total.erase(c); } if (dp[r][c - 1] == false) { total.erase(c - 1); } dp[r][c] = false; } else { if (dp[3 - r][c] == true) { total.insert(c); } if (dp[3 - r][c - 1] == true) { total.insert(c - 1); } if (dp[3 - r][c + 1] == true) { total.insert(c); } dp[r][c] = true; } if (total.empty()) { cout << "Yes" << endl; } else { cout << "No" << endl; } } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int t; t = 1; for (int i = 1; i <= t; i++) { solve(i); } return 0; }
#include <bits/stdc++.h> using namespace std; const long long maxx = 1e5 + 5; long long a[3][maxx]; void S() { long long n, q, ans = 0; cin >> n >> q; for (long long(i) = (0); (i) < (q); (i)++) { long long x, y; cin >> x >> y; if (a[x][y] == 1) { ans -= a[x % 2 + 1][y] == 1; ans -= a[x % 2 + 1][y + 1] == 1; ans -= a[x % 2 + 1][y - 1] == 1; } else { ans += a[x % 2 + 1][y] == 1; ans += a[x % 2 + 1][y + 1] == 1; ans += a[x % 2 + 1][y - 1] == 1; } a[x][y] = (a[x][y] + 1) % 2; cout << (ans > 0 ? "NO\n" : "YES\n"); } } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; S(); }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, q; cin >> n >> q; vector<vector<bool>> v(3, vector<bool>(n + 2)); int c = 0; while (q--) { int i, j; cin >> i >> j; bool d = v[i][j]; v[i][j] = !d; if (v[i][j]) { int x; if (i == 1) x = 2; else x = 1; if (v[x][j]) c++; if (v[x][j - 1]) c++; if (v[x][j + 1]) c++; } else { int x; if (i == 1) x = 2; else x = 1; if (v[x][j]) c--; if (v[x][j - 1]) c--; if (v[x][j + 1]) c--; } if (c) cout << "NO" << endl; else cout << "YES" << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const int INF = 1034567890; const long long LL_INF = 1234567890123456789ll; const double PI = acos(-1); const long double ERR = 1E-10; int main() { int n, q; cin >> n >> q; set<pair<int, int>> cells; int bad_nei{}; for (auto i{0}; i < q; i++) { int row, col; cin >> row >> col; bool was_forbidden = cells.count({row, col}); for (auto r{row - 1}; r < row + 2; r++) { for (auto c{col - 1}; c < col + 2; c++) { if (r == row) continue; if (!(1 <= r && r <= 2 && 1 <= c && c <= n)) { continue; } if (cells.count({r, c})) { if (was_forbidden) bad_nei--; else bad_nei++; } } } if (cells.count({row, col})) cells.erase({row, col}); else cells.insert({row, col}); if (bad_nei >= 1) puts("NO"); else puts("YES"); } return 0; }
#include <bits/stdc++.h> using namespace std; int ar[2][1000001]; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); int n, q, x, y, des, yy, count = 0; cin >> n >> q; for (int i = 0; i < q; i++) { cin >> x >> y; x--; y--; ar[x][y] = 1 - ar[x][y]; des = ((ar[x][y] == 1) ? +1 : -1); for (yy = -1; yy <= 1; yy++) { if (y + yy < 0 || y + yy >= n) continue; if (ar[1 - x][y + yy] == 1) count += des; } cout << ((count == 0) ? "Yes\n" : "No\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int T = 1; while (T-- > 0) { int n, q; cin >> n >> q; bool lava[2][n]; memset(lava, false, sizeof(lava)); int blocked_pairs = 0; while (q--) { int r, c; cin >> r >> c; r--; c--; int delta = ((lava[r][c]) ? -1 : +1); lava[r][c] ^= 1; for (int i = -1; i <= 1; i++) { if (c + i < 0 || c + i >= n) continue; if (lava[r ^ 1][c + i]) { blocked_pairs += delta; } } if (blocked_pairs == 0) cout << "YES"; else cout << "NO"; cout << '\n'; } } return 0; }
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; vector<long long int> initializeDiffArray(vector<long long int>& A); void update(vector<long long int>& D, long long int l, long long int r, long long int x); void getArray(vector<long long int>& A, vector<long long int>& D); long long int min(long long int a, long long int b); long long int max(long long int a, long long int b); long long int gcd(long long int a, long long int b); void swap(long long int* a, long long int* b); long long int lcm(long long int a, long long int b); long long int modpower(long long int x, long long int y, long long int p); long long int power(long long int x, long long int y); long long int modulo(long long int value, long long int m); long long int myXOR(long long int x, long long int y); long long int diff(long long int a, long long int b); int main() { { ios ::sync_with_stdio(false); cin.tie(0); cout.tie(0); }; long long int rep = 1; cin >> rep; while (rep--) { long long int n; cin >> n; long long int a[n]; for (long long int i = 0; i <= n - 1; ++i) cin >> a[i]; sort(a, a + n); for (long long int i = n - 1; i >= 0; i--) cout << a[i] << ' '; cout << '\n'; } return 0; } long long int myXOR(long long int x, long long int y) { return (x | y) & (~x | ~y); } long long int min(long long int a, long long int b) { if (a > b) return b; return a; } long long int max(long long int a, long long int b) { if (a < b) return b; return a; } 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 diff(long long int a, long long int b) { if (a > b) return a - b; return b - a; } void swap(long long int* a, long long int* b) { long long int t = *a; *a = *b; *b = t; } long long int lcm(long long int a, long long int b) { if (a == 0) return b; if (b == 0) return a; return (a * b) / gcd(a, b); } long long int modpower(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } long long int power(long long int x, long long int y) { long long int temp; if (y == 0) return 1; temp = power(x, y / 2); if (y % 2 == 0) return temp * temp; else return x * temp * temp; } long long int modulo(long long int value, long long int m) { long long int mod = value % m; if (value < 0) { mod += m; } return mod; } vector<long long int> initializeDiffArray(vector<long long int>& A) { long long int n = A.size(); vector<long long int> D(n + 1); D[0] = A[0], D[n] = 0; for (long long int i = 1; i < n; i++) D[i] = A[i] - A[i - 1]; return D; } void update(vector<long long int>& D, long long int l, long long int r, long long int x) { D[l] += x; D[r + 1] -= x; } void getArray(vector<long long int>& A, vector<long long int>& D) { for (long long int i = 0; i < A.size(); i++) { if (i == 0) A[i] = D[i]; else A[i] = D[i] + A[i - 1]; } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long t; cin >> t; while (t) { t--; long long n; cin >> n; vector<long long> v(n); for (long long i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end(), greater<int>()); for (long long i = 0; i < n; i++) cout << v[i] << " "; cout << endl; } }
#include <bits/stdc++.h> using namespace std; long long int mod = 1000000007; long long int m = 998244353; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = n - 1; i >= 0; i--) cout << a[i] << " "; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; void solve() { long long int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n, greater<int>()); for (int i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl; } int main() { int t; cin >> t; while (t--) { solve(); } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n, i, j, flag = 1; cin >> n; vector<int> v(n, 0), f, s; for (i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end(), greater<int>()); i = 0; for (i = 0; i < n; i++) cout << v[i] << " "; cout << endl; } }
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T> using V = vector<T>; template <class T, class U> using P = pair<T, U>; using vll = V<ll>; using vvll = V<vll>; template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; } const ll MOD = 1000000007; const ll HIGHINF = (ll)1e18; const int INF = 1e9; int t; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> t; while (t-- > 0) { int n; cin >> n; V<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); reverse(a.begin(), a.end()); for (int i = 0; i < n; i++) cout << a[i] << (i == n - 1 ? '\n' : ' '); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); std::cin.sync_with_stdio(0); std::cout.sync_with_stdio(0); int t; cin >> t; while (t--) { int n, m; int a[101]; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); reverse(a, a + n); for (int i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int MAXN = 100; int n; int a[MAXN + 10]; void input() { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } } void output() { for (int i = 0; i < n; i++) { cout << a[i] << ' '; } cout << '\n'; } void solve() { sort(a, a + n, greater<int>()); } void start() { int t; cin >> t; for (int i = 0; i < t; i++) { input(); solve(); output(); } } int main() { ios::sync_with_stdio(false); cin.tie(NULL); start(); return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t, n; int i; cin >> t; for (i = 0; i < t; i++) { cin >> n; int ara[n], j, k, ara1[n], tmp; for (k = 0; k < n; k++) { cin >> ara[k]; ara1[k] = k - ara[k]; } for (j = 0; j < n - 1; j++) { for (k = j + 1; k < n; k++) { if (ara1[j] == ara1[k]) { tmp = ara[j]; ara[j] = ara[k]; ara[k] = tmp; ara1[k] = k - ara[k]; ara1[j] = j - ara[j]; j = -1; break; } } } for (k = 0; k < n; k++) { cout << ara[k] << " "; } cout << "\n"; } }
#include <bits/stdc++.h> using namespace std; int main(int argc, const char* argv[]) { long long int i, j, k, l, a, b, c, N, T, n, m; cin >> T; while (T--) { cin >> n; vector<long long int> vvj; for (i = 0; i < n; i++) { cin >> a; vvj.push_back(a); } for (i = 0; i < n; i++) { for (j = i + 1; j < (n); j++) { if ((i - vvj[i]) == (j - vvj[j])) { swap(vvj[i], vvj[j]); i = -1; break; } } } for (i = 0; i < n; i++) { cout << vvj[i] << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t, n; cin >> t; int res[t][100]; int duz[t]; for (int o = 0; o < t; o++) { cin >> n; int a[n]; duz[o] = n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); reverse(a, a + n); for (int i = 0; i < n; i++) res[o][i] = a[i]; } for (int i = 0; i < t; i++) { for (int j = 0; j < duz[i]; j++) cout << res[i][j] << ' '; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end()); for (long long i = n - 1; i >= 0; i--) { cout << a[i] << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> bool check1(int a) { return (a & (a - 1)) == 0 ? true : false; } using namespace std; const int inf = 0x3f3f3f3f; const int mod = 1e9 + 7; const int Maxn = 2e5 + 7; int a[Maxn], b[Maxn], k; void solve() { int n; cin >> n; for (int i = 1; i <= n; i++) scanf("%d", &a[i]); sort(a + 1, a + 1 + n, greater<int>()); for (int i = 1; i <= n; i++) { cout << a[i] << " "; } cout << endl; } int main() { int n; scanf("%d", &n); while (n--) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int tc, i, j, k, m; cin >> tc; int n; for (i = 0; i < tc; i++) { cin >> n; int x[n]; for (j = 0; j < n; j++) cin >> x[j]; for (j = 0; j < n; j++) sort(x, x + n); for (j = n - 1; j >= 0; j--) { cout << x[j] << " "; } cout << endl; } }
#include <bits/stdc++.h> const double PI = 3.141592653589793238460; using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int A[n]; for (int i = 0; i < n; i++) cin >> A[i]; sort(A, A + n, greater<int>()); for (int i = 0; i < n; i++) cout << A[i] << " "; cout << '\n'; } }
#include <bits/stdc++.h> using namespace std; int main() { int i, j, k, l, m, n, t; cin >> t; while (t--) { cin >> n; int a[n]; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (i = n - 1; i >= 0; i--) { cout << a[i] << " "; } cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long t; cin >> t; for (int tt = 0; tt < t; tt++) { long long n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; i++) cin >> a.at(i); sort(a.begin(), a.end()); reverse(a.begin(), a.end()); for (int i = 0; i < n; i++) { if (i != n - 1) cout << a.at(i) << ' '; else cout << a.at(i) << endl; } } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { iostream::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.rbegin(), a.rend()); for (auto it : a) cout << it << " "; cout << "\n"; } }
#include <bits/stdc++.h> using namespace std; long long a[105]; int32_t main() { long long t; cin >> t; while (t--) { long long n; cin >> n; for (long long i = 1; i <= n; i++) cin >> a[i]; sort(a + 1, a + 1 + n); for (long long i = n; i >= 1; i--) cout << a[i] << " "; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t, n; cin >> t; while (t--) { cin >> n; int a[n], b[n], i, j; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (i = n - 1, j = 0; j < n; i--, j++) { b[j] = a[i]; } for (i = 0; i < n; i++) cout << b[i] << " "; cout << endl; } }
#include <bits/stdc++.h> using namespace std; long long int A[200]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int t; cin >> t; while (t--) { long long int n; cin >> n; for (long long int i = 1; i <= n; i += 1) cin >> A[i]; sort(A + 1, A + 1 + n); reverse(A + 1, A + 1 + n); for (long long int i = 1; i <= n; i += 1) cout << A[i] << " "; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; bool comp(int x, int y) { return x > y; } int main() { int t, n; cin >> t; while (t--) { cin >> n; int a[n + 1]; for (int k = 1; k <= n; k++) cin >> a[k]; sort(a + 1, a + 1 + n, comp); for (int k = 1; k <= n; k++) { cout << a[k] << ' '; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll inf = 1e18; const int N = 2 * 1e5 + 10; ll res; ll a[N]; std::vector<ll> v; void solve() { ll n; cin >> n; for (int i = 0; i < n; ++i) { cin >> res, v.push_back(res); } sort(v.rbegin(), v.rend()); for (auto i : v) { cout << i << " "; } cout << "\n"; } int main(int argc, char const *argv[]) { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); ll t = 1; cin >> t; while (t--) { solve(); v.clear(); } }
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; void primeFactors(long long n) { while (!(n % 2)) { n /= 2; } for (long long i = 3; i <= sqrt(n); i += 2) { while (!(n % i)) { n /= i; } } if (n > 2) { ; } } long long cd(long long n) { return floor(log10(n) + 1); } unsigned long long cb(long long number) { unsigned long long l = log2(number) + 1; return l; } bool at_position(long long num, long long pos) { unsigned long long go = (1ULL << pos); bool bit = num & go; return bit; } template <typename... T> void input(T &...args) { ((cin >> args), ...); } template <typename... T> void print(T &&...args) { ((cout << args << " "), ...); } template <typename... T> void deb(T &&...args) { ((cerr << args << " "), ...); cerr << "\n"; } void forv(vector<long long> &v, long long n) { long long x; for (long long i = 0; i < n; i++) { cin >> x; v.push_back(x); } } void printv(vector<long long> v) { for (auto i : v) { cout << i << " "; } } void fora(long long a[], long long n) { for (long long i = 0; i < n; i++) cin >> a[i]; } void printa(long long a[], long long n) { for (long long i = 0; i < n; i++) cout << a[i] << " "; } void dmap(map<char, long long> mp) { for (auto i : mp) cout << i.first << " " << i.second << "\n"; } void dmmap(multimap<long long, long long> mp) { for (auto i : mp) cout << i.first << " " << i.second << "\n"; } signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; fora(a, n); sort(a, a + n); for (long long i = n - 1; i >= 0; i--) { cout << a[i] << " "; } cout << "\n"; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { long long int t; cin >> t; while (t--) { long long int n; cin >> n; long long int a[n + 1]; for (long long int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n, greater<int>()); for (long long int i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int mod = int(1e9) + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end(), greater<int>()); for (int i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; long long n, m, t, a[999], b[999]; void swap(int &a, int &b) { int tmp = a; a = b; b = tmp; } int main() { cin >> t; while (t--) { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); reverse(a, a + n); for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; const int maxx = 1e3 + 10; int t, n; int a[maxx]; int main() { cin >> t; while (t--) { cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); for (int i = n - 1; i >= 0; i--) { cout << a[i] << ' '; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { vector<int> vector; int t, size; cin >> t; for (int i = 0; i < t; i++) { cin >> size; int value = 0; for (int j = 0; j < size; j++) { cin >> value; vector.push_back(value); } sort(vector.begin(), vector.end()); reverse(vector.begin(), vector.end()); for (int j = 0; j < vector.size(); j++) { cout << vector[j] << " "; } cout << endl; vector.clear(); } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> a(n), r(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.end(), greater<int>()); for (int i = 0; i < n; i++) { cout << a[i] << " "; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; int n[t]; int res[t][100]; for (int a = 0; a < t; a++) { int p, q; cin >> n[a]; int in[n[a]]; for (int b = 0; b < n[a]; b++) { cin >> in[b]; } for (int d = 0; d < n[a]; d++) { p = in[0]; q = 0; for (int c = 0; c < n[a]; c++) { if (in[c] > p) { p = in[c]; q = c; } } res[a][d] = p; in[q] = 0; } } for (int e = 0; e < t; e++) { for (int f = 0; f < n[e]; f++) { cout << res[e][f] << " "; } cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int n; int t, a[105]; scanf("%d", &t); while (t--) { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a, a + n); for (int i = n - 1; i >= 0; i--) { printf("%d%c", a[i], i == 0 ? '\n' : ' '); } } return 0; }
#include <bits/stdc++.h> using namespace std; template <class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } template <class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } const long double EPS = 1e-10; const long long INF = 1e18; const long double PI = acos(-1.0L); void solve() { long long n; cin >> n; vector<long long> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end(), greater<long long>()); for (auto val : a) { cout << val << " "; } cout << endl; } int main() { cin.tie(0); ios::sync_with_stdio(false); long long T; cin >> T; while (T--) solve(); return 0; }
#include <bits/stdc++.h> using namespace std; const long double pi = 3.1415926535897932384626433; const long long M = 1743; long long t, n, m; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; cin >> t; while (t--) { vector<long long> v; cin >> n; for (long long i = 0; i < n; i++) { cin >> m; v.push_back(m); } sort(v.rbegin(), v.rend()); for (auto i : v) cout << i << " "; cout << "\n"; } }
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); ; long long int t; cin >> t; for (int j = 0; j < t; j++) { long long int n; cin >> n; long long int a[n]; vector<long long int> v; for (int i = 0; i < n; i++) { cin >> a[i]; v.push_back(a[i]); } sort(v.begin(), v.end()); for (int k = 0; k < n; k++) { cout << v[n - 1 - k] << " "; } cout << '\n'; } }
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long oo = 1e9 + 10; const int Max = 1e6 + 10; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } long long n, m; void solve() { cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; sort((a).begin(), (a).end()); reverse((a).begin(), (a).end()); for (int i = 0; i < n; i++) cout << a[i] << " "; cout << endl; } int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); int ___T; cin >> ___T; for (int cs = 1; cs <= ___T; cs++) { solve(); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<int> val(n); for (int i = 0; i < n; i++) { cin >> val[i]; } sort(val.begin(), val.end()); for (int i = val.size() - 1; i >= 0; i--) cout << val[i] << ' '; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int32_t main() { ios_base::sync_with_stdio(false); int64_t Q; cin >> Q; while (Q-- > 0) { int64_t n; cin >> n; vector<int64_t> v(n); for (int64_t i = 0; i < n; ++i) cin >> v[i]; sort(v.rbegin(), v.rend()); for (int64_t i = 0; i < n; ++i) { cout << v[i] << ' '; } cout << endl; } }
#include <bits/stdc++.h> using namespace std; void input(vector<int>& v, int n) { long long i, io; for (i = 0; i < n; i++) { cin >> io; v.push_back(io); } } void output(vector<int> v) { int i; for (i = 0; i < v.size(); i++) cout << v.at(i) << " "; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int T; cin >> T; while (T--) { int i, j, n; cin >> n; vector<int> v; input(v, n); sort(v.begin(), v.end(), greater<int>()); output(v); cout << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int t, m, n, i, j, l; int arr[1005]; scanf("%d", &t); for (i = 0; i < t; i++) { scanf("%d", &n); for (j = 0; j < n; j++) { scanf("%d", &arr[j]); } sort(arr, arr + j); for (l = n - 1; l >= 0; l--) { printf("%d ", arr[l]); } printf("\n"); } }
#include <bits/stdc++.h> using namespace std; clock_t time_p = clock(); void rtime() { time_p = clock() - time_p; cout << "\nTime Taken : " << fixed << (float)(time_p) / CLOCKS_PER_SEC << "s\n"; } inline long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } inline long long lcm(long long a, long long b) { return (a / gcd(a, b) * b); } inline long long ncr(long long n, long long r) { long long res = 1; if (r > n - r) r = n - r; for (long long i = 0; i < r; i++) { res *= n - i; res /= i + 1; } return res; } inline bool prime(long long n) { long long i; for (i = 2; i <= sqrt(n); i++) { if (n % i == 0) return false; } return true; } template <class T> ostream& operator<<(ostream& os, string V) { os << "[ "; for (auto v : V) os << v << " "; return os << "]"; } template <class T> ostream& operator<<(ostream& os, vector<T> V) { os << "[ "; for (auto v : V) os << v << " "; return os << "]"; } template <class T> ostream& operator<<(ostream& os, set<T> S) { os << "{ "; for (auto s : S) os << s << " "; return os << "}"; } template <class T> ostream& operator<<(ostream& os, multiset<T> S) { os << "{ "; for (auto s : S) os << s << " "; return os << "}"; } template <class T, class T1> ostream& operator<<(ostream& os, map<T, T1> S) { os << "{ "; for (auto s : S) os << "(" << s.first << "," << s.second << ") "; return os << "}"; } template <class L, class R> ostream& operator<<(ostream& os, pair<L, R> P) { return os << "(" << P.first << "," << P.second << ")"; } template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1 << " | "; __f(comma + 1, args...); } const long long mod = 1e9 + 7; inline long long add(long long x, long long y) { x += y; if (x >= mod) return x - mod; return x % mod; } inline long long sub(long long x, long long y) { x -= y; if (x < 0) return x + mod; return x; } inline long long mul(long long x, long long y) { return (x * 1ll * y) % mod; } inline long long expo(long long x, long long y) { long long ans = 1; while (y) { if (y & 1) ans = mul(ans, x); x = mul(x, x); y >>= 1; } return ans % mod; } inline long long inv(long long x) { return expo(x, mod - 2); } long long rr[] = {0, 1, 1, 1, 0, -1, -1, -1}; long long cc[] = {1, 1, 0, -1, -1, -1, 0, 1}; const long long MAXN = 2e5 + 10, MAX2N = 2e3 + 10, LG = 20, INF = 2e18; const long long N = MAXN; long long n, m, k, c, x, q, a[MAXN]; void solve() { cin >> n; for (long long i = 0; i < (long long)n; i++) cin >> a[i]; sort(a, a + n); reverse(a, a + n); for (long long i = 0; i < (long long)n; i++) cout << a[i] << " "; cout << "\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long t; t = 1; cin >> t; for (long long i = 1; i <= t; i++) { solve(); } }
#include <bits/stdc++.h> int main() { int t, i; scanf("%d", &t); for (i = 0; i < t; i++) { int n; scanf("%d", &n); int j = n, k, l, m, o, p, a[n]; for (k = 0; k < n; k++) { scanf("%d", &a[k]); } for (l = 0; l < n; l++) { for (m = l + 1; m < n; m++) { if (a[m] > a[l]) { o = a[l]; a[l] = a[m]; a[m] = o; } else continue; } } for (p = 0; p < n; p++) { printf("%d ", a[p]); } printf("\n"); } return 0; }
#include <bits/stdc++.h> using namespace std; int T; int n, m; int num[110]; int main() { scanf("%d", &T); while (T--) { scanf("%d", &n); for (int i = 1; i <= n; i++) scanf("%d", num + i); sort(num + 1, num + n + 1); for (int i = n; i >= 1; i--) printf("%d%c", num[i], i == 1 ? '\n' : ' '); } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { int m, n, t; cin >> t; while (t--) { cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = n - 1; i >= 0; i--) cout << a[i] << " "; cout << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int ar[n]; for (int i = 0; i < n; i++) cin >> ar[i]; sort(ar, ar + n); for (int i = n - 1; i >= 0; i--) cout << ar[i] << " "; cout << endl; } return 0; }
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long long t; cin >> t; while (t--) { long long n, k = 0, m = 0, h = 0, d = 0, j = 0, g = 1000000007, c = 0, ans = 0; cin >> n; vector<int> a(n); for (auto &x : a) cin >> x; sort(a.begin(), a.end(), greater<int>()); for (auto y : a) cout << y << " "; cout << endl; } }
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n, greater<int>()); for (int j = 0; j < n; j++) cout << a[j] << " "; cout << "\n"; } }
#include <bits/stdc++.h> using namespace std; template <class T> T gcd(T a, T b) { while (a && b) if (a > b) a %= b; else b %= a; return a + b; } template <class T> void sortf(vector<T> &v) { stable_sort(v.begin(), v.end()); } template <class T> void sortb(vector<T> &v) { stable_sort(v.rbegin(), v.rend()); } template <class T> T max3(T a, T b, T c) { return max(a, max(b, c)); } template <class T> T min3(T a, T b, T c) { return min(a, min(b, c)); } template <typename T> istream &operator>>(istream &in, vector<T> &v) { for (T &t : v) in >> t; return in; } ostream &operator<<(ostream &out, const vector<char> &v) { for (const char &t : v) out << t; out << endl; return out; } template <typename T> ostream &operator<<(ostream &out, const vector<T> &v) { for (const T &t : v) out << t << ' '; return out; } static void init_iostream_speed() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); } template <typename T> T lcm(T a, T b) { return a * b / gcd(a, b); } template <class T> void swap(T *a, T *b) { T c = *a; *a = *b; *b = c; } template <typename T> class vector2 : public vector<T> { public: long long min_ind() { return min_element(this->begin(), this->end()) - this->begin(); } long long max_ind() { return max_element(this->begin(), this->end()) - this->begin(); } T min() { return *min_element(this->begin(), this->end()); } T max() { return *max_element(this->begin(), this->end()); } void sortf() { ::sortf(*this); } void sortb() { ::sortb(*this); } vector2() : vector<T>() {} vector2(vector<T> __v) : vector<T>(__v) {} vector2(initializer_list<T> __i_l) : vector<T>(__i_l) {} vector2(size_t __n, size_t __val = 0) : vector<T>(__n, __val) {} }; template <class T> T sum(const vector<T> &vc) { T ans = 0; for (const T &v : vc) ans += v; return ans; } long long nextInt() { long long t; cin >> t; return t; } long long nextLong() { long long t; cin >> t; return t; } constexpr long long MOD = 1000000007; bool operator<<(const string &a, const string &b) { if (a == b) return true; if (a.size() != b.size()) return a.size() < b.size(); return a < b; } long long intlen(long long x) { long long res = 1; while (x /= 10) res++; return res; } string operator*(const string &s, long long x) { string a; while (x--) a += s; return a; } long long factorial(long long x) { long long a = 1; for (long long i = 1; i <= x; i++) a *= i; return a; } template <class T> T reverse(T o) { reverse(o.begin(), o.end()); return o; } template <class T> struct reader : public T { template <class... Con> reader(Con &&...par) : T(par...) { cin >> *this; } }; template <> class reader<long long> { long long x; public: reader() { cin >> x; } operator long long() { return x; } }; class TaskAnswer {}; void answer() { cout << '\n'; throw TaskAnswer(); } template <class C, class... Ts> void answer(C &&cur, Ts &&...args) { cout << cur; answer(args...); } class Answerer { private: ostream &out; void operator()() { out << '\n'; throw TaskAnswer(); } public: Answerer(ostream &os) : out(os) {} template <class C, class... Ts> void operator()(C &&cur, Ts &&...args) { out << cur; this->operator()(args...); } }; vector<long long> pre_func(const string &s) { long long n = s.size(); vector<long long> p(n); for (long long i = 1; i < n; i++) { long long j = p[i - 1]; while (j > 0 && s[j] != s[i]) j = p[j - 1]; if (s[i] == s[j]) j++; p[i] = j; } return p; } long long knut(const string &s, const string &t) { auto p = pre_func(s + '$' + t); long long n = s.size(), m = t.size(); for (long long i = n + 1; i <= n + m; i++) if (p[i] == n) return i - n - n; return -1; } class fastio { private: FILE *out = stdout; FILE *in = stdin; FILE *err = stderr; template <class T> void write(const T &val) { this->operator<<(val); } template <class T> void read(T &val) { this->operator>>(val); } template <class T> void error(const T &val) { this->operator<=(val); } public: fastio() {} ~fastio() {} fastio &operator>>(char *val) { scanf("%s", val); return *this; } fastio &operator<<(const char *val) { printf("%s", val); return *this; } fastio &operator<=(const char *val) { fprintf(this->err, "%s", val); return *this; } fastio &operator>>(long long &val) { scanf("%lld", &val); return *this; } fastio &operator<<(long long val) { printf("%lld", val); return *this; } fastio &operator>>(long &val) { scanf("%ld", &val); return *this; } fastio &operator<<(long val) { printf("%ld", val); return *this; } fastio &operator>>(short &val) { scanf("%hd", &val); return *this; } fastio &operator<<(short val) { printf("%hd", val); return *this; } fastio &operator>>(char &val) { scanf("%c", &val); return *this; } fastio &operator<<(char val) { printf("%c", val); return *this; } template <class T, class... AT> void write(const T &val, const AT &...args) { this->operator<<(val); this->write(args...); } template <class T, class... AT> void read(T &val, AT &...args) { this->operator>>(val); this->read(args...); } template <class T, class... AT> void error(const T &val, const AT &...args) { this->operator<=(val); this->error(args...); } }; template <class T> fastio &operator<<(fastio &out, const vector<T> &a) { for (const T &x : a) out << x << ' '; return out; } template <class T> fastio &operator>>(fastio &in, vector<T> &a) { for (long long &x : a) in >> x; return in; } fastio console; class yesno { private: string yes, no; public: yesno(string y, string n) : yes(y), no(n) {} string operator()(bool ok) const { return ok ? this->yes : this->no; } }; Answerer fanswer(cout); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); inline void solve(); signed main() { init_iostream_speed(); long long t; cin >> t; while (t--) try { solve(); } catch (TaskAnswer) { } catch (...) { cout << "0\n"; } cout.flush(); return 0; } inline void solve() { long long n = nextInt(); vector<long long> a(n); cin >> a; sortb(a); cout << a << '\n'; }
#include <bits/stdc++.h> using namespace std; int arr[107]; int main() { int t; cin >> t; int n; while (t--) { cin >> n; for (int i = 0; i < n; i++) { cin >> arr[i]; } sort(arr, arr + n); for (int i = n - 1; i >= 0; i--) { cout << arr[i] << " "; } } }