solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; vector<pair<int, pair<int, int> > > records; void construct(vector<vector<int> >& grid, int n) { if (n == 1) return; int emp = -1; for (int i = n - 1; i >= 0; i--) { if (emp != -1) break; for (int j = 0; j < n; j++) { if (grid[j][i]) break; if (j =...
13
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:16777216") using namespace std; using namespace std; double const PI = acos(-1.0); double const EPS = 1e-7; int a[100100]; int b[100100]; int brute(int n, int h) { int res = 1000000000; for (int i = 0; i < (1 << n); i++) { vector<int> A, B; int MAX = ...
10
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); map<int, int> m; int n; cin >> n; m[-1] = -1; m[int(1e9 + 3)] = -1; for (int i = (0); i < (n); i++) { int x; cin >> x; if (i == 0) { m[x] = 0; continue; } auto p = m.lower_bound(x); ...
10
#include <bits/stdc++.h> using namespace std; const int maxn = 5e5 + 50; const int mod = 1e9 + 7; long long qp(long long a, long long n) { long long res = 1; while (n > 0) { if (n & 1) res = res * a % mod; a = a * a % mod; n >>= 1; } return res; } template <class T> inline bool scan(T &ret) { char...
13
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > a; int h, q; long long cl, cr; int main() { scanf("%d%d", &h, &q); cl = 1ll << (h - 1); cr = (cl << 1) - 1; while (q--) { int i, ans; long long l, r; scanf("%d%I64d%I64d%d", &i, &l, &r, &ans); l = l << (h - i); ...
15
#include <bits/stdc++.h> using namespace std; const int N = 305; string mat[N]; bool is_diagonal[N][N]; int n; int main() { char cmp1, cmp2; bool is1 = true; bool is2 = true; cin >> n; for (int i = 0; i < n; i++) { cin >> mat[i]; } cmp1 = mat[0][0]; cmp2 = mat[0][1]; for (int i = 0; i < n; i++) { ...
2
#include <bits/stdc++.h> using namespace std; long long int findmin(long long int a, long long int b) { if (a < b) return a; return b; } long long int findmax(long long int a, long long int b) { if (a > b) return a; return b; } long long int fast_pow(long long int base, long long int exp) { if (exp == 0) retu...
5
#include <bits/stdc++.h> int a[200100]; int main() { int t; scanf("%d", &t); while (t--) { int n; scanf("%d", &n); int flag = 1, f = 0; for (int i = 0; i < n; i++) { scanf("%d", &a[i]); if (i && a[i] != a[i - 1]) flag = 0; else if (i) f = i; } if (flag) { ...
10
#include <bits/stdc++.h> using namespace std; vector<long long> dp(1000001, 0LL); long long n; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; long long arr[n + 1]; for (long long i = 1; i <= n; i++) { cin >> arr[i]; dp[arr[i]]++; } for (long long i = 1; i < 1000001 - 1; i+...
7
#include <bits/stdc++.h> #pragma GCC optimize("Ofast,unroll-loops") #pragma GCC target( \ "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") using namespace std; void itval(istream_iterator<string> it) {} template <typename T, typename... Args> void itval(istream_iterator<string> it, T a, Args... args)...
11
#include <bits/stdc++.h> using namespace std; const int inf = 1000 * 1000 * 1000; vector<string> pref; vector<string> st; int n, m; int dp[1 << 10][11][1 << 7]; int fp[1 << 7][4]; const int MOD = inf + 9; const string s = "ACGT"; int findp(int p, int c) { if (fp[p][c] == inf) { fp[p][c] = -1; int res = -1; ...
17
#include <bits/stdc++.h> using namespace std; template <typename T> class graph { public: struct edge { int from; int to; T cost; }; vector<edge> edges; vector<vector<int> > g; int n; graph(int n) : n(n) { g.resize(n); } virtual int add(int from, int to, T cost) = 0; }; template <typename T> ...
19
#include <bits/stdc++.h> using namespace std; const int Inf = 100000000; int n, dp[105][55][2]; char s[105]; int main() { scanf("%s%d", s, &n); int m = strlen(s); for (int i = 0; i <= m; i++) for (int j = 0; j <= n; j++) dp[i][j][0] = dp[i][j][1] = -Inf; dp[0][0][0] = dp[0][0][1] = 0; for (int i = 0; i < ...
10
#include <bits/stdc++.h> using namespace std; const long long fuck = 499122177; const long long Mod = 998244353; long long pow_mod(long long a, long long n, long long m) { long long ans = 1LL; while (n) { if (n & 1LL) { ans = (ans * a) % m; } a = (a * a) % m; n >>= 1LL; } return ans; } int...
13
#include <bits/stdc++.h> using namespace std; int main() { int n, l, v1, v2, k; cin >> n >> l >> v1 >> v2 >> k; int g = (n + k - 1) / k; if (g == 1) { long double ans = (l + 0.0) / v2; cout << fixed << setprecision(10) << ans << endl; return 0; } long double d2 = (v1 + v2 + 0.0) / ((2 * g - 1) *...
11
#include <bits/stdc++.h> using namespace std; bool comp(const pair<int, int> &a, const pair<int, int> &b) { if (a.first == b.first) return a.second < b.second; return a.first < b.first; } int asum(long long int a[], long long int n) { long long int sum = 0; for (long long int i = 0; i < n; i++) sum += a[i]; r...
0
#include <bits/stdc++.h> using namespace std; int t, n, k, A[1000000]; vector<int> Less, Greater; bool Check(int Val) { Less.clear(); Greater.clear(); for (int i = 1; i <= n; i++) if (A[i] <= Val) Less.push_back(i); else Greater.push_back(i); if (Less.size() == 0) return false; if (Less.si...
12
#include <bits/stdc++.h> using namespace std; map<int, int> A[110000]; int n, m, now, gox, goy, k1, k2; char ch[10]; int main() { scanf("%d%d", &n, &m); scanf("%d%d", &k1, &k2); scanf("%s", ch + 1); gox = 1; goy = 1; if (ch[1] == 'U') gox = -1; if (ch[2] == 'L') goy = -1; int rem = n + m - 2, ti = 0; ...
17
#include <bits/stdc++.h> using namespace std; const long long INF(0x3f3f3f3f3f3f3f3fll); const int inf(0x3f3f3f3f); namespace Polynomial { const long long P = 998244353, g = 3, gi = 332748118; static int rev[1000]; int lim, bit; long long add(long long a, long long b) { return (a += b) >= P ? a - P : a; } long long qpo...
2
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, m, k; cin >> n >> m >> k; vector<int> a(n), offer(k + 1); for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < m; i++) { int x, y; cin >> x >> y; if (x <...
13
#include <bits/stdc++.h> using namespace std; const int N = 5e4 + 5; const long long mod = 1e9 + 7; long long ct[105][105]; long long tp[105][105]; long long dp[105]; long long temp[105]; int num[10]; struct matrix { long long a[105][105]; }; matrix t, e; int x, b; matrix multi(matrix A, matrix B) { matrix C; for...
12
#include <bits/stdc++.h> using namespace std; long long n, m; long long arr[300005][10]; long long mask[1 << 10]; pair<long long int, long long int> check(long long x) { pair<long long int, long long int> p = {-1, -1}; memset(mask, -1, sizeof(mask)); for (long long int i = 1; i < n + 1; i++) { long long c = 0...
12
#include <bits/stdc++.h> using namespace std; int n, i, j, inv_old, inv_new, ans; int a[2048]; int main() { srand(time(0)); ios_base::sync_with_stdio(0); cin >> n; for (int i = 1; i <= n; i++) cin >> a[i], a[i] = abs(a[i]); for (int i = 1; i <= n; i++) { inv_old = 0; for (int j = 1; j <= n; j++) ...
14
#include <bits/stdc++.h> using namespace std; bool flag = true; const long long int N = 1e5 + 10; const long long int inf = 998244353; vector<long long int> adj[N], col(N); long long int color = -1; void dfs(long long int n, long long int par) { if (col[n] != color) flag = 0; for (auto it : adj[n]) { if (it != ...
8
#include <bits/stdc++.h> using namespace std; int64_t A, B, C, S, V; int N, T; int64_t P[80]; int M[80]; void dfsB(int64_t a, int pIdx, int64_t b) { if (b * b * a > V) return; if (pIdx >= N) { int64_t curS = 0; curS = a * b + V / a + V / b; if (curS < S) { S = curS; A = a; B = b; ...
21
#include <bits/stdc++.h> using namespace std; long long arr[4][200009]; map<pair<long long, long long>, vector<int> > a; int main() { long long n; cin >> n; vector<pair<pair<long long, long long>, int> > v; for (int f = 1; f <= n; f++) { cin >> arr[0][f] >> arr[1][f]; a[make_pair(arr[0][f], arr[1][f])]....
18
#include <bits/stdc++.h> using namespace std; int n, m, q; int arr[100005]; bitset<1005> full; bitset<1005> tree[400005]; int tag[400005]; vector<int> road[100005]; int id[100005], dfn[100005], las[100005], cnt; void dfs(int x, int pa) { id[++cnt] = x; dfn[x] = cnt; for (int it : road[x]) if (it != pa) dfs(it...
20
#include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } sort((a).begin(), (a).end()); a.erase(unique((a).begin(), (a).end()), a.end()); for (int i = 0; i + 1 < a.size(); i++) { if (a[i] == 1) continue; if (!...
6
#include <bits/stdc++.h> int a, b, c, d, e, f; int main() { scanf("%d%d%d%d%d%d", &a, &b, &c, &d, &e, &f); puts(!a && b && d || !c && d || b * d * f > a * c * e ? "Ron" : "Hermione"); }
10
#include <bits/stdc++.h> using namespace std; map<int, int> mp; map<int, int>::iterator it; int main() { int n, x, a[5], cnt = 0, flag = 0, max = -1; cin >> n; for (int i = 0; i < n; i++) { cin >> x; if (mp[x] == 0) { cnt++; mp[x] = 1; } else mp[x]++; if (mp[x] > max) { max...
2
#include <bits/stdc++.h> using namespace std; int mask[100100]; int maskc[1 << 6]; int chc[10]; const int ss = 75, tt = 76; const int N = 100; struct Edge { int v, r; long long f, c, p; }; vector<Edge> adj[N]; int sz[N]; long long mc; vector<Edge> mcf_edges; void init(int n = N) { mc = 0; fill(sz, sz + n, 0); ...
16
#include <bits/stdc++.h> using namespace std; const long long P = 1000 * 1000 * 1000 + 7; int main() { long long a, b, res = 0; scanf("%I64d%I64d", &a, &b); long long l = ((b % 2 ? b : b / 2) * (b % 2 ? (b - 1) / 2 : (b - 1))) % P; long long r = ((a % 2 ? a : a / 2) * (a % 2 ? (a + 1) / 2 : (a + 1))) % P; r *...
8
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; if (n < 4) { cout << "NO"; return 0; } cout << "YES\n"; if (n % 2 == 0) { cout << "1 * 2 = 2\n2 * 3 = 6\n6 * 4 = 24\n"; for (int i = 6; i <= n; i += 2) { cout << i << " - " << i - 1 << " = 1\n"; } for (...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const int mod = 998244353; int n, k, tot1, tot2; long long a[maxn], b[maxn]; long long solve(long long *a, int len) { if (len == 1) if (a[1] == -1) return k; else return 1; long long s = 1, d = 0, res = 1; long long ls = ...
14
#include <bits/stdc++.h> using namespace std; const int maxn = 1000009; int n; int beginp, anst, anssum; int sum[maxn]; int s, t, l; int main() { scanf("%d", &n); for (int i = 1; i <= n; ++i) scanf("%d", &sum[i]); for (int i = n + 1; i <= n + n; ++i) sum[i] = sum[i - n]; for (int i = 2; i <= n + n; ++i) sum[i] ...
8
#include <bits/stdc++.h> using namespace std; const int N = 100005; int n, m, vis[N], du[N]; vector<int> a[N], b[N]; queue<int> q; int dfs(int x) { vis[x] = 1; int ans = 1; if (du[x] == 0) q.push(x); for (int i = 0; i < a[x].size(); i++) if (!vis[a[x][i]]) ans += dfs(a[x][i]); return ans; } int main() { ...
14
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; long long n; string s[N]; vector<long long> pos[30], adj[N]; bool vis[N]; void dfs(long long v) { vis[v] = true; for (auto u : adj[v]) { if (!vis[u]) dfs(u); } } signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ...
7
#include <bits/stdc++.h> using namespace std; const int INF = (1e9) + 10; const long long 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 << 3ll) + (x << 1...
17
/* Priyansh Agarwal*/ #include<bits/stdc++.h> // #include<ext/pb_ds/assoc_container.hpp> // #include<ext/pb_ds/tree_policy.hpp> using namespace std; using namespace chrono; // using namespace __gnu_pbds; #define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define MOD 1000000007 #define MOD...
8
#include <bits/stdc++.h> using namespace std; const int N = 1e5, m1 = 1e9 + 7, m2 = 1e9 + 9; int a[N + 11], n, k; long long ans; int u; long long v; void gao(int o) { u = v = 1; int x, y; for (int i = 2; i * i <= o; ++i) { if (o % i == 0) { y = 0; while (o % i == 0) ++y, o /= i; y %= k; ...
10
#include <bits/stdc++.h> using namespace std; long long b_p(int a, int n) { long long p = 1; while (n > 0) { if (n % 2 == 0) { a *= a; n /= 2; } else { n--; p *= a; } } return p; } void solve() { int n, k; cin >> n >> k; char a[5][n + 10]; bool d[5][n + 10]; for (in...
9
#include <bits/stdc++.h> using namespace std; int main() { int a, b, n; while (scanf("%d%d%d", &n, &a, &b) != EOF) { if (a + 1 < n - b) { printf("%d\n", b + 1); } else { printf("%d\n", n - a); } } return 0; }
2
#include <bits/stdc++.h> using namespace std; const long long N = 5e5 + 5; long long n, m, k, a[N], ans = 1e18; struct edge { long long u, v, w, nxt; } e[N << 1], E[N]; long long cnt, head[N]; inline void add(long long u, long long v, long long w) { e[++cnt].u = u; e[cnt].v = v; e[cnt].w = w; e[cnt].nxt = hea...
18
#include <bits/stdc++.h> using namespace std; const double PI = 4 * atan(1); int N; int A[1000013], B[1000013]; string op[1000013]; bool val[1000013]; int ans[1000013]; bool apply(bool a, bool b, string op) { if (op[0] == 'A') return a & b; else if (op[0] == 'O') return a | b; else if (op[0] == 'X') r...
12
#include <bits/stdc++.h> using namespace std; int n; string a; int main() { scanf("%d", &n); while (n--) { cin >> a; int l = 0, i = 0; for (; i < a.size() - 1; i++) if (a[i] != a[i + 1]) l++; if (!l && a[i] == '0') printf("1\n"); else if (!l && a[i] == '1') printf("0\n"); e...
0
#include <bits/stdc++.h> using namespace std; const long long int N = 3 * 1e6 + 2; long long int n, k; int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); long long int x0, y0, ax, ay, bx, by; long long int xs, ys, t; cin >> x0 >> y0 >> ax >> ay >> bx >> by; cin >> xs >> ys >> t; vector<long long i...
9
#include <bits/stdc++.h> using namespace std; namespace INPUT { const int L = 1 << 20; char _buf[L], *S, *T, c; int len; char _gc() { if (S == T) { T = (S = _buf) + fread(_buf, 1, L, stdin); if (S == T) return EOF; } return *S++; } void Readi(int &x) { for (c = _gc(); c < '0' || c > '9'; c = _gc()) ...
8
#include <bits/stdc++.h> using namespace std; const int m = 1000000; int n; bool c[m]; int main() { ios_base::sync_with_stdio(false); cin >> n; for (int i = 0; i < n; ++i) { int x; cin >> x; c[x - 1] = true; } vector<int> ans; vector<pair<int, int> > gg; int q = 0; for (int i = 0; i < m; ++i...
9
#include <bits/stdc++.h> int main() { long long n, b; scanf("%I64d", &n); if (n <= 2) puts("-1"); else if (n & 1) { b = (n * n - 1) >> 1; printf("%I64d %I64d\n", b, b + 1); } else { b = ((n * n) >> 2) - 1; printf("%I64d %I64d\n", b, b + 2); } return 0; }
7
#include <bits/stdc++.h> using namespace std; int t, n; void mapp(int x) { if (x == 1 || x == 2) { for (int i = 1; i <= x; i++) { for (int j = 1; j <= x; j++) { cout << '1' << ' '; if (j == x) cout << endl; } } return; } if (x % 2 == 0) { for (int i = 1; i <= x; i++) ...
1
#include <bits/stdc++.h> #pragma GCC optimize("O2") #pragma GCC optimize("unroll-loops") using namespace std; const int MAX = 1e6 + 5; const long long MAX2 = 11; const long long MOD = 1000000000; const long long INF = 2e18; const int dr[] = {1, 0, -1, 0, 1, 1, -1, -1, 0}; const int dc[] = {0, 1, 0, -1, 1, -1, 1, -1, 0}...
18
#include <bits/stdc++.h> using namespace std; 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(nam...
9
#include <bits/stdc++.h> using namespace std; const int dx[4] = {1, 0, 0, -1}; const int dy[4] = {0, 1, -1, 0}; bool used[410][410], can[410][410]; pair<int, int> a[410], P[4], L, R, U, D; int p[100000], q[100000][4]; int Sx, Sy, Tx, Ty, n; bool BFS(void) { q[1][0] = Sx, q[1][1] = Sy, used[Sx][Sy] = true; for (int ...
23
#include <bits/stdc++.h> using namespace std; pair<pair<int, int>, int> P; long long s; int n, i, tmp; int main() { scanf("%d", &n); for (; i < n; i++) { scanf("%d", &tmp); s += tmp * 2 - (tmp > P.second ? P.second : tmp); if (tmp > P.first.second) { P.first.first = P.first.second; P.first.s...
17
#include <bits/stdc++.h> #define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) #define X first #define Y second #define nl '\n' #define AC return 0 #define pb(a) push_back(a) #define mst(a,b) memset(a, b, sizeof a) #define rep(i,n) for(int i = 0; (i)<(n); i++) #define rep1(i,n) for(int i = 1; (i)<=(n); i++) #de...
12
#include <bits/stdc++.h> using namespace std; void smain(); int main() { ios_base::sync_with_stdio(0); cout.precision(12); cout << fixed; smain(); return 0; } long long n; long long p[500000], sz[500000], ans[500000]; long long get_p(long long v) { return v == p[v] ? v : p[v] = get_p(p[v]); } vector<pair<long...
15
#include <bits/stdc++.h> using namespace std; inline int read() { register int x = 0, f = 1; register char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') f = 0; ch = getchar(); } while (isdigit(ch)) { x = x * 10 + (ch ^ '0'); ch = getchar(); } return f ? x : -x; } const int N = 51; ...
19
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; class fenvic { public: vector<int> second; int n; void init(int sz) { second.assign(sz + 3, 0); n = sz; } void upd(int v, int x) { while (v <= n) { second[v] += x; v = v | (v + 1); } } int sum(int v) { in...
12
#include <bits/stdc++.h> using namespace std; int N, M, K; int limit = 10000; int arr[10010]; char home_name[25], away_name[25]; int home_pl[110], away_pl[110]; int home_time[110], away_time[110]; void input() { cin >> home_name; cin >> away_name; cin >> N; int time, pl_num; char team, card; int i = 0; fo...
5
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:512000000") using namespace std; void solve(__attribute__((unused)) bool); void precalc(); clock_t start; int main() { start = clock(); int t = 1; cout.sync_with_stdio(0); cin.tie(0); precalc(); cout.precision(10); cout << fixed; int testNum = 1; ...
15
#include <bits/stdc++.h> const int N = 1e4 + 5; using namespace std; long long int ceil(long long int a, long long int b) { long long int res = (a + b - 1) / b; return res; } long long int str_to_num(string s) { return stoi(s); } long long int gcd(long long int a, long long int b) { if (b == 0) return a; return...
4
#include <bits/stdc++.h> using namespace std; long long power(long long a, long long b, long long m) { long long ret = 1; while (b) { if (b % 2) ret = ((ret % m) * (a % m)) % m; a = ((a % m) * (a % m)) % m; b /= 2; } return ret; } int main() { long long n, m; cin >> n >> m; bool row[n], col[n]...
4
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5, K = 55; int n, k; int a[N]; long long pre[N]; double inv[N], w[N]; double f[N][K]; int s[N][2], top[2]; double X(int u) { return pre[u]; } double Y(int u, int c) { return f[u][c] - w[u] + pre[u] * inv[u]; } double Slope(int u, int v, int c) { return...
16
#include <bits/stdc++.h> using namespace std; int main(int argc, char const* argv[]) { int arr[3]; cin >> arr[0] >> arr[1] >> arr[2]; sort(arr, arr + 3); int grow = (arr[0] + arr[0] + arr[1] - 2) * (arr[1] - 1); int const_part = (arr[0] + arr[1] - 1) * (arr[2] - arr[1] + 1); ; cout << grow + const_part <<...
4
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; for (int i = 0; i < t; i++) { string str; cin >> str; if (str.length() == 1) { cout << "-1" << endl; continue; } char ch = str[0]; int flag = 0; int l = str.length(); for (int i = 0; i < l; i++)...
1
#include <bits/stdc++.h> using namespace std; int IN() { int c, f, x; while (!isdigit(c = getchar()) && c != '-') ; c == '-' ? (f = 1, x = 0) : (f = 0, x = c - '0'); while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + c - '0'; return !f ? x : -x; } const int N = 100000 + 19; int Pow(int a, int b, int...
18
#include <bits/stdc++.h> using namespace std; int main() { long double EPS = 1e-10; long double y1, y2, yw, xb, yb, r; cin >> y1 >> y2 >> yw >> xb >> yb >> r; swap(y1, y2); yw -= r; long double y1m = yw * 2 - y1; long double y2m = yw * 2 - y2; long double xi = (y2m - y1m - r) / (y2m - yb - r) * xb; lo...
12
#include <bits/stdc++.h> using namespace std; int32_t main() { long long t; cin >> t; while (t--) { long long n; cin >> n; long long arr[n]; for (long long i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); long long ans = 1; for (long long i = n - 1; i >= n - 5; i--) { ans *=...
4
#include <bits/stdc++.h> using namespace std; long long a[35], b[35], k[35], p[35]; long long n, u, r, ans; void op1() { for (int i = 0; i < n; i++) a[i] = a[i] ^ b[i]; } void op2() { long long tmp[35]; for (int i = 0; i < n; i++) tmp[i] = a[p[i]] + r; for (int i = 0; i < n; i++) a[i] = tmp[i]; } void dfs(int t...
12
#include <bits/stdc++.h> using namespace std; void solve() { long long n, k, o = 0, tot = 0, f = 0; cin >> n >> k; char s[n]; long long i = 0; for (i = 0; i < n; i++) { cin >> s[i]; if (s[i] == '0') { if (i - o <= k) { char y = s[i]; s[i] = s[o]; s[o] = y; k -= i ...
7
#include <bits/stdc++.h> using namespace std; vector<int> topological_sort(vector<vector<int>> &ad) { int n = ad.size(); vector<int> res; vector<bool> jun(n, false); function<void(int)> dfs = [&](int cur) { if (jun[cur]) return; jun[cur] = true; for (int ch : ad[cur]) dfs(ch); res.push_back(cur)...
11
#include <bits/stdc++.h> using namespace std; long long vx[200005], vy[200005], x[200005]; set<long long> s; set<pair<long long, long long> > second; set<pair<long long, long long> >::iterator it2; map<pair<long long, long long>, long long> mp2; set<long long>::iterator it; map<long long, long long> mp; int32_t main() ...
12
#include <bits/stdc++.h> using namespace std; const int INF = 0x7fffffff; int Solution() { int n, k; cin >> n >> k; int now = 1; for (int i = 0; i < k; ++i) { for (int j = 1; j <= n - 2 * now; ++j) cout << j << ' '; for (int j = max(1, n - 2 * now + 1); j <= n - now; ++j) cout << j + now << ' '; ...
8
#include <bits/stdc++.h> using namespace std; const int MAX = 3e5 + 9, MOD = MAX; int n, m, k, p[MAX], v[MAX]; long long dist[MAX]; vector<int> tree[MAX]; vector<pair<int, long long>> adj[MAX]; vector<pair<int, int>> st; vector<pair<int, pair<int, int>>> ham[MOD]; int fh(int x, int y) { if (x > y) swap(x, y); retur...
10
#include <bits/stdc++.h> using namespace std; long long f[110] = {1, 2}; long long a1[1010], a2[1010], b1[1010], b2[1010]; int n, m; struct ios { inline char read() { static const int IN_LEN = 1 << 18 | 1; static char buf[IN_LEN], *s, *t; return (s == t) && (t = (s = buf) + fread(buf, 1, IN_LEN, stdin)), ...
18
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; string s; cin >> s; long long arr[10]; for (long long i = 0; i < 10; i++) { arr[i] = 0; } for (long long i = 0; i < n; i++) { if (s[i] == 'L') { for (long long j = 0; j < 10; j++) { if (arr[j] == 0) {...
0
#include <bits/stdc++.h> using namespace std; const int N = 50010; struct EXSAM_node { EXSAM_node *next[26], *pre; int step; int bel; int size; int visit; int cnt[11]; void clear() { pre = NULL; step = 0; size = 0; visit = 0; memset(next, 0, sizeof(next)); } }; EXSAM_node EXSAM_Pool[...
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int mat[n][n]; for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { int temp; cin >> temp; mat[i][j] = temp; } int array[1000]; int count = 0; for (int i = 0; i < n; i++) { int flag = 1; int ...
1
#include <bits/stdc++.h> using namespace std; int save[2005]; vector<int> cq[2005]; int main() { int n; scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &save[i]); cq[save[i]].push_back(i); } int forpc; int ans = 1; bool can = false; int fir = 0, sec = 0; for (int i = 1; i <= 2000; ...
5
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 10; int num[27]; int reduce[27]; int main() { ios::sync_with_stdio(false); int n, k; string str; cin >> n >> k; cin >> str; memset(num, 0, sizeof(num)); memset(reduce, 0, sizeof(reduce)); for (int i = 0; i < n; i++) { num[str[i] - ...
4
#include <bits/stdc++.h> using namespace std; template <class T> inline int size(const T &c) { return c.size(); } template <class T> inline int length(const T &c) { return c.length(); } template <class T> inline void RP(T &a) { cin >> a.first >> a.second; } void RI(int &a) { scanf("%d", &a); } void RI(int &a, int...
11
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } const int MAXN = 1000; const int MAXM = 30000; int n, m, s, t; int ghead[MAXN], gnxt[2 * MAXM], gto[2 * MAXM], gcost[MAXM]; bool dead[MAXM]; int calcidx; int d[MAXN], mind[MAXN], par[MAXN]; bool ...
18
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); long n, l, r, end = 0, ans = 0; cin >> n; pair<long, long> p[n]; for (long i = 0; i < n; i++) cin >> p[i].second >> p[i].first; sort(p, p + n); for (long i = 0; i < n; i++) { if (p[i].second > end) { ...
8
#include <bits/stdc++.h> using namespace std; int a, b, c, d, M, V; int main() { cin >> a >> b >> c >> d; M = max(3 * a / 10, a - (a / 250 * c)); V = max(3 * b / 10, b - (b / 250 * d)); if (M > V) cout << "Misha"; else if (V > M) cout << "Vasya"; if (M == V) cout << "Tie"; return 0; }
1
#include <bits/stdc++.h> using namespace std; struct has { long long int first, second; }; bool cmp(has a, has b) { if (a.first == b.first) { return a.second > b.second; } else { return a.first > b.first; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long int a, b,...
2
#include <bits/stdc++.h> using namespace std; const long long INF = (1LL << 60); struct SegmentTree { long long Tree[4 * 200007], Lazy[4 * 200007]; SegmentTree() {} void pushdown(int at) { if (Lazy[at]) { Lazy[(at << 1)] += Lazy[at]; Lazy[((at << 1) | 1)] += Lazy[at]; Tree[(at << 1)] += Lazy...
16
#include <bits/stdc++.h> using namespace std; const long long Inf = 1e18; long long mul(long long a, long long b, long long mod) { long long ret = 0; while (b) { if (b & 1) ret = (ret + a) % mod; a = (a + a) % mod, b >>= 1; } return ret; } int main() { long long a; cin >> a; long long l = a - mul(...
17
#include <bits/stdc++.h> using namespace std; int n; int main() { cin >> n; cout << "I hate "; for (int i = 2; i <= n; i++) { if (i % 2 == 0) cout << "that I love "; else cout << "that I hate "; } cout << "it" << endl; return 0; }
0
#include <bits/stdc++.h> using namespace std; 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()); long long req = n / 2; long long cnt = 0, i = 1; while (cnt < req) { cout << a[i] << " " << a[0] << endl; cnt++; i++;...
2
#include <bits/stdc++.h> using namespace std; const int maxN = 400 + 10; int n, m; vector<pair<int, int> > qu; bool vis1[maxN], vis2[maxN]; vector<int> G[maxN], Gp[maxN]; vector<int> et; int mol[maxN]; vector<vector<int> > anss; int javab; bool javabs[maxN]; int NOT(int a) { a = a - n; a *= -1; a = a + n; retur...
11
#include <iostream> #include <cstring> #include <cstdio> #include <cctype> #include <string> #include <cmath> #include <algorithm> #include <vector> #include <queue> #include <map> #include <list> #include <set> #include <stack> #include <tuple> using namespace std; #define Check(x) cout << "x:" << x << " " #define Mi...
6
#include <bits/stdc++.h> using namespace std; int n, m, q, ex[200005], ey[200005], bcc[200005], num; int tot = 1, fir[200005], nxt[200005 << 1], to[200005 << 1]; vector<int> G[200005]; inline void addE(int u, int v) { nxt[++tot] = fir[u], fir[u] = tot, to[tot] = v; } namespace T { int tme, dfn[200005], low[200005], b...
20
#include <bits/stdc++.h> using namespace std; int a[100005], b[100005]; int main() { cin.sync_with_stdio(false); cout.sync_with_stdio(false); int n, l, r; cin >> n >> l >> r; for (int i = 0; i < n; i++) cin >> a[i]; for (int i = 0; i < n; i++) cin >> b[i]; sort(a + l - 1, a + r); sort(b + l - 1, b + r);...
7
#include <bits/stdc++.h> using namespace std; constexpr int MOD = 1000000007; template <class T = int> T in() { T x; cin >> x; return (x); } template <class T = int> void out(T x) { cout << (x) << '\n'; } long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; } void solve() { int q = in(); ...
1
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long n; cin >> n; long long count = 0, a = 1, b = 10, c = 100, d = 1000, e = 10000; a *= (n % 10); n /= 10; b *= (n % 10); n /= 10; c ...
0
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long t; cin >> t; while (t--) { long long n; cin >> n; long long a[n]; vector<long long> v[n + 1]; for (long long i = 0; i < n; ++i) { cin >> a[i]; v[i + 1].pu...
7
#include <bits/stdc++.h> using namespace std; const int MAX = 100005; static vector<int> a; static int l[MAX]; static int r[MAX]; static vector<int> b; static vector<int> c; int bin(int x) { int lo = 0; int hi = c.size() - 1; while (lo <= hi) { int m = (lo + hi) / 2; if (c[m] <= x) { lo = m + 1; ...
6
#include <bits/stdc++.h> using namespace std; int n, cnt, curr; int G[200005]; int dfs(int u) { if (u == curr) return 1; int v = G[u]; return dfs(v) + 1; } void query() { cin >> n; for (int u = 1; u <= n; u++) { int v; cin >> G[u]; } for (curr = 1; curr <= n; curr++) { cout << dfs(G[curr]) << ...
2
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 + 7; pair<long long, long long> p[MAXN]; int n, res = 0; bool cw(pair<long long, long long> a, pair<long long, long long> b, pair<long long, long long> c) { return (b.first - a.first) * (c.second - b.second) - (c.first - b.first) ...
16
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const int N = 2e5 + 10; long long f[26][N][2], ff[26][N][2]; long long a[N][2]; pair<long long, long long> d[26], dd[26]; int n, m; pair<long long, long long> get(int sig, int l, int r) { return make_pair( (f[sig][r][0] - (f[sig][l - 1...
15