func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; string vow = aeiou ; long long month[] = {-1, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; const long long dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2}; const long long dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1}; const long long dx4[] = {-1, 0, 1, 0}; const lon... |
#include <bits/stdc++.h> using namespace std; const int mod = (int)1e9 + 7; const int N = (int)1e6 + 6; int f[30][N]; int pref[30][N]; int lp[N]; void precalc() { pref[0][0] = f[0][0] = 1; for (int i = 1; i < 30; i++) { f[i][0] = 2; pref[i][0] = f[i][0] + pref[i - 1][0]; pref[i][... |
#include <bits/stdc++.h> using namespace std; int gcd(int a, int b) { return a % b == 0 ? b : gcd(b, a % b); } const int MAXN = 3e5 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e7 + 9; int a[MAXN]; int main() { int n; scanf( %d , &n); for (int i = (1); i < (n + 1); ++i) { scanf( %d... |
#include <bits/stdc++.h> using namespace std; int main() { long long int n, sum = 1; cin >> n; sum += 6 * ((n * (n + 1)) / 2); cout << sum << endl; return 0; } |
#include <bits/stdc++.h> using namespace std; const int N = 500005; const int M = 998244353; int n, a[N], i, s; long long f[N], c[N], x, y, z, ans[N], tp; long long qpow(long long a, long long b) { long long s = a, ans = 1; while (b) { if (b & 1) ans = ans * s % M; s = s * s % M; b... |
#include <bits/stdc++.h> using namespace std; long long w[2], b[2], q[2], mod = 998244353, fac[100001]; long long modpow(long long b, long long p) { long long ret = 1; while (p > 0) { if (p & 1) ret = ret * b % mod; b = b * b % mod; p >>= 1; } return ret; } long long choose(l... |
#include <bits/stdc++.h> using std::abs; using std::bitset; using std::cerr; using std::cin; using std::copy; using std::cout; using std::endl; using std::fill; using std::fixed; using std::greater; using std::lower_bound; using std::map; using std::max; using std::min; using std::next_per... |
#include <bits/stdc++.h> using namespace std; bool vis[305][305]; string s[305]; int len[305][305]; int d[305]; int hs[305][305]; int n; const int mod = 9e8 + 7; int qpow(int x, int y) { long long ret = 1; long long now = x; while (y) { if (y & 1) ret = ret * now % mod; now = n... |
#include <bits/stdc++.h> using namespace std; vector<int> v[100005]; int p[100005]; int h[100005]; int happy[100005]; int sad[100005]; bool vis[100005]; bool ok; void init(int n) { for (int i = 1; i < n + 1; i++) { v[i].clear(); vis[i] = false; } ok = true; } void dfs(int n... |
#include <bits/stdc++.h> using namespace std; long long j, k, a, b, s, ss, l, m, n, t, d; long long e, i, c[221]; vector<long long> p[111], q[111], r, v; char w; map<long long, long long> y, z; long long too(long long i, long long j) { long long l = 0, d = 0; for (k = 0; k < q[i].size(); k++) { ... |
#include <bits/stdc++.h> using namespace std; const int N = int(1e6) + 50; char S[N], T[N]; int slen, tlen, lef[N], rig[N], cnt[255][255]; inline int getID(char c) { if (c == R ) return 0; if (c == G ) return 1; if (c == B ) return 2; throw; } int main() { scanf( %s , S + 1); sl... |
#include <bits/stdc++.h> using namespace std; int n, m, k; long long ans; int main() { cin >> n >> m >> k; if (k > n + m - 2) { cout << -1 << endl; return 0; } if (n >= m) swap(n, m); if (k <= m - 1) { ans = (long long)(m / (k + 1)) * n; } else { ans = (long lon... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 110; int n, m, k; int h[MAXN]; void load() { scanf( %d%d%d , &n, &m, &k); for (int i = 0; i < n; i++) scanf( %d , h + i); } bool solve() { long long sum = m; int ind = 0; while (ind < n - 1) { if (h[ind] >= h[ind + 1]... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 3e5 + 10; int n, k; int a[MAXN], f[MAXN]; int bsL(int l, int r, int val) { int pos = -1; while (l <= r) { int mid = (l + r) >> 1; if (a[mid] >= val) { pos = mid; r = mid - 1; } else l = mid + 1; ... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 10; long long h[N], e[2 * N], ne[2 * N], idx; void add(long long a, long long b) { e[idx] = b, ne[idx] = h[a], h[a] = idx++; } struct node { long long sum, add; }; node tr[N << 2]; long long arr[N]; long long f[N][20]; long ... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const double EPS = 1e-9; const int INF = 1 << 29; int const NN = 5e3 + 3; int const MX = 1e9 + 9; int a[505][505]; int mx[505][505]; int main() { int n, m, K, q; cin >> n >> m >> K >> q; for (int i = 1; i <= n; ++i) { ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; void solve() { int n, k; cin >> n >> k; if(2 * k + 1 > n) { cout << -1 n ; return; } vector<int> v(n); int p = n; for(int i = 1; i < 1 + 2 * k; i += 2) v[i] = p--; ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 100005; char S[maxn][10]; int ju(char a[], char b[]) { int n = strlen(a), m = strlen(b); int x = 0, y = 0; for (int i = 0; i < n; i++) x = x * 10 + a[i] - 0 ; for (int j = 0; j < m; j++) y = y * 10 + (b[j] == ? ? 9 : b[j] - 0 ); ... |
#include <bits/stdc++.h> using namespace std; struct Friend { string name; int x, y, z; } f[123]; bool Isde(char *a) { if (a[0] <= a[1]) return false; if (a[1] <= a[3]) return false; if (a[3] <= a[4]) return false; if (a[4] <= a[6]) return false; if (a[6] <= a[7]) return false; r... |
#include <bits/stdc++.h> using namespace std; const int L = 0, R = 10000; int n, vote, tot; vector<int> p[110000]; pair<int, int> x[110000]; long long sum[110000]; long long he[4 * 110000]; int num[4 * 110000]; long long ask(int root, int l, int r, int k) { if (k <= 0) return 0; else if ... |
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; long long inv(long long a) { long long u = 0, v = 1, b = mod; while (a) { long long t = b / a; b -= t * a, u -= t * v; swap(a, b); swap(u, v); } u %= mod; if (u < 0) u += mod; return u; } s... |
#include <bits/stdc++.h> using namespace std; int main() { long long int i, a, p, b, p1, p2; cin >> a; b = a; p = 0; p1 = p2 = 1; for (i = 2; i <= sqrt(b); i++) { if (b % i == 0) { b = b / i; p++; if (p == 1) p1 = i; if (p == 2) p2 = i; i--; ... |
#include <bits/stdc++.h> using namespace std; template <class P, class Q> ostream& operator<<(ostream& stream, pair<P, Q> v) { stream << ( << v.first << , << v.second << ) ; return stream; } template <class T> ostream& operator<<(ostream& stream, const vector<T> v) { stream << [ ; for... |
#include <bits/stdc++.h> using namespace std; template <typename T> T inverse(T a, T m) { T u = 0, v = 1; while (a != 0) { T t = m / a; m -= t * a; swap(a, m); u -= t * v; swap(u, v); } assert(m == 1); return u; } template <typename T> class Modular { pub... |
#include <bits/stdc++.h> using namespace std; long long f[60][110][2]; long long bin[60], num[60], s, tt; inline long long rd() { long long x = 0; char ch = getchar(); for (; ch < 0 || ch > 9 ; ch = getchar()) ; for (; ch >= 0 && ch <= 9 ; ch = getchar()) x = x * 10 + ch - 0 ; r... |
#include <bits/stdc++.h> using namespace std; int shortestPaths[100][100]; int graph[100][100]; void bfs(int start, int n) { queue<int> q; q.push(start); int visited[n]; for (int i = 0; i < n; i++) { visited[i] = 0; } visited[start] = 1; int dist = 1; while (true) { i... |
#include <bits/stdc++.h> using namespace std; const int maxn = 111111; long long tree[maxn * 4]; void Insert(int o, int l, int r, int k, int v) { if (l == r) { tree[o] = v; return; } int mid = (l + r) >> 1; if (k <= mid) Insert(o * 2, l, mid, k, v); else Insert(o * 2 ... |
#include <bits/stdc++.h> using namespace std; int a[200001][22]; int p[200001]; int d[200001]; int lca(int u, int v) { if (d[u] < d[v]) swap(u, v); int k = d[u] - d[v]; while (k > 0) { int t = log2(k); k -= (1 << t); u = a[u][t]; } if (u == v) return v; for (int i = 2... |
#include <bits/stdc++.h> using namespace std; const int N = 6e5 + 7; int a, b, n, ans; int main() { ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> a >> b, n = a + b; for (int l = 1, r, s; l <= n; l = r + 1) { s = n / l, r = n / s; int al = (a + s) / (s + 1), ar = a / s,... |
#include <bits/stdc++.h> using namespace std; long long n, a, b, c, d, s, len; vector<long long> z, t, v[2]; map<long long, int> ma; int main() { ios_base::sync_with_stdio(false); cin >> n >> a >> b >> c >> d >> s >> len; t.assign(n + 1, -1); v[0].assign(n + 1, s); v[1].assign(n + 1, s); ... |
#include <bits/stdc++.h> using namespace std; int main() { int A[100], L[100], n, m; cin >> n >> m; for (int i = 0; i < n; ++i) cin >> A[i], A[i]--; for (int i = 0; i < m; ++i) cin >> L[i]; for (int i = 0; i < n; ++i) { for (int j = i + 1; j <= n; ++j) { vector<int> cnt(m + 1, 0); ... |
#include <bits/stdc++.h> using namespace std; int n, k, b[1000010]; int main() { scanf( %d%d , &n, &k); int i; if (k * 3 > n || k == 1) puts( -1 ); else { for (i = 1; i <= (int)(k); ++i) b[i] = b[i + 2 * k] = i, b[i + k] = i - 1; b[k + 1] = k; for (i = 3 * k + 1; i <= n; ++... |
#include <bits/stdc++.h> using namespace std; long long a[9][5], b[8]; long long dis(int i, int j) { long long x = a[i][0] - a[j][0], y = a[i][1] - a[j][1], z = a[i][2] - a[j][2]; return x * x + y * y + z * z; } bool check() { for (int i = 0; i < 8; i++) { for (int j = 0; j < 8; j++) { ... |
#include <bits/stdc++.h> using namespace std; int constexpr nax = 3e5 + 5; using ll = int64_t; const int INF = 1e9; template <typename T> struct fenwick { T bit[nax]; fenwick() { memset(bit, 0, sizeof(bit)); } void update(int x, T val) { for (; x < nax; x += x & -x) bit[x] += val; } ... |
#include <bits/stdc++.h> using namespace std; const int inf = 1e9 + 239; int n, m, k; vector<set<int>> row; vector<set<int>> column; vector<set<int>> row_free; vector<set<int>> column_free; int get_row_left(int i, int to, int from) { auto it = row[i].lower_bound(from); if (it == row[i].begin()) ... |
#include <bits/stdc++.h> using namespace std; string s, t; int dp[5005][5005]; int get(int i, int j) { if (dp[i][j] != -1) return dp[i][j]; if (i >= s.size() or j >= t.size()) return 0; int ret = get(i, j + 1); if (s[i] == t[j]) ret = (ret + 1 + get(i + 1, j + 1)) % 1000000007; return dp[i][... |
#include <bits/stdc++.h> using namespace std; long long t, n, k; long long f(long long x) { if (x == 0) return k * (k + 1) / 2; long long t = x % k, val = f(x / k), ofs = 0; if (val < k * t + 2) { ofs = k; } else if ((t + 1) * k < val) { ofs = 0; } else { ofs = (t + 1) * k - ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 305; long long dp[maxn][maxn][6]; int n, x[maxn], y[maxn]; vector<pair<double, pair<int, int>>> seg; int main() { ios_base::sync_with_stdio(0); cin >> n; for (int i = 0; i < n; i++) cin >> x[i] >> y[i]; for (int i = 0; i < n; i++... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; if ((n & (n - 1)) == 0) { cout << 0 << n ; } else { int k = 0; while ((1 << k + 1) <= n) { k++; } n ^= 1 << k; int ans = 0; ... |
#include <bits/stdc++.h> using namespace std; bool isprime(int n) { if (n == 2) return 1; for (int i = 2; i < n; i++) { if (n % i == 0) return 0; } return 1; } int main() { int n, m; cin >> n >> m; int flag = 1; if (isprime(n) && isprime(m)) { for (int i = n + 1; i < ... |
#include <bits/stdc++.h> const int N = 200000 + 10; int a[N], n, K; int main() { scanf( %d%d , &n, &K); for (int i = 0; i < n; ++i) scanf( %d , &a[i]); long long pre = 0; int tot = n - 1, id = 0; for (int i = 0; i < n; ++i) { long long d = pre - (long long)a[i] * (tot - id) * id; i... |
#include <bits/stdc++.h> using namespace std; int a[105][105], t, m, n, ret, cnt, mn; int main(void) { cin >> t; for (int i = 0; i < t; i++) { ret = 0, cnt = 0, mn = 101; cin >> n >> m; for (int j = 0; j < n; j++) { for (int k = 0; k < m; k++) { cin >> a[j][k]; ... |
#include <bits/stdc++.h> using namespace std; const int MAX = 510; int n, m; double xa, ya, x2, y2; double v, vx1, vx2, vy1, vy2, t; int check(double k) { double x, y; x = xa + vx1 * min(k, t) + vx2 * max(0.0, k - t); y = ya + vy1 * min(k, t) + vy2 * max(0.0, k - t); double dist = sqrt((x - ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, x, sum = 0, q; vector<int> v; vector<int>::iterator it; scanf( %d , &n); while (n--) { scanf( %d , &x); sum += x; v.push_back(sum); } int sz = v.size(); scanf( %d , &q); while (q--) { scanf(... |
#include <bits/stdc++.h> using namespace std; int a[3005]; int main() { int n; int cnt = 0; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &a[i]); } for (int i = 0; i < n; i++) { for (int j = i + 1; j < n; j++) { if (a[i] > a[j]) cnt++; } } if ... |
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; long long r = n % 3; if (r != 2) cout << 1ll << << 1ll << << n - 2 << endl; else cout << 1ll << << 2ll << << n - 3 << endl; } |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast,unroll-loops ) #pragma GCC target( avx,avx2,fma ) using namespace std; template <typename T> using vc = vector<T>; template <typename T> using uset = unordered_set<T>; template <typename A, typename B> using umap = unordered_map<A, B>; template <t... |
#include <bits/stdc++.h> using namespace std; #define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0) #define fileio freopen( in.in , r , stdin),freopen( out.out , w , stdout); #define ll long long #define int long long #define FF first #define SS second #define mp make_pair #defi... |
#include <bits/stdc++.h> using namespace std; namespace INIT { char buf[1 << 15], *fs, *ft; inline char getc() { return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft)) ? 0 : *fs++; } inline int read() { int x = 0, f = 1; char ch... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100010; const int MAXM = 20010; const int MAXNODE = 16 * MAXN; const int LOGMAXN = 50; const int INF = 0x3f3f3f3f; const double eps = 1e-9; int N, M; int b[MAXM], z[MAXM], x[3 * (MAXN + MAXM)]; struct Tree { int x, h; double l, r... |
#include <bits/stdc++.h> const int N = 502; void sw(float* x) { float tmp = *x; *x = *(x + 2); *(x + 2) = *(x + 1); *(x + 1) = tmp; } int main() { int _t; scanf( %d , &_t); while (_t--) { static float arr[N]; static int anss[N * N]; static int tm[N]; memset(tm... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m; cin >> n >> m; string test; cin >> test; for (int i = 0; i < m; i++) { int l, r; char c1, c2; cin >> l >> r >> c1 >> c2; l -= 1; r -= 1; for (; l <= r; l++) { if (test[l] == c1) { ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; const long long mod = 1e9 + 7; char s[maxn]; int num[55]; long long dp[maxn]; long long tmp[maxn]; long long quesnum[55][55]; long long ques[55][55]; long long inv[maxn], fac[maxn], invf[maxn]; void init(int hf) { inv[1]... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 500000 + 10; int a[MAXN]; int n, m, ans, tp, tot; int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d , a + i); ans = n; sort(a + 1, a + 1 + n); for (int i = n / 2; i >= 1; --i) if (a[ans] >= a[i] * 2) --... |
#include <bits/stdc++.h> using namespace std; char a[500001 + 10], b[500001 + 10], s[(500001 << 1) + 10]; int n, m; struct BIT { long long c[500001 << 1]; long long query(int x) { if (x <= 0) return 0; long long ans = 0; for (int i = x; i; i -= (i & -i)) ans += c[i]; return ans; ... |
#include <bits/stdc++.h> using namespace std; long long int dec(string s, int n) { long long int r = 0, p = 0, l = s.size() - 1, tmp; while (l >= 0) { if (isalpha(s[l])) tmp = s[l] - 55; else tmp = s[l] - 48; int prod = 1; for (int k = 0; k < p; k++) prod *= n; ... |
#include <bits/stdc++.h> using namespace std; const int INF = (int)2e9; const long long INFL = (long long)9e18; const int MAXINT = ((~0) ^ (1 << 31)); const long long MAXLL = ((~0) ^ ((long long)1 << 63)); template <class T> inline T pow2(T a) { return a * a; } template <class T> inline bool min... |
#include <bits/stdc++.h> using namespace std; long long n, ti[2005], co[2005], dp[2005][2005], i, j; int main() { cin >> n; for (i = 1; i <= n; i++) { cin >> ti[i] >> co[i]; ti[i]++; } for (i = 0; i <= n; i++) { for (j = 1; j <= n; j++) dp[i][j] = 1e16; } for (i = 1; i <=... |
#include <bits/stdc++.h> using namespace std; struct pen { int color; int diameter; }; int n, m, u, v; pen marker[100000], cap[100000]; struct match { vector<pen> marker; vector<pen> cap; }; match singleMatch[1000 + 1]; match doubleMatch[1000 + 1][1000 + 1]; int main(int argc, char *... |
#include <bits/stdc++.h> using namespace std; const int inf = 109; const int mod = 1000000007; long long cnt[inf]; long long dp[inf]; long long temp[inf][inf]; long long sol[inf][inf]; long long bs[inf][inf]; int main() { int n, x, a; scanf( %d%d , &n, &x); for (int i = 0; i < n; ++i) { ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 4e5 + 10; const int M = 22; class SegmentTree { public: int ql, qr, qx; int xorv[N]; int sumv[N]; void init() { memset((xorv), (0), sizeof(xorv)); memset((sumv), (0), sizeof(sumv)); } ... |
#include <bits/stdc++.h> using namespace std; struct data { int s, m, r, t; int operator<(const data &b) const { return t < b.t; } void get() { scanf( %d , &s); scanf( %d , &m); scanf( %d , &r); t = r ? (m / r + (m % r > 0)) : 2e9; } int calc(int o) { return min(1ll * m, ... |
#include <bits/stdc++.h> using namespace std; struct Edge { int v; Edge *link; } edge[400010 * 2], *adj[200010], *tree[200010 * 2]; int totE, con, root, currT, top, top1; int totCut, totBi; int dep[200010], deps[200010], num[200010], dfn[200010], lowlink[200010], cut[200010], bi[200010], color... |
#include <bits/stdc++.h> template <typename T> inline void read(T &x) { x = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) x = x * 10 + (c ^ 48), c = getchar(); } using namespace std; int t; int pri[4001000], pcnt; bool depri[35001000]; inline void init() { ... |
#include <bits/stdc++.h> using namespace std; long long MOD = 1e9 + 7; std::vector<long long> factorial; void precompute_factorial(int ma) { factorial.push_back(1); for (int i = 1; i <= ma; i++) factorial.push_back((factorial.back() * i) % MOD); } long long power(long long base, int e) { l... |
#include <bits/stdc++.h> using namespace std; const int N = 105; const int M = 505; const int MOD = int(1e9) + 7; const int INF = 0x3f3f3f3f; const double EPS = 1e-9; const double PI = acos(-1.0); const int dx[] = {-1, 1, 0, 0}; const int dy[] = {0, 0, -1, 1}; template <class T> inline T Min(T a, ... |
#include <bits/stdc++.h> using namespace std; int n, q; int A[600006]; int gcd(int a, int b) { return !b ? a : gcd(b, a % b); } map<pair<int, int>, int> M; int L[600006], R[600006], lst[600006], cn; struct que { int l, r, idx; } Q[600006]; vector<int> bc[600006]; int T[600006]; void ad(int x, ... |
#include <bits/stdc++.h> using namespace std; const long long remi = 1000000007; const long long remi2 = 998244353; const long long inf = 1e18 + 1e17 + 1e16 + 1e15 + 1e14; long long Pow(long long x, long long y, long long m) { if (y == 0) return 1; long long p = Pow(x, y / 2, m) % m; p = (p * p) %... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false), cin.tie(0); int t; cin >> t; while (t--) { map<int, int>L, R; int bal = 0; string s; cin >> s; for (char &c : s) { if (c == 1 ) { R[bal]++; bal++; } else { L... |
#include <bits/stdc++.h> using namespace std; int tree[100010 << 2]; bool flag; struct node { int row, col, pos; friend bool operator<(node a, node b) { if (a.row == b.row) return a.col < b.col; return a.row < b.row; } }; node p[100010]; inline void pushUp(int rt) { tree[rt] = min(... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; int n, t, sz[200010], cen; vector<int> g[200010], v; bool mark[200010]; int dfs(int pos, int par) { sz[pos] = (int)mark[pos]; bool ok = true; for (int i = 0; i < g[pos].size(); i++) if (g[pos][i] != par) { ... |
#include <bits/stdc++.h> using namespace std; template <class T> inline int countbit(T n) { return (n == 0) ? 0 : (1 + countbit(n & (n - 1))); } template <class T> inline T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } const double EPS = 1e-9; const double PI = acos(-1.0); int n, k, h; i... |
#include <bits/stdc++.h> using namespace std; int n, m; map<int, int> mym; void kaisa() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> n >> m; queue<int> q; for (int i = 1; i <= n; i++) { int x; cin >> x; mym[x] = 0; q.push(x); } ... |
#include <bits/stdc++.h> using namespace std; long long q, x, y; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> q; while (q--) { cin >> x >> y; if (x - y > 1) cout << YES << n ; else cout << NO << n ; } return 0;... |
#include <bits/stdc++.h> using namespace std; int main() { int t, a, b, x; cin >> t; while (t--) { cin >> a >> b; if (a < b) { x = b - a; x % 2 == 0 ? cout << 2 : cout << 1; } else if (a > b) { x = a - b; x % 2 == 0 ? cout << 1 : cout << 2; } else ... |
#include <bits/stdc++.h> using namespace std; int gcd_(int a, int b) { if (b == 0) return a; else return gcd_(b, a % b); } int main() { int n, i, x; vector<int> v; cin >> n; for (i = 0; i < n; i++) { cin >> x; v.push_back(x); } int max1 = v[0]; x = v[0... |
#include <bits/stdc++.h> std::vector<int> ReadVector(size_t size) { std::vector<int> vector(size); for (auto& element : vector) { std::cin >> element; } return vector; } bool is_pal(const std::string& a) { for (size_t i = 0; i < a.size() / 2; ++i) { if (a[i] != a[a.size() - i - 1])... |
#include <bits/stdc++.h> using namespace std; long long INF = 1e9; const int maxn = 1e6 + 5; int a[maxn]; int tpr = 0; vector<int> adj[maxn]; void dfs(int root) { if (adj[root].size() > 0) { if (adj[root][0] == (root + 1)) { dfs(root + 1); tpr++; } else return; ... |
#include <bits/stdc++.h> #pragma GCC optimize( O3 ) #pragma GCC target( sse4 ) using namespace std; using ii = pair<int, int>; using ll = long long; const int N = 3000 + 5; const int mod = 1e9 + 7; string source[N], target[N]; int n; ii ranges[N]; vector<int> FAIL(string pat) { int m = pat.siz... |
#include <bits/stdc++.h> using namespace std; template <typename T> inline bool inrange(T a, T l, T r) { if (l > r) swap(l, r); return (a >= l and a <= r); } template <typename T, typename U> inline bool exist(T val, U &any) { return (any.find(val) != any.end()); } template <typename T> in... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<vector<int>> v; for (int i = 0; i < (n); ++i) { int l; cin >> l; vector<int> temp; for (int j = 0; j < (l); ++j) { int ele; cin >> ele; temp.push_back(ele); } ... |
#include <bits/stdc++.h> using namespace std; const int MAX = 1e6 + 6; int main() { int n; cin >> n; string str = ; while (n) { str += ((n % 2) + 0 ); n /= 2; } reverse(str.begin(), str.end()); while (str.size() < 6) str = 0 + str; string ss = ; ss += str[0];... |
#include <bits/stdc++.h> using namespace std; int getint() { unsigned int c; int x = 0; while (((c = getchar()) - 0 ) >= 10) { if (c == - ) return -getint(); if (!~c) exit(0); } do { x = (x << 3) + (x << 1) + (c - 0 ); } while (((c = getchar()) - 0 ) < 10); return x... |
#include <bits/stdc++.h> using namespace std; const int MXX = 3e5 + 5; int n, m; int a[MXX], ans[MXX]; bool ok(int x) { int mx = m - 1; for (int i = n - 1; i >= 0; i--) { if (a[i] <= mx) { if (a[i] + x >= mx) { ans[i] = mx; } else { ans[i] = a[i] + x; ... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b); void print(long long arr[], long long n); void printv(vector<long long> arr); signed main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long k; cin >> k; vect... |
#include <bits/stdc++.h> using namespace std; int par[300005]; int vis[300005]; unordered_map<int, int> edge[300005]; int d[300005]; vector<int> ans; int find(int u) { return par[u] == u ? u : par[u] = find(par[u]); } void join(int u, int v) { u = find(u); v = find(v); if (u > v) swap(u, v);... |
#include <bits/stdc++.h> using namespace std; const long long MAX = 1e6 + 100; const long long mod = 1e9 + 7; const long long inf = 1e18 + 12; vector<long long> arr(MAX); map<long long, long long> mm; int main() { ios_base::sync_with_stdio(false); cout.tie(NULL); cout.tie(NULL); ; long... |
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int N = 200005; const double PI = 4 * atan(1); const long long MAX = 9223372036854775807; int dx[] = {1, -1, 0, 0, 1, -1, 1, -1}; int dy[] = {0, 0, 1, -1, 1, 1, -1, -1}; long long gcd(long long a, long long b) { return (b == ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 7; int n, lim, a[N], mn[N], mx[N], suf[N]; long long ans; int main() { scanf( %d%d , &n, &lim); for (int i = 1; i <= lim; i++) mn[i] = n + 1; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); mn[a[i]] = min(mn[a[i]], i)... |
#include <bits/stdc++.h> #pragma warning(disable : 4996) using namespace std; int n, m; int a[300000]; int b[300000]; vector<int> edge[300000]; int ngood; int child[300000]; int good[300000]; int d[300000]; int ans; void back(int now, int parent) { child[now] = 1; good[now] = b[now]; ... |
#include <bits/stdc++.h> using namespace std; const int N = 5e4 + 10, max_node = N * 200; int n, m, q, C, c[N], a[N], size[N], heavy[N], dfn[N], dfn_t, top[N], father[N], tt, lo[max_node], ro[max_node], addv[max_node]; long long sum[max_node], sum2[max_node]; vector<int> graph[N], nodes[N]; void dfs1(... |
#include <bits/stdc++.h> const long long int mod = 1000000007; const long long int AM = 2e6 + 5; using namespace std; long long int powm(long long int a, long long int b, long long int n) { long long int x = 1, y = a; while (b > 0) { if (b % 2 == 1) { x = (x * y) % n; } y = (y ... |
#include <bits/stdc++.h> using namespace std; int f[305][305], rf[305][305], g[305][305], rg[305][305]; int a[305][305]; int n, m, s, t1, t2, t3; int ans1, ans2, ans3, ans4, Min = 1999999999; set<pair<int, int> > S; int C(int first, int second) { if (first < second) return t2; if (first == second)... |
#include <bits/stdc++.h> template <class T> T abs(T x) { return x > 0 ? x : -x; } const int MAXINT = 1111 * 1111 * 1111; const long long MAXLINT = MAXINT * 1ll * MAXINT; const long double EPS = 1e-10; using namespace std; int n, m, x, y, z, p; int a, b; void reverse_left() { int aa = a, bb =... |
#include <bits/stdc++.h> using namespace std; set<long long> s; map<long long, long long> m; vector<long long> v; long long n, a[100010], b[100010], dp[100010], mx = 0; bool mark[100010]; int main() { ios_base::sync_with_stdio(false); cin >> n; for (long long i = 1; i <= n; i++) { cin >>... |
#include <bits/stdc++.h> using namespace std; void _print(long long t) { cerr << t; } void _print(int t) { cerr << t; } void _print(string t) { cerr << t; } void _print(char t) { cerr << t; } void _print(long double t) { cerr << t; } void _print(double t) { cerr << t; } void _print(unsigned long long t)... |
#include <bits/stdc++.h> using namespace std; char s[1005]; char t[1000005]; int main() { scanf( %s , s); scanf( %s , t); int len1 = strlen(s); int len2 = strlen(t); int le = 0x3f3f3f3f; int ri = 0x3f3f3f3f; for (int i = 0, j = 0; j < len2; j++) { if (s[i] == t[j]) i++; i... |
#include <bits/stdc++.h> int N, K; std::string S; int main() { std::cin >> N >> K; std::cin >> S; std::string t = S; std::string s = ; for (int l = 1; l < N; ++l) { if (S.substr(0, l) == S.substr(N - l, l)) { t = S.substr(0, N - l); s = S.substr(N - l, l); } }... |
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> candies(n); for (int i = 0; i < n; i++) cin >> candies[i]; int i = 0, j = n - 1; int store_a = 0, store_b = 0; int turn = 0, sum_a = 0, sum_b = 0; while (i <= j) { if (turn % 2 == 0) { ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast , unroll-loops , no-stack-protector ) using namespace std; using ll = long long; using ld = double; using pii = pair<int, int>; using uint = unsigned int; using ull = unsigned long long; mt19937 rnd(chrono::steady_clock::now().time_since_epoch().cou... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.