func_code_string stringlengths 59 71.4k |
|---|
#include <bits/stdc++.h> int main() { int dem = 1, i, n, c; scanf( %d %d , &n, &c); int a[n]; for (i = 0; i < n; i++) { scanf( %d , &a[i]); } for (i = 1; i < n; i++) { if (a[i] - a[i - 1] <= c) { dem++; } if (a[i] - a[i - 1] > c) { dem = 1; } }... |
#include <bits/stdc++.h> using namespace std; const int m = 1e9 + 7; const int N = 3e5 + 15; const int64_t INF = 100000000000000018LL; priority_queue<pair<long long, long long>, vector<pair<long long, long long>>, greater<pair<long long, long long>>> pq; vector<vector<long long>> grap... |
#include <bits/stdc++.h> using namespace std; struct Point { int x, y; Point(int x0, int y0) : x(x0), y(y0) {} Point() : x(0), y(0) {} }; int t; int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1}; int dy[] = {0, -1, 0, 1, -1, 1, -1, 1}; int n, m; long long maxx; int d[100005][4]; int a[100005], h[10... |
#include <bits/stdc++.h> using namespace std; int main() { int n; string str; cin >> n >> str; int sum = 0; bool flag = false; for (int i = 0; i < n - 1; i++) { sum += str[i] - 48; int ts = 0, ti = i + 1; while (ti < n && ts <= sum) { if (ts == sum && str[ti] != 48)... |
#include <bits/stdc++.h> using namespace std; int n, m, st; int tmp, tmp2; vector<int> adj[200005]; int memo[200005][5]; bool vis[200005][5]; int stc, stn; pair<int, int> par[200005][5]; int dp(int node, int cur) { if (adj[node].size() == 0) { if (cur == 2) { stc = cur; stn =... |
#include <bits/stdc++.h> using namespace std; int n, k; char ch[111111]; int main() { scanf( %d%d , &n, &k); scanf( %s , ch); int pos = 0; for (int act = 0; act <= 1000000 && act < k && pos < n - 1; ++act) { if (act >= 1000000 && act % 2 == k % 2) break; while (pos < n - 1 && !(ch[po... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 100000; const int MAXV = 100; double prob[MAXN + 5][MAXV + 5]; int sz[MAXN + 5]; double temp[MAXV + 5]; int n; double ncr(int r, int n) { if (r > n) return 0; double ret = 1; for (int c = 0; c < r; c++) ret *= n - c; for (int... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:500000000 ) using namespace std; vector<int> A[2]; int main() { int n, i, j, t, w; cin >> n; for (i = 0; i < n; i++) { cin >> t >> w; A[t - 1].push_back(w); } for (i = 0; i < 2; i++) sort(A[i].begin(), A[i].end(), greater<i... |
#include <bits/stdc++.h> using namespace std; void solve() { long long int a, b, k; cin >> a >> b >> k; long long int total = 0; if (k % 2 != 0) { total -= b * (k / 2); total += a * (k / 2 + 1); } else { total -= b * (k / 2); total += a * (k / 2); } cout << total ... |
#include <bits/stdc++.h> using namespace std; int a[503][503]; int max_row[503]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); int n, m, q, i, j, mxi, cnt, x, y; cin >> n >> m >> q; for (i = 1; i <= n; i++) { mxi = 0, cnt = 0; for (j = 1; j <= m; j++) { cin >> a[... |
#include <bits/stdc++.h> using namespace std; int n, m; char A[200006]; int S[200006], T[200006]; void solve() { cin >> n >> m; scanf( %s , A + 1); long long re = 0; for (int i = (1), iend = (n); i <= iend; ++i) { S[i] = (A[i] != A[i + 1]) + S[i - 1]; if (i >= 2 && A[i] == A[i - 2]... |
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, m, n, x, y; cin >> n; if (n == 1) { x = 9; y = 8; } if (n == 2) { x = 6; y = 4; } if (n == 3) { x = 9; y = 6; } if ((n != 2) && (n != 1) && (n != 3)) { if (... |
#include <bits/stdc++.h> using namespace std; unsigned long long A, B, D; int a[70], b[70], len1, len2; int main() { cin >> A >> B; D = A - B; unsigned long long temp = A; if (A < B) { cout << -1 << endl; return 0; } while (A) { a[len1++] = A % 2; A /= 2; } ... |
#include <bits/stdc++.h> using namespace std; int main() { long long x, d; while (~scanf( %lld%lld , &x, &d)) { vector<pair<long long, int> > counts; long long sum = 0; long long num = 1; while (x > 0) { long long two = 1; int count = 0; while (two - 1 <= x) t... |
#include <bits/stdc++.h> using namespace std; int long long x, y, l, r, k, i, j, ans; vector<int long long> mex, mey, my; int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); cin >> x >> y >> l >> r; for (k = 1; k <= 1e18 / x; k *= x) mex.push_back(k); if (k <= 1e18)... |
#include <bits/stdc++.h> using namespace std; int N, P; bool can = false; string word; int main() { scanf( %d%d , &N, &P); cin >> word; if (P == 1) { cout << NO n ; return 0; } else if (P == 2) { if (N == 1) { if (word == a ) cout << b n ; else ... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); ; int ts; cin >> ts; while (ts--) { long long n, i, vis[500] = {0}, a; cin >> n; for (i = 1; i <= 2 * n; i++) { cin >> a; if (vis[a] == ... |
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 7; int a[1003][1003], p[maxn], num[maxn], n, m, vis[1003][1003]; long long k; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; int fi(int x) { return p[x] == x ? x : p[x] = fi(p[x]); } void uni(int x, int y) { int p1 = fi(x), ... |
#include <bits/stdc++.h> using namespace std; bool prime[100005]; int dp[505][505], dp2[505][505]; int main() { long long int h, w, i, j, a, b, c, d, q, sum; cin >> h >> w; char arr[h][w + 1]; for (i = 0; i <= h - 1; i++) cin >> arr[i]; for (i = 0; i <= h - 1; i++) { for (j = 1; j <= w... |
#include <bits/stdc++.h> using namespace std; const int Maxn = 2e6 + 14; int n, a[Maxn], b[Maxn], ans, m; int main() { cin >> n; for (int i = 0; i < n; i++) cin >> a[i], b[a[i]] = a[i], m = max(m, a[i]); sort(a, a + n); for (int i = 1; i <= 2 * m; i++) { if (b[i] == 0) b[i] = b[i - 1]; ... |
#include <bits/stdc++.h> using namespace std; const int oo = 1e9; const int MX = 1e6 + 5; const int MD = 1e9 + 7; int next(vector<int> &a, int pos, long long p) { long long cnt = 2; int l = pos, r = pos; while (r < ((int)a.size())) { while (r < ((int)a.size()) && cnt > 0 && a[r] == a[l]) r++... |
#include <bits/stdc++.h> using namespace std; int main() { int n; char a[15], b[15], c[15]; scanf( %s%s , a, b); scanf( %d , &n); printf( %s %s n , a, b); for (int i = 1; i <= n; i++) { scanf( %s , c); int l = strlen(c); int la = strlen(a); int lb = strlen(b); i... |
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 1; const long long nol = 0; long long n, k, a, cnt, ans, j, mx; deque<long long> v, vc; void vkoshp() { cin >> n >> k; for (long long i = 0; i < n; i++) { cin >> a; v.push_back(a); } for (long long i = 0; i <... |
#include <bits/stdc++.h> using namespace std; int f[10000001]; int main() { int n, m, l, r; scanf( %d%d , &n, &m); long long ans = 0; int Max0 = max(n * 2, m); for (long long b = 1; b <= n; ++b) { ans += 2 * min(b * b, (long long)m); l = max(0, int(ceil(sqrt(b * b - m)))); r ... |
#include <bits/stdc++.h> using namespace std; int t = 0; int ans = 1; long long int prime(long long int n) { while (n % 2 == 0) { if (t == 2) break; n = n / 2; t++; ans *= 2; } for (int i = 3; i <= sqrt(n); i += 2) { while (n % i == 0) { if (t == 2) break; ... |
#include <bits/stdc++.h> using namespace std; void err(istream_iterator<string> it) {} template <typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) { cerr << *it << = << a << n ; err(++it, args...); } template <class T1, class T2> ostream &operator<<(ostre... |
#include <bits/stdc++.h> using namespace std; const int INF = INT_MAX - 10000000; const double eps = 1e-8; long long t1, t2, x1, x2, t0; int main() { cin >> t1 >> t2 >> x1 >> x2 >> t0; if (t1 == t2) { cout << x1 << << x2 << endl; return 0; } long long minp = 12345678, minq = 1;... |
#include <bits/stdc++.h> using namespace std; int N, K; int A[310000]; int dp[31000][210][4][2]; int ins(int i, int k, int bit) { if (k == 1) { if (bit % 2 == 0) return A[i]; return -A[i]; } if (k == K) { if (bit / 2 == 0) return -A[i]; return A[i]; } int res = 0; ... |
#include <bits/stdc++.h> using namespace std; long long powmod(long long n, long long q) { long long ans = 1; n %= 1000000007; while (q > 0) { if (q & 1) ans = (ans * n) % 1000000007; n = (n * n) % 1000000007; q >>= 1; } return ans % 1000000007; } int main() { ios_base:... |
#include <bits/stdc++.h> int reverseChar(char input) { const int N = 8; int output(0); for (int p = 0; p < N; p++) { output = 2 * output + (input % 2); input /= 2; } return output; } int main() { const int N = 256; std::string line; getline(std::cin, line); int prev... |
#include <bits/stdc++.h> using namespace std; struct box { long long int x1, x2, y1, y2; box() : x1(0), x2(0), y1(0), y2(0) {} box(int x1, int x2, int y1, int y2) : x1(x1), x2(x2), y1(y1), y2(y2) {} }; struct edge { long long int to, c, f; edge() : to(0), c(0), f(0) {} edge(int to, long ... |
#include <bits/stdc++.h> using namespace std; const int N = 5010; const int MOD = 1000000007; int n, x[N], y[N], w[N][N], vis[N]; inline void dfs(int v, int val) { for (int u = 0; u < n; u++) { if (w[v][u] > val) { if (vis[u] == vis[v]) throw 0; if (vis[u] != -1) continue; vi... |
#include <bits/stdc++.h> using namespace std; long long int rowblk[200005]; long long int colblk[200005]; long long int col[200005]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int l, n, i, j, k, m; cin >> n >> m; for (i = 1; i <= m; i++) { cin >> k >> l; ... |
#include <bits/stdc++.h> using namespace std; long long arr[200001]; long long gcd(long long a, long long b) { if (b == 0) return a; return gcd(b, a % b); } int main() { int n; cin >> n; for (int i = 0; i < n; ++i) { cin >> arr[i]; } sort(arr, arr + n, greater<int>()); lo... |
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cout << ? << ; fflush(stdout); for (int i = 0; i < 100; i++) { cout << i << ; fflush(stdout); } cout << endl; int n; cin >> n; c... |
#include <bits/stdc++.h> using namespace std; struct Pair { int a, b, c; }; int a1[200009], a2[200009]; vector<Pair> arr; bool rules(Pair x, Pair y) { return ((x.a - x.b) < (y.a - y.b)); } int main() { int n, k, sum = 0; scanf( %d%d , &n, &k); for (int i = 0; i < n; i++) scanf( %d , &a1[i]... |
#include <bits/stdc++.h> using namespace std; template <class T> inline void umax(T &x, T y) { if (y > x) x = y; } template <class T> inline void umin(T &x, T y) { if (y < x) x = y; } const int N = 2e5 + 5, B = 0x7fffffff; map<int, int> comp; set<int> s; vector<int> ans; int a[N]; int ... |
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const long long int MOD = 1000000007; int main() { int t, a, b; scanf( %lld , &t); while (t--) { scanf( %d %d , &a, &b); if (b >= a) printf( 1 ); else { vector<int> v; bool k = false; ... |
#include <bits/stdc++.h> using namespace std; template <typename T> void __p(T a) { cout << a; } template <typename T, typename U> void __p(pair<T, U> a) { cout << { ; __p(a.first); cout << , ; __p(a.second); cout << } ; } template <typename T> void __p(std::vector<T> a) { ... |
#include <bits/stdc++.h> using namespace std; int n, x; bool X[26]; int mat[6][6]; int niz[26]; int sum; bool check() { sum = 0; for (int i = 0; i < n; i++) sum += mat[i][0]; for (int j = 1; j < n; j++) { int st = 0; for (int i = 0; i < n; i++) st += mat[i][j]; if (st != sum)... |
#include <bits/stdc++.h> using namespace std; int n, a[200001], b[200001], m; int main() { cin >> n >> m; n = n + m; for (int i = 1; i <= n; i++) { scanf( %d , &a[i]); } vector<int> vec; for (int i = 1; i <= n; i++) { scanf( %d , &b[i]); if (b[i] == 1) { vec.push_... |
#include <bits/stdc++.h> using namespace std; bitset<1000> mask[1010]; long long sqr(int x) { return 1LL * x * x; } int n, m, k; int px[10010], py[10010], x[10010], y[10010], r[10010]; int main() { int i, j; scanf( %d%d%d , &n, &m, &k); for (i = 0; i < n; ++i) { scanf( %d%d , &px[i], &py[i... |
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n; int head[N], Next[N << 1], ver[N << 1], size[N], edge[N << 1], w[N]; int tot; long long ans; void add(int x, int y, int z) { ver[++tot] = y; edge[tot] = z; Next[tot] = head[x]; head[x] = tot; } void dfs(int x, i... |
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 50; const int mod = 1e9 + 7; const int inf = 0x3f3f3f3f; long long n, k; long long a[maxn]; int vis[maxn]; long long ans = 0; bool Overflow(long long x, long long y) { if (x > LLONG_MAX / y) return false; else ret... |
#include <bits/stdc++.h> using namespace std; const long long MAXN = 1e5 + 5; long long N, K; long long v[MAXN]; int main() { cin >> N >> K; for (int i = 0; i < N; i++) cin >> v[i]; sort(v, v + N); long long resp = N; for (int i = 0; i < N; i++) { long long value = v[i] * K; in... |
#include <bits/stdc++.h> using namespace std; int main() { long long int i, j, k, n, c = 0, p = 0, al, bl, l = 0; string s; cin >> s; for (i = 0; i < s.length(); i++) { l++; c += (s[i] - 0 ); if (c % 3 == 0 || (s[i] - 0 ) % 3 == 0 || l >= 3) { p++; c = 0; ... |
#include <bits/stdc++.h> using namespace std; const int NMX = 5007; const int MMX = 20007; long long a[NMX][NMX]; long long mi[NMX]; int main() { int n, m; scanf( %d %d , &n, &m); for (int i = 1; i <= m; i++) { int k, l; scanf( %d %d , &k, &l); a[k % n][l % n] += 1; } f... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int h[n]; for (int i = 0; i < n; i++) { cin >> h[i]; } int wys[n][2]; int rosnpr = 0; int rosnlw = 0; for (int i = 0; i < n; i++) { if (h[i] > rosnpr) { rosnpr++; wys[i][0] = r... |
#include <bits/stdc++.h> using namespace std; template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p) { out << ( << p.first << , << p.second << ) ; return out; } template <typename T> ostream& operator<<(ostream& out, vector<T> const& v) { int l = v.size();... |
#include <bits/stdc++.h> using namespace std; struct fenwick_tree_t { vector<int> t; void init(int n) { t.assign(n, 0); } void inc(int pos, int x = 1) { while (pos < (int)t.size()) { t[pos] += x; pos = pos | (pos + 1); } } int get(int pos) const { int ret = 0; ... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx,avx2,fma ) using namespace std; bool sortbysec(const pair<char, int> &a, const pair<char, int> &b) { return (a.second < b.second); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); string ip, hh, mm;... |
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const int N = 1e5 + 10; char a[N], b[N]; int main() { int t; scanf( %d , &t); while (t--) { int n; scanf( %d , &n); scanf( %s%s , a, b); int t = 0; int t1 = 0, t2 = 0; for (int i = 0; i < ... |
#include <bits/stdc++.h> using namespace std; int n, m, q; int par[26][100005], depth[100005]; vector<int> st[400005]; vector<int> G[100005]; vector<int> SS[26][100005]; int cnt, chaincnt; void get10(vector<int> &res, const vector<int> &fir, const vector<int> sec) { int c1 = 0, c2 = 0; res = vec... |
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int n, c; cin >> n >> c; int a[n], t[n]; for (int i = 0; i < n; i++) cin >> a[i]; for (int j = 0; j < n; j++) cin >> t[j]; int b = 0, e = 0, e1 = 0; for (int i = 0; i < n; i++) { ... |
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } void vrikodara(long long n = 12) { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cout << setprecision(n) << fixed; } long long lb = 100000; void solve() { long... |
#include <bits/stdc++.h> using namespace std; long long vis[1009]; vector<long long> v[1000]; long long th, n; void dfs(long long s) { if (vis[s]) return; vis[s] = 1; for (long long i = 0; i < v[s].size(); i++) { if (s <= n) th++; dfs(v[s][i]); } } int main() { ios_base::sy... |
#include <bits/stdc++.h> using namespace std; int main() { int a[7]; while (scanf( %d , &a[0]) != EOF) { int maxx = a[0]; int minn = a[0]; int ans = 0; for (int i = 1; i < 6; i++) { cin >> a[i]; } ans = (a[0] + a[1] + a[2]) * (a[0] + a[2] + a[1]) - a[0] * a[0] - ... |
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize( -O3 ) using ld = long double; const long long int mod = 1000000007; const long long int inf = 1000000000000000000; const long long int rk = 256; const ld PI = 3.141592653589793; ostream& operator<<(ostream& os, pair<long long int, long ... |
#include <bits/stdc++.h> using namespace std; const long long N = 100005, val1 = 20, val2 = 50, val3 = 120; long long in[N], sum[N]; int n; long long Sum(int pos) { if (pos < 0) return 0LL; return sum[pos]; } int main() { cin >> n; for (int i = 0; i < n; i++) cin >> in[i]; for (int i =... |
#include <bits/stdc++.h> using namespace std; const int MAXN = 200005; int n; int a[MAXN]; int inc[MAXN], p; int de[MAXN], q; bool flag; int main() { scanf( %d , &n); for (int i = 1; i <= n; ++i) scanf( %d , &a[i]); sort(a + 1, a + n + 1); for (int i = 3; i <= n; ++i) if (a[i] == a... |
#include <bits/stdc++.h> using namespace std; int p, n, m, x[10005], ans; char c[10005], *s; void Init() { scanf( %d , &p); scanf( %s , c + 1); if (c[1] == - ) s = c + 1; else { c[0] = + ; s = c; } n = strlen(s); int d, t; for (int i = 0; i <= n - 1; ++i) { ... |
#include <bits/stdc++.h> using namespace std; inline int gcd(int a, int b) { return (b == 0 ? a : gcd(b, a % b)); } inline int lcm(int a, int b) { return (a * (b / gcd(a, b))); } inline long long int bigmod(long long int a, long long int b, long long int m) { if (b == 0) return 1 % m; long long int x = ... |
#include <bits/stdc++.h> using namespace std; const long long N = 1e6 + 5, mod = 1e9 + 7; long long n, k, pre[N], suf[N], fac[N], qx[N], qy[N]; long long mul(long long x, long long n, long long mod) { long long ans = mod != 1; for (x %= mod; n; n >>= 1, x = x * x % mod) if (n & 1) ans = ans * x % ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, r, s, range = 0; scanf( %d%d , &n, &m); vector<int> sub[m + 1]; set<int> st; for (int i = 0; i < n; i++) { scanf( %d%d , &s, &r); sub[s].push_back(r); st.insert(s); } for (auto it : st) { int sz ... |
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; long long po[1000006]; long long sr[1000006]; long long a[1000006]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); po[0] = 1; sr[0] = 1; for (int i = 1; i <= 1000002; i++) { po[i] = po[i - 1]... |
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { if (a[i] != i + 1) { cout << i + 1; return 0; } } cout << n + 1; return 0; } ... |
#include <bits/stdc++.h> using namespace std; int vis[100005], tick = 0; vector<int> G[100005]; int a[200001], b[200005]; int main() { int n, m, h, t; scanf( %d%d%d%d , &n, &m, &h, &t); for (int i = 1; i <= m; ++i) { int u, v; scanf( %d%d , &u, &v); G[u].push_back(v); G[v].... |
#include <bits/stdc++.h> using namespace std; const int maxn = 5e3 + 5; char a[maxn], b[maxn]; int dp[maxn][maxn]; int main() { int n, m; cin >> n >> m; scanf( %s%s , a + 1, b + 1); int max_ = 0; for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { if (a[i] == b[j]) ... |
#include <bits/stdc++.h> using namespace std; const int MOD = int(1e9) + 7; const long long int MOD64 = (long long int)(1e18) + 7; const int INF = 0x7fffffff; const long long int INF64 = 0x7fffffffffffffff; const int N = 2e4 + 200; int a[60][N]; int sum[60][N]; int dp[60][N]; int t[4 * N], lazy[4 * ... |
#include <bits/stdc++.h> using namespace std; long long v[200005]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); long long tc; cin >> tc; while (tc--) { long long n; cin >> n; for (long long int i = 0; i < n; i++) { cin >> v[i]; } ... |
#include <bits/stdc++.h> using namespace std; const int N = 105; int n, m, c[N], s[N]; bool cmp(int a, int b) { return a > b; } int main() { int cnt = 0, p = 0, q = 0; scanf( %d , &n); for (int i = 0; i < n; i++) { scanf( %d , &m); int tmp = m / 2; for (int j = 0; j < m; j++) { ... |
#include <bits/stdc++.h> using namespace std; const int N = 1200; int n; const double eps = 1e-9; double c, t; double dp[110][110][1110]; double skill[110]; pair<int, int> a[N]; inline bool cmp(pair<int, int> a, pair<int, int> b) { return a.first > b.first; } inline long long get() { int s... |
#include <bits/stdc++.h> using namespace std; int a[200000]; int calculate(int x, int y) { int pos1 = -1, pos2 = -1; for (int i = x; i <= y; i++) { if (a[i] != -1) { if (pos1 == -1) pos1 = i; else if (pos2 == -1) pos2 = i; else break; } ... |
#include <bits/stdc++.h> using namespace std; long long t[200025 * 4], lz[200025 * 4], n, a[200025]; void build(int l, int r, int i) { t[i] = 1ll * l * (l - 1) / 2; if (l == r) return; build(l, (l + r) / 2, i * 2 + 1); build((l + r) / 2 + 1, r, i * 2 + 2); t[i] = max(t[i * 2 + 1], t[i * 2 + 2]... |
#include <bits/stdc++.h> #pragma comment(linker, /STACK:640000000 ) using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); template <class T> T sqr(T x) { return x * x; } const int maxn = (int)(1e5) + 10; const int inf = (int)(2e9); struct Edge { int to, w, num; Edg... |
//#include /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/bits/stdc++.h #include <bits/stdc++.h> using namespace std; //#include <atcoder/dsu> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_... |
#include <bits/stdc++.h> using namespace std; template <typename A, typename B> ostream &operator<<(ostream &os, const pair<A, B> &p) { return os << ( << p.first << , << p.second << ) ; } template <typename T_container, typename T = typename enable_if< !is_same<... |
#include <bits/stdc++.h> using namespace std; int main() { int x1, y1, x2, y2; while (scanf( %*d %*d %d %d %d %d , &x1, &y1, &x2, &y2) == 4) { int a = abs(x1 - x2), b = abs(y1 - y2); if (min(a, b) <= 2 && max(a, b) < 5) puts( First ); else if (max(a, b) < 4) puts( First );... |
#include <bits/stdc++.h> using namespace std; const int N = (int)2e5 + 5; vector<int> g[N], son[N]; bool used[N]; int tin[N], tout[N], tup[N]; vector<int> fstep[N]; int start = -1, a, b, c; void dfs(int v, int p) { static int TIME = 0; tin[v] = TIME++; tup[v] = tin[v]; used[v] = true; ... |
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 9; const int MAXN = 100005; struct disj { int pa[MAXN], sz[MAXN]; void init(int n) { for (int i = 0; i <= n; i++) { pa[i] = i; sz[i] = 1; } } int find(int x) { return pa[x] = (pa[x] == x ? x : find(pa... |
#include <bits/stdc++.h> using namespace std; struct Node { int x, t, whe, s, s2; } a[100100]; int n, t_cnt, V, ans, ans2, Mint = (1 << 30); int f[100100], f2[100100], Max[100100 * 4], Max2[100100 * 4]; bool cmp(Node x, Node y) { return x.s > y.s || (x.s == y.s && x.s2 < y.s2); } bool cmp2(Node x, Nod... |
#include <bits/stdc++.h> using namespace std; bool chmin(int64_t& a, const int64_t& b) { return b < a ? a = b, 1 : 0; } bool chmax(int64_t& a, const int64_t& b) { return a < b ? a = b, 1 : 0; } constexpr int pct(int x) { return __builtin_popcount(x); } constexpr int bits(int x) { return 31 - __builtin_clz(x);... |
#include <bits/stdc++.h> using namespace std; const int mod = 998244353; inline int add(int a, int b) { return a + b < mod ? a + b : a + b - mod; } inline int mul(int a, int b) { return int(1LL * a * b % mod); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int n; cin >> n; ... |
#include <bits/stdc++.h> using namespace std; int a[100001]; vector<int> v[100001]; int it = 1; long double e[100001]; int dfs(const int i) { a[i] = 1; for (int j : v[i]) { int p = dfs(j); a[i] += p; } return a[i]; } void dfs2(int i, long double t) { e[i] = t; for (in... |
#include <bits/stdc++.h> using namespace std; const int N = (int)3e6 + 11; using ll = long long; ll cnt[N]; ll pre[N]; int main() { int n; scanf( %d , &n); for (int i = 0; i < n; i++) { int x; scanf( %d , &x); cnt[x]++; } for (int i = 1; i < N; i++) for (int j = 1... |
#include <bits/stdc++.h> using namespace std; int n, q; long long m, w[100000]; vector<long long> phiChain; long long modPow(long long a, long long p, long long mod) { return (p ? modPow((a * a) % mod, p / 2, mod) * ((p & 1) ? a : 1) : 1) % mod; } long long phi(long long x) { long long temp = x; ... |
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; string s; cin >> s; string ans = ; int cnt = 0; for (int i = n - 1; i >= 0; i--) { if (s[i] == 1 ) { if (cnt > 0) { while (i >= 0 && s[i] == 1 ) i--; cnt = 1; i++... |
#include <bits/stdc++.h> using namespace std; int a[300005], b[300005]; int main() { int i, k, t, x, y, n, q, num1, num2; string s; scanf( %d , &t); for (i = 0; i < t; i++) { scanf( %d %d , &n, &q); cin >> s; s = + s; for (k = 0; k <= n; k++) a[k] = b[k] = 0; if (... |
#include <bits/stdc++.h> using namespace std; const long long MOD = (long long)1e9 + 7; const long double PI = 3.141592653589793238462643383279502884197; priority_queue<int, vector<int>, greater<int> > pq; vector<int> v; char s[300001]; int main() { int n; scanf( %d , &n); scanf( %s , s); ... |
#include <bits/stdc++.h> using namespace std; int vis[3010][3010]; int A[3010], canKill[3010], canNotKill[3010], n, k; queue<pair<int, int> > q; void insert(int i, int j, int t) { if (t > k) return; if (vis[i][j] == -1) { vis[i][j] = t; q.push(make_pair(i, j)); } } void killi(int i... |
#include <bits/stdc++.h> using namespace std; int32_t main() { double n, k; cin >> n >> k; cout << ((long long)ceil((2 * n) / k) + (long long)ceil((5 * n) / k) + (long long)ceil((8 * n) / k)); } |
#include <bits/stdc++.h> using namespace std; ifstream in; ofstream out; const long long kk = 1000; const long long ml = kk * kk; const long long mod = ml * kk + 7; const long long inf = ml * ml * ml + 7; const long long gs = 500 * kk; long n, m, i, j, k, ans; vector<long> reb[gs + 10]; set<long l... |
#include <bits/stdc++.h> using namespace std; void solve() { long long int n, i; cin >> n; vector<long long int> a(n), b, c; for (i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); for (i = 0; i < n; i++) { if (a[i] % 2 == 0) b.push_back(a[i]); else c.push_... |
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; long long POW(long long a, long long b, long long MMM = MOD) { long long ret = 1; for (; b; b >>= 1, a = (a * a) % MMM) if (b & 1) ret = (ret * a) % MMM; return ret; } long long gcd(long long a, long long b) { return b... |
#include <bits/stdc++.h> #pragma GCC optimize( Ofast ) #pragma GCC target( avx ) #pragma GCC target( avx2 ) #pragma GCC target( fma ) namespace { const bool TEST_GEN = 0; const int K = 19, N = 1 << K; const double pi = std::acos(-1.0); struct Complex { double x, y; Complex(double x_ = 0, doubl... |
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { int n; string s; cin >> n; cin >> s; int l = 0, r = n - 1, x = 0, y = 0; while (s[l] == < ) { l++; x++; } while (s[r] == > ) { r--; ... |
#include <bits/stdc++.h> struct stack { char a[1000010]; int top; } st; void push(char val) { st.a[st.top++] = val; } int pop() { return st.a[--st.top]; } int empty() { return st.top == 0; } char s[1000010]; int main() { char t; int i, cnt = 0; gets(s); st.top = 0; for (i = 0; ... |
#include <bits/stdc++.h> using namespace std; int n; char c[5005]; int l[5005]; int r[5005]; int solve(int x) { int a = 0, b = 0; for (int i = 0; i < n; i++) { if (x < l[i] || x > r[i]) continue; else { if (c[i] == M ) a++; else b++; } ... |
#include <bits/stdc++.h> using namespace std; int main() { int n, m, i, j, sum = 0, x, y, b; cin >> n >> m; int a[n][m]; vector<pair<int, int>> v; for (i = 0; i < n; i++) { for (j = 0; j < m; j++) { cin >> a[i][j]; sum += a[i][j]; if (a[i][j] == 0) v.push_back(make_... |
#include <bits/stdc++.h> using namespace std; map<int, int> M; int n, cnt, a[5001], ans[5001]; int m, k, b[5001]; bool vis[10001], used[5001]; void init() { for (int i = 2; i < 10001; i++) { if (!vis[i]) { for (int j = i + i; j < 10001; j += i) { vis[j] = true; } ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.