func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; inline long long read() { long long x = 0, f = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) f = -1; c = getchar(); } while (c >= 0 && c <= 9 ) { x = (x << 1) + (x << 3) + c - 0 ; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 10; int gi() { int x = 0, o = 1; char ch = getchar(); while (!isdigit(ch) && ch != - ) ch = getchar(); if (ch == - ) o = -1, ch = getchar(); while (isdigit(ch)) x = x * 10 + ch - 0 , ch = getchar(); return x * o; } in... |
#include <bits/stdc++.h> using namespace std; bool checkbit(int mask, int bit) { return mask & (1 << bit); } int setbit(int mask, int bit) { return mask | (1 << bit); } int clearbit(int mask, int bit) { return mask & ~(1 << bit); } int togglebit(int mask, int bit) { return mask ^ (1 << bit); } int main() { ... |
#include <bits/stdc++.h> using namespace std; int main() { int N = 0; string s; cin >> N >> s; map<char, int> number = {{ 0 , 0}, { 1 , 1}, { 2 , 2}, { 3 , 3}, { 4 , 4}, { 5 , 5}, { 6 , 6}, { 7 , 7}, { 8 , 8}, { 9 , 9}}; int curr_prefix = 0; for (int i = 0; i < N... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n, x; cin >> n; long ans = 0; vector<int> divisiors, dp(1e6 + 1); dp[0] = 1; for (int i = 0; i < n; i++) { cin >> x; divisiors.clear(); ... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 10; int N, arr[MAXN], tid[MAXN], a[MAXN], b[MAXN]; int main() { scanf( %d , &N); for (int i = (0), iend = (N); i < iend; ++i) scanf( %d , &arr[i]); iota(tid, tid + N, 0); sort(tid, tid + N, [](const int& x, const int& ... |
#include <bits/stdc++.h> using namespace std; int a, b, k; int main() { cin >> a >> b >> k; a %= b; bool ok = false; int i; for (i = 0; i < 1000000; i++) { a *= 10; int x = a / b; a %= b; if (x == k) { ok = true; break; } } if (ok) co... |
#include <bits/stdc++.h> using namespace std; const double pi = 3.14159265; using namespace std; int a[200000]; int main() { int n, x, y; scanf( %d , &n); scanf( %d , &x); scanf( %d , &y); fill(a, a + 200000, 2e9); int count0 = -1; for (int i = 0; i < n; i++) { scanf( %d , &a... |
#include <bits/stdc++.h> using namespace std; int main() { long long l[2], r[2], k; cin >> l[0] >> r[0] >> l[1] >> r[1] >> k; long long max_ow = min(r[0], r[1]); long long min_ow = max(l[0], l[1]); long long ans = max_ow - min_ow; if (max_ow >= k && min_ow <= k) { ans--; } if (... |
#include <bits/stdc++.h> using namespace std; int n; const int N = 2e5; int dep[N], fa[N], cnt[N], ans; int main() { ios ::sync_with_stdio(0); cin >> n; ans = 1; for (int i = 2; i <= n; ++i) { cin >> fa[i]; dep[i] = dep[fa[i]] + 1; cnt[dep[i]] ^= 1; } for (int i = 1; ... |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const long long MOD = 1000000000 + 7; const int MAXN = 100000 + 5; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } inline long long readLL() { char ch; bool flag = false; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1E3 + 5, M = 11; int n, d; long long dp[N][M][N], inv[M] = {1}, ans, mo; inline void upd(long long &x, long long y) { x += y; if (x >= mo) x -= mo; } long long Pow(long long a, int b = mo - 2) { long long res = 1; for (; b; b >>= ... |
#include <bits/stdc++.h> using namespace std; long long t; long long a[200005]; int main() { ios_base::sync_with_stdio(false); cin >> t; while (t--) { long long n; cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; if (a[i] >= 0) a[i] %= n; else... |
#include <bits/stdc++.h> using namespace std; const int N = 1000010; int P[N]; string T[N]; vector<int> G[N], depth[N + 1]; int DP[N][4]; int V[N]; int D[N]; int dfs(int c) { D[c] = D[P[c]] + 1; depth[D[c]].push_back(c); if (T[c][0] == I ) return V[c]; if (T[c][0] == N ) return V[c] ... |
#include <bits/stdc++.h> using namespace std; long long i, j, k, s, l, m, n, t, a, c, b, d, e[11][11]; string p, q, r, f; int main() { cin >> n >> a >> m >> b; a = abs(b - a); s = 0; for (i = 1; i <= m; i++) { b = abs(a - i); c = a + i; t = 0; if (n >= c) { t = 2 ... |
#include <bits/stdc++.h> time_t st = clock(); using namespace std; template <class stl> void DBGSTL(stl a) { cout << tDEBUG: n t ; for (typeof(a.begin()) i = a.begin(); i != a.end(); i++) { cerr << *i << ; } cerr << n ; return; } long long gcd(long long a, long long b) { ret... |
#include <bits/stdc++.h> using namespace std; int n, m; long long a[333333]; const long long MOD = 1000000009; long long fib[333333]; long long fsum[333333]; inline const long long getFsum(const int l, const int r) { return ((fsum[r] - fsum[l - 1]) + MOD) % MOD; } inline void pllAdd(pair<long long... |
#include <bits/stdc++.h> using namespace std; long long n, a[1000005], ans, p = 1; int main() { scanf( %I64d , &n); for (int i = 1; i <= n; i++) scanf( %I64d , a + i); for (int i = n - 1; i > 0; p = (p << 1) % 998244353, i--) ans = (ans + (n + 2 - i) * p % 998244353 * a[i] % 998244353) % 9982443... |
#include <bits/stdc++.h> using namespace std; string s, s2, t1, t2; int main() { long long n, l, r, i, j; cin >> s; n = s.length(); char mx = a ; for (i = n - 1; i >= 0; i--) { if (s[i] - mx >= 0) { mx = s[i]; l = i; } } s2 += mx; r = l; for (i = mx... |
#include <bits/stdc++.h> using namespace std; template <class T> void OUT(T x, int n) { for (int i = 0; i < n; ++i) cout << x[i] << ; cout << endl; } template <class T> void OUT(T x, int n, int m) { for (int i = 1; i <= n; ++i) OUT(x[i], m); cout << endl; } template <class T> void c... |
#include <bits/stdc++.h> using namespace std; bool binary(vector<int> v, int key) { int lo = 0, hi = v.size() - 1; while (lo <= hi) { int mid = (lo + hi) / 2; if (v[mid] == key) return true; else if (v[mid] < key) lo = mid + 1; else hi = mid - 1; } ret... |
#include <bits/stdc++.h> using namespace std; using i64 = int_fast64_t; using seika = string; template <class kizuna> using akari = vector<kizuna>; template <class yuzuki> using yukari = akari<akari<yuzuki>>; template <class tsurumaki> using maki = akari<yukari<tsurumaki>>; template <class kotonoha>... |
#include <bits/stdc++.h> using namespace std; template <typename T> ostream& operator<<(ostream& os, const vector<T>& v) { for (auto i : v) os << i << ; return os; } template <typename T> ostream& operator<<(ostream& os, const set<T>& v) { for (auto i : v) os << i << ; return os; } ... |
#include <bits/stdc++.h> using namespace std; vector<int> v[3 * 100005]; int n, m, nr, h[3 * 100005], f[3 * 100005], a[3 * 100005], b[3 * 100005], t[3 * 100005], q; void dfs(int x) { for (auto it : v[x]) if (h[it] == 0) { t[it] = x; h[it] = h[x] + 1; dfs(it); } } ... |
#include <bits/stdc++.h> using namespace std; char str[100005]; int main() { cin.getline(str, 100005); int y = 0; int l = strlen(str); int has = 0; for (int i = 0; i < l; i++) { if (y == 1 && str[i] != ) { cout << str[i]; continue; } if (str[i] == ) { ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, k, p, total = 0; cin >> n; k = (n - 11) / 2; for (int i = 1; i <= n; i++) { char temp; cin >> temp; if (temp == 8 ) { total++; if (t... |
#include <bits/stdc++.h> using namespace std; const long long inf = 1e15; void Tez() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); } int main() { Tez(); long long n, k; cin >> n >> k; long long cap[k]; for (int i = 0; i < k; i++) cin >> cap[i]; long long tp = 1, no = ... |
#include <bits/stdc++.h> using namespace std; int vis[2000007]; string s; int main() { int n, k, i, j, l, x, len = 0, pos; string in; cin >> n; for (i = 0; i < 2000007; i++) s += a ; for (i = 0; i < n; i++) { cin >> in >> k; pos = -(int)in.length(); for (j = 1; j <= k; j++... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 502; int a[maxn][maxn]; int izq[maxn][maxn], arr[maxn][maxn]; void solve() { int n, m; cin >> n >> m; for (int i = 1; i <= n; i++) { for (int j = 1; j <= m; j++) { char c; cin >> c; ... |
#include <bits/stdc++.h> using namespace std; int a[5][5]; pair<int, int> cost[5]; int n; int main() { cin >> n; for (int i = 1; i <= 4; i++) for (int j = 1; j <= 4; j++) cin >> a[i][j]; for (int i = 1; i <= 4; i++) { cost[i].first = min(a[i][1] + a[i][3], min(a... |
#include <bits/stdc++.h> const int dx[] = {1, -1, 0, 0}; const int dy[] = {0, 0, -1, 1}; using namespace std; long long tests; long long n, m, b, MOD, dp[5256][5256], a[5256], ans; void solve() { scanf( %I64d%I64d%I64d%I64d , &n, &m, &b, &MOD); for (int i = 1; i <= n; i += 1) { scanf( %I64d , ... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); } long long min(long long a, long long b) { return a < b ? a : b; } long long max(long long a, long long b) { return a >... |
#include <bits/stdc++.h> using namespace std; inline char gc() { static char buf[100000], *p1 = buf, *p2 = buf; return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2) ? EOF : *p1++; } inline long long read() { long long x = 0; char ch = getcha... |
#include <bits/stdc++.h> using namespace std; string s; char a; int b, c, d, i, k, n; int main() { cin >> s; k = s.size(); if (k < 2) d = 1; while (n < 100 && d == 0) { while (i < k - 2 && d == 0) { if (s[i] > s[i + 2]) { a = s[i + 2]; s[i + 2] = s[i]; ... |
#include <bits/stdc++.h> using namespace std; int n, m, k; struct Edge { int u; int v; } e[1000000]; int dp[3000][3000]; bool Judge1(int x, int y) { for (int i = 0; i < n; i++) if (!(x & (1 << i)) && (y & (1 << i))) return false; return true; } bool Judge2(int u, int v, int x, int ... |
#include<bits/stdc++.h> using namespace std; int main() { int t; cin>>t; while(t--) { int a,b,c; cin>>a>>b>>c; int sum=a+b+c; if(sum<7) cout<< No <<endl; else { if(sum%9==0) { ... |
#include <bits/stdc++.h> using namespace std; int main() { int x, d; cin >> x >> d; long long start = 1; vector<long long> arr; while (x > 0) { int toPrint = 1; while ((1LL << toPrint) - 1 <= x) toPrint++; toPrint--; for (long long i = start; i < start + toPrint; i++) arr... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 5; int T, n, m; int t1, t2; bool w; map<pair<int, long long>, int> mex; int solve(int rem = 60, long long msk = (1 << 60) - 1) { if (mex.count({rem, msk})) { return mex[{rem, msk}]; } mex[{rem, msk}] = 0; int x = 0; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5, M = 2e3 + 5; const long long INF = 1e18 + 5; inline long long read() { long long sum = 0, fh = 1; char c = getchar(); while (c < 0 || c > 9 ) { if (c == - ) fh = -1; c = getchar(); } while (c >= 0 && c <= ... |
#include <bits/stdc++.h> using namespace std; void fre() { freopen( c://test//input.in , r , stdin); freopen( c://test//output.out , w , stdout); } template <class T1, class T2> inline void gmax(T1 &a, T2 b) { if (b > a) a = b; } template <class T1, class T2> inline void gmin(T1 &a, T2 b) ... |
#include <bits/stdc++.h> using namespace std; struct xy { int x, y; }; int a[1212121], par[1212121], depth[1212121]; vector<int> C[1212121]; void dfs(int w, int dep) { depth[w] = dep; for (int nxt : C[w]) dfs(nxt, dep + 1); } int Hn = 0, myH[1212121], sz[1212121], root[1212121], ppar[1212121... |
#include <bits/stdc++.h> int main() { int x, y; scanf( %d %d , &x, &y); printf( %d , (x * y - 1) / (y - 1)); } |
#include <bits/stdc++.h> using namespace std; int a[210][210], b[210][210]; int n, m; int main() { while (cin >> n >> m) { int ra = 1, rb = 1, ca = 1, cb = 1; for (int i = 1; i <= m; i++) if (i % 2) { a[ra++][ca] = i; if (ra > n) ra = 1, ca++; } else { ... |
#include <bits/stdc++.h> using namespace std; int n, bear, ans, a, aux, votes[128]; priority_queue<int> q; int Solution() { int ans = 0; while (bear <= q.top()) { aux = q.top(); if (bear <= aux) { bear++; aux--; q.pop(); q.push(aux); ans++; } ... |
#include <bits/stdc++.h> using namespace std; long long fpm(long long b, long long e, long long m) { long long t = 1; for (; e; e >>= 1, b = b * b % m) e & 1 ? t = t * b % m : 0; return t; } template <class T> inline bool chkmin(T &a, T b) { return a > b ? a = b, true : false; } template <... |
#include <bits/stdc++.h> using namespace std; const int MAX = 1e5 + 3; map<int, vector<int>> sign; int a[MAX]; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n; cin >> n; multiset<int> st; for (int i = 1; i <= n; i++) { cin >> a[i]; st.insert(a[i... |
#include <bits/stdc++.h> using namespace std; int num[105]; double cal(int w, int e, int s) { if (e < s) return 1.0; double res = 1, dw = (double)w, de = (double)e; for (int i = 0; i < s; i++) { res = res * de / dw; dw--; de--; } return 1.0 - res; } int main() { int n... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const ll M = 1e4 + 10; const ll G = 1e3 + 10; ll n, m, g, r; vector<ll> d; ll ansDep = -1; ll ansT = -1; bool seen[M][G]; ll ans = 1e17; void bfs() { deque<tuple<ll, ll, ll> > q; q.emplace_front(0, 0, 0); while (!q.emp... |
#include <bits/stdc++.h> using namespace std; long long res, cur, n, dp[1000006]; struct info { long long x, y; long long a; bool operator<(const info &b) const { return x < b.x; } }; struct P { long long x, y; P operator+(const P &a) const { return (P){x + a.x, y + a.y}; } P operator-... |
#include <bits/stdc++.h> using namespace std; template <typename T> bool chkmin(T &x, T y) { return x > y ? x = y, 1 : 0; } template <typename T> bool chkmax(T &x, T y) { return x < y ? x = y, 1 : 0; } int readint() { int x = 0, f = 1; char ch = getchar(); while (ch < 0 || ch > 9 ... |
#include <bits/stdc++.h> using namespace std; int main() { int k, l, m, n, i, j, d, fucked = 0; cin >> k >> l >> m >> n >> d; int p[100010]; if (k == 1 || l == 1 || m == 1 || n == 1) { cout << d; } else { for (i = 1; i <= d; i++) { if (i % (k) == 0 || i % (l) == 0 || i % (m) ... |
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (b == 0) return a; return gcd(b, a % b); } long long int lcm(long long int a, long long int b) { return (a / gcd(a, b)) * b; } long long int dp[2005][2005]; long long int help(long long int n... |
#include <bits/stdc++.h> using namespace std; void calc(int n, long long s, long long m, int i) { if (n == 0) return; s = s / 2; if (s < m) { calc(n - 1, s, m - s, i + 1); cout << i << ; } else { cout << i << ; calc(n - 1, s, m, i + 1); } } int main() { int ... |
#include <bits/stdc++.h> using namespace std; int max2; int two[35]; void DFS(int K, int L1, int R1, int L2, int R2) { if (((R1 - L1 + 1) <= max2) || ((R2 - L2 + 1) <= max2)) return; if (K == 0) { if (1 > max2) max2 = 1; return; } int L3, R3; if (L1 >= L2) L3 = L1; else... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using uint = unsigned int; using ull = unsigned long long; template <typename T> using pair2 = pair<T, T>; using pii = pair<int, int>; using pli = pair<ll, int>; using pll = pair<ll, ll>; mt19937_64 rng(chr... |
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; using std::pair; using std::string; using std::swap; using std::vector; void doit(int& xk, int& yk, int w, int h, int x, int y, int z) { for (int i = 0; i < x; ++i) { swap(xk, yk); swap(w, h); xk = w - xk + ... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; for (int i = 0; i < 2 * n + 1; i++) { for (int j = 0; j < 2 * n + 1; j++) { if ((i + j - n) >= 0 && i <= n && j <= n && i > 0) { cout << i + j - n << ; } else if (i <= n && j > n && (n + 1 + i ... |
#include <bits/stdc++.h> using namespace std; using ll = long long; const int INF = 0x3f3f3f3f; const int mxN = 61; ll level[mxN]; int q; int getlevel(ll x) { int res = 0; while ((1LL << res) <= x) { res++; } return res - 1; } int main() { cin.tie(0)->sync_with_stdio(0); ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int n, i, x = 0; cin >> n; string second; cin >> second; vector<long long int> v; if (second.size() == 1 && second[0] == ? ) return cout << Yes , 0; f... |
#include <bits/stdc++.h> using namespace std; #define ll long long #define mod 1000000007 #define ffor(i,a,b) for(int i=a;i<b;i++) #define bfor(i,a,b) for(int i=a-1;i>=b;i--) #define mp make_pair #define pb push_back #define ff first #define ss second #define mem(x,y) memset(x,y,sizeof(x)) #def... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 5; int N, M; long long tree[4][MAXN][MAXN]; int ju(int x, int y) { int tt = 0; if (x % 2) tt++; if (y % 2) tt += 2; return tt; } void Update(int x, int y, long long v) { int ty = ju(x, y); for (int i = x; i <= N; ... |
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 4e5 + 10; vector<int> ans[N]; vector<int> v[N]; int tot; int vis[N]; int cnt = 0; void dfs(int x) { vis[x] = 1; ans[cnt++ / tot].push_back(x); for (auto &y : v[x]) { if (vis[y]) continue; ... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long INF = 1e18; template <typename T> void read(T &x) { x = 0; int s = 1, c = getchar(); for (; !isdigit(c); c = getchar()) if (c == - ) s = -1; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; ... |
#include <bits/stdc++.h> using namespace std; long long int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long int t; cin >> t; while (t--) { long long int l, r, m; cin >> l >> r >> m; long long int nn, xx; long lo... |
#include <bits/stdc++.h> using namespace std; const long long INF = 5e18; const int MK = 10101; const int MN = 101010; long long H, M, N, K; map<long long, long long> mp; vector<long long> methods; vector<pair<long long, long long> > ip[MK]; bool pllcmp(pair<long long, long long> p1, pair<long long, l... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:268435456 ) using namespace std; template <typename T> T sqr(const T &x) { return x * x; } template <typename T> T my_abs(const T &x) { return x < 0 ? -x : x; } const int INF = (int)1e9; const long long LINF = (long long)6e18; const ... |
#include <bits/stdc++.h> using namespace std; const long long MOD = 1e9 + 7; const double pi = acos(-1.0); int32_t main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long tt; tt = 1; while (tt--) { long long n, m; cin >> n >> m; long long cost[n + 2]; ... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; cin >> n; vector<long long> a; for (int i = 0; i < n; i++) { long long x; cin >> x; a.push_back(x); } long long m = 0; for (int i = 0; i < (n... |
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long long int lli; const int mod=1e9+7; int main() { ll t; cin>>t; while(t--) { ll n; cin>>n; if(n<=32) { ll m=n-3; m+=5; ... |
#include <bits/stdc++.h> using namespace std; int read() { int a = 0; char c = getchar(); while (!isdigit(c)) c = getchar(); while (isdigit(c)) { a = a * 10 + c - 48; c = getchar(); } return a; } const int _ = 3e5 + 7, __ = _ * 19; vector<int> nxt[_]; int N, M, dep[_]; ... |
#include <bits/stdc++.h> int main() { int x, y, s; scanf( %d %d %d , &x, &y, &s); if (s >= 0) { y = y + s; if (y % x) printf( %d , y % x); else printf( %d , x); } else if (s < 0) { double p = abs(s); p = ceil(p / x); y = y + s + (p * x); if (y ... |
#include <bits/stdc++.h> using namespace std; int main() { long long q = 1, w, a[3], s[3], d[3] = {1000000000, 0, 0}; for (w = 0; w < 18; w++) q *= 10; bool c = 0; for (w = 0; w < 3; w++) { cin >> a[w] >> s[w]; if ((w == 2) && (d[2] > 0)) c = 1; if (a[w] == 0) { if (s[w] > ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); ; long long n, a, b; cin >> n >> a >> b; set<long long> s; while (a--) { long long j; cin >> j; s.insert(j); } for (long long i = 1; i... |
#include <bits/stdc++.h> using namespace std; const int INF = 1e9, MAXN = 4010; int n; inline int pack(int l, int r, int k) { return (l << 19) + (r << 7) + k; } unordered_map<int, int> dp(MAXN* MAXN * 2); vector<int> a, pref; int calc(int l, int r, int k, int p) { if (p) { if (dp.count(pack(l, r... |
#include <bits/stdc++.h> using namespace std; const int INF = numeric_limits<int>::max(); int n; vector<int> d, a; int get_longest(int l) { vector<int> d; while (l > a.size()) for (int i = 0; i < n; ++i) a.push_back(a[i]); d.assign(l + 10, INF); d[0] = -INF; for (int i = 0; i < l; ++... |
#include <bits/stdc++.h> using namespace std; namespace DynamicTree { unsigned int randxor() { static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123; unsigned int t; t = (x ^ (x << 11)); x = y; y = z; z = w; return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8))); } s... |
/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press Run button to compile and execute it. ******************************... |
#include <bits/stdc++.h> using namespace std; int main() { int x, x1, y, y1; char a, b; cin >> a >> y >> b >> y1; x1 = a - 96; x = b - 96; int counter = 0; string s[100000]; while (true) { if (x == x1 && y == y1) { break; } if (x > x1) { x1++; ... |
#include <bits/stdc++.h> using namespace std; const int N = 1e5 + 7; const int INF = 1e8 + 7; int n; int Min[N][20], Max[N][20]; struct Node { int x, y; bool operator<(const Node& p) const { return x < p.x; } } nod[N]; long long sqr(long long x) { return x * x; } void rmq() { for (int i = ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e5 + 100; int m, n, h; int t[maxn]; int first[maxn * 2], nxt[maxn * 2], des[maxn * 2], tot; int dfn[maxn], low[maxn], dft; bool d[maxn]; int flag[maxn], cnt[maxn], scc; stack<int> stk; inline void add(int x, int y) { tot++; des[... |
#include <bits/stdc++.h> using namespace std; int n, i, j, a[2002]; double p[5005], sp[5005], m, res; int main() { scanf( %d , &n); for (i = 0; i < n; i++) scanf( %d , &a[i]); sort(a, a + n); for (i = 0; i < n; i++) for (j = 0; j < i; j++) p[a[i] - a[j]]++; m = (n - 1) * n / 2; for... |
#include <bits/stdc++.h> using namespace std; int main() { long long T, n, i, l, r, mid, res; scanf( %lld , &T); while (T--) { scanf( %lld , &n); l = 2; r = n - 1; res = n - 1; while (l <= r) { mid = (l + r) >> 1; if (mid * (mid - 1) / 2 + (n - mid) <= 2 * (... |
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) { cerr << endl; } template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << , ; err(++it, args...); } void solve() { int n, m; cin >> n ... |
#include <bits/stdc++.h> using namespace std; int k[5] = {3, 4, 5, 4, 3}; int st[5] = {0, 0, 0, 1, 2}; int dx[] = {0, -1, -1, 0, 1, 1}; int dy[] = {-1, -1, 0, 1, 1, 0}; int x[32], y[32]; int id[32][32]; char a[32][32]; char f[1 << 20]; int prep() { memset(id, 0xff, sizeof(id)); int n = 0; ... |
#include <bits/stdc++.h> using namespace std; long long read() { char c = getchar(); if (c < 0 && c > 9 && c != - ) c = getchar(); long long f = 1, cnt = 0; if (c == - ) f = -1, c = getchar(); while (c >= 0 && c <= 9 ) { cnt = cnt * 10 + int(c - 0 ); c = getchar(); } ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long q; cin >> q; while (q--) { long long n, m; cin >> n; cin >> m; if (m > n || m % 10 == 0) { cout << 0 << n ; continue... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:65777216 ) using namespace std; long long n, l, r, ql, qr, sum, ans, w[100005]; long long koll, kolr, t; using namespace std; int main() { cin >> n >> l >> r >> ql >> qr; for (int i = 1; i <= n; i++) { cin >> w[i]; sum += w[i] * r;... |
#include <bits/stdc++.h> using namespace std; const double EPS = 1e-9; const double PI = acos(-1.0); const int MOD = 1000 * 1000 * 1000 + 7; const int INF = 2000 * 1000 * 1000; template <typename T> inline T sqr(T n) { return n * n; } int C, Hr, Hb, Wr, Wb; long long ans; int main() { scan... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; cout << (n <= 2 ? n : n % 2 ? (long long)n * (n - 1) * (n - 2) : n % 3 ? (long long)n * (n - 1) * (n - 3) : (long long)(n - 1) * (n - 2) * (n - 3)) << n ; return 0; ... |
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( Ofast ) const int maxn = 1e5 + 10, N = 3e6, SQ = 1000, base = 800287, mod = 1e9 + 7, INF = 1e9 + 10, lg = 22; const long double eps = 1e-4; int n, m, q; unordered_map<int, int> par[maxn], res[maxn]; inline int root(int v, int ... |
#include <bits/stdc++.h> using namespace std; long long int power(long long int a, long long int b) { if (b == 0) return 1; long long int c = power(a, b >> 1); c = (c * c) % 1000000007; if (b & 1) return (a * c) % 1000000007; return c; } const int N = (int)1e5 + 5; const int Q = 301; int... |
#include <bits/stdc++.h> using namespace std; const int MOD = 998244353; const int BITS = 60; struct tree_node { int child[2] = {-1, -1}; bool full = false; }; struct tree { vector<tree_node> nodes = {tree_node()}; int get_or_create_node(int &node) { int answer = node; if (node <... |
#include <bits/stdc++.h> using namespace std; int main(void) { int t, n, i, j, x; int n1, n2; int a, b, p, q; cin >> t; for (i = 0; i < t; i++) { cin >> n; n1 = 0, n2 = 0; vector<int> v, v1, v2; vector<int> even, odd; for (j = 0; j < n; j++) { cin >> x; ... |
#include <bits/stdc++.h> using namespace std; int n, m; int a[2005][2005]; bitset<2000> b[2000]; bitset<2000> c[2000]; int u[500005], v[500005]; template <class T> void dbg(T x) { for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { cout << (int)x[i][j]; } cout << ... |
#include <bits/stdc++.h> using namespace std; long long dx4[] = {0, 0, -1, 1}; long long dy4[] = {-1, 1, 0, 0}; long long n, m; long long V[5003]; long long cnt[5003]; long long dis(long long x, long long y) { if (y > x) return y - x; else { return y + n - x; } } long long res[... |
#include <bits/stdc++.h> using u32 = unsigned; using u64 = unsigned long long; int lg_ceil(u64 n) { return 63 - __builtin_clzll(2 * n - 1); } int lg_floor(u32 n) { return 31 - __builtin_clz(n); } template <class T> struct sparse_table { sparse_table() {} sparse_table(std::vector<T>& V, std::function... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n], b[n]; for (int i = 0; i < n; ++i) cin >> a[i]; for (int i = 0; i < n; ++i) cin >> b[i]; int ans = 0; for (int i = 0; i < n; ++i) { int x = a[i], y = b[i]; ans = max(ans, x + y); for (i... |
#include <bits/stdc++.h> using namespace std; const int maxn = 200010, P = 1000000007; int n, q, a[maxn], b[maxn], w[maxn]; __int128 c1[maxn], c2[maxn]; void add(__int128 *c, int p, __int128 v) { for (; p <= n; p += p & -p) c[p] += v; } __int128 sum(__int128 *c, int p) { __int128 s = 0; for (;... |
#include <bits/stdc++.h> using namespace std; long long int len = 0, k = 0, a[100005], p, q; void findlength(long long int n, long long int mul) { if (n < 2) return; if (n % 2 == 0) { len += mul; } findlength(n / 2, 2 * mul); } void findans(long long int n, long long int l, long long int... |
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; using vi = vector<int>; const int MAXN = 5 + 100000; vector<int> g[MAXN], s; bitset<MAXN> vis; int k, pos[MAXN]; void dfs(int u) { assert(int(g[u].size()) >= k); vis[u] = true; pos[u] = s.size();... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.