solution
stringlengths
53
181k
difficulty
int64
0
27
#include <bits/stdc++.h> using namespace std; void swapp(int &a, int &b); double fabss(double a); int maxx(int a, int b); int minn(int a, int b); int Del_bit_1(int n); int lowbit(int n); int abss(int a); const double E = 2.718281828; const double PI = acos(-1.0); const double ESP = 1e-6; const int inf = 0x7fffffff; con...
7
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return b == 0 ? a : gcd(b, a % b); } const double PI = 3.1415926535897932; const double EPS = 1e-10; const int INF = 0x3f3f3f3f; const int maxn = 1e3 + 100; const int hashmaxn = 8388608; int lowbit(int x) { return x & ...
12
#include<bits/stdc++.h> #define INF 0x3f3f3f3f #define inf 0x7FFFFFFF #define LL long long #define endl '\n' using namespace std; long long read(){ long long q=0,w=1; char ch=getchar(); while(ch>'9' || ch<'0'){if(ch=='-')w=-1;ch=getchar();} while(ch>='0'&&ch<='9'){q=q*10+(ch-'0');ch=getchar();} return q*w; } void ...
8
#include <bits/stdc++.h> using namespace std; string s1, s2, s; int up; int main() { cin >> s1; cin >> s2; cin >> s; for (int i = 0; i < s.size(); ++i) { up = 0; char c; if (s[i] < 'A') { printf("%c", s[i]); continue; } if (s[i] < 'a') up = 1, s[i] += 32; for (int j = 0; j < ...
0
#include <bits/stdc++.h> using namespace std; char BUFFER[100000 + 5]; bool readn(int &n) { return scanf("%d", &n) == 1; } bool readl(long long &n) { return scanf("%I64d", &n) == 1; } bool readd(double &n) { return scanf("%lf", &n) == 1; } bool reads(string &s) { s = ""; int n = scanf("%s", BUFFER); if (n == 1) s...
18
#include <bits/stdc++.h> namespace Helper { using LL = long long; const int MAXN = 1e5 + 1; const int MOD = 1e9 + 7; const LL INF = 1e18 * 1LL; template <typename T> void PrintVector(std::vector<T> v) { for (typename std::vector<T>::iterator it = v.begin(); it != v.end(); it++) { std::cout << *it << " "; } } au...
7
#include <bits/stdc++.h> using namespace std; int main() { long long int t, i, j, n, k, mx; mx = 1000000000LL; cin >> n >> k; t = (n * (n - 1)) / 2; if (t <= k) { cout << "no solution"; } else { for (i = 0; i < n - 1; i++) { cout << "0 " << i << "\n"; } cout << mx << " " << mx; } r...
5
#include <bits/stdc++.h> using namespace std; void dbg() { std::cout << " #\n"; } template <typename T, typename... Args> void dbg(T a, Args... args) { std::cout << a << ' '; dbg(args...); } const long long maxn = 2e5 + 10; const long long MAX = 1000; const long long inf = 0x3f3f3f3f; const long long mod = 9982443...
18
#include <bits/stdc++.h> using namespace std; using ll = long long; constexpr ll mod = 1e9 + 7; int main() { ios::sync_with_stdio(0); cin.tie(0); int TT = 1; cin >> TT; while (TT--) { ll n; cin >> n; vector<array<ll, 3>> A(n); for (ll i = 0; i < n; ++i) { cin >> A[i][0] >> A[i][1]; ...
15
#include <bits/stdc++.h> using namespace std; vector<int> grundy; int main() { for (int x = 0;; x++) { for (int rep = 0; rep < (int)(x + 1); rep++) grundy.push_back(x); if (((int)(grundy).size()) > 60) break; } int n, ans = 0; scanf("%d", &n); while (n--) { int x; scanf("%d", &x); ans ^= g...
13
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1); const double eps = 1e-9; const int inf = 2000000000; const long long infLL = 9000000000000000000; inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; } inline long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % ...
22
#include <bits/stdc++.h> using namespace std; const int N = 5010; int a[N], p[N][N]; long long dp(int l, int r, int val) { if (r < l) return 0; int pos = p[l][r]; if (a[pos] == val) return dp(l, pos - 1, val) + dp(pos + 1, r, val); long long res = r - l + 1; res = min(res, dp(l, pos - 1, a[pos]) + dp(po...
14
#include <bits/stdc++.h> using namespace std; const int N = 4e5 + 1; vector<int> ve[N]; int num[N], maxson[N], down[N], up[N]; int n; void gmax(int& a, int b) { if (a < b) a = b; } void dfs(int x, int fa) { num[x] = 1; down[x] = maxson[x] = 0; for (int i = 0; i < ve[x].size(); i++) { int y = ve[x][i]; i...
15
#include <bits/stdc++.h> using namespace std; using lli = long long int; const int MOD = 1000000007; const int MOD1 = 998244353; const int maxn = 100010; const int lim = (int)1e9; vector<int> tank(1010, 0); vector<int> tap(1010, 0); vector<int> dia(1010, 0); vector<tuple<int, int, int> > v; void funRepeat(int tk, int t...
6
#include <bits/stdc++.h> using namespace std; const long long NR = 1e5 + 10, oo = 1e17 + 10, MOD1 = 1e9 + 7; const long double pi = 2 * acos(0.0); int t; long long n, k; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> t; while (t--) { cin >> n >> k; if (k <= n) { if (n %...
1
#include <bits/stdc++.h> using namespace std; const int B = 350, MX = 110005; long long add[B] = {}, sum[B] = {}; int id[MX] = {}; int cnt[MX][B] = {}; int c[MX] = {}; long long a[MX] = {}; bool h[MX] = {}; vector<int> g[MX] = {}; vector<int> t[MX] = {}; int n, m, q, k = 0; int main() { ios_base::sync_with_stdio(fals...
17
#include <bits/stdc++.h> using namespace std; const int N = int(3e5) + 12, mod = int(1e9) + 7; int a, b, c, d; long long get(long long a, long long b, long long d, long long k) { return (k + 1) * a - k * (k + 1) / 2 * d * b; } long long my(long long a, long long b, long long c, long long d) { if (a > b * c) return ...
13
#include <bits/stdc++.h> using namespace std; namespace output { void __(short x) { cout << x; } void __(unsigned x) { cout << x; } void __(int x) { cout << x; } void __(long long x) { cout << x; } void __(unsigned long long x) { cout << x; } void __(double x) { cout << x; } void __(long double x) { cout << x; } void _...
20
#include <bits/stdc++.h> using namespace std; const int nmax = 20; const int inf = 1e9 + 7; const int modulo = 1e9 + 7; const double linf = 1e36; int main() { long long n; scanf("%I64d", &n); long long ret = 3 * n * (n + 1) + 1; printf("%I64d\n", ret); return 0; }
3
#include <bits/stdc++.h> using namespace std; int main() { string s; getline(cin, s); int len = s.length(); int i = 0; int last_even = -1; bool flag = false; while (i < len) { if ((int(s[i]) - '0') % 2 == 0) { last_even = i; if (s[i] < s[len - 1]) { char c = s[i]; s[i] = s[...
5
#include <bits/stdc++.h> using namespace std; int main() { int n; int l, r, PR, PL; cin >> n >> l >> r >> PL >> PR; int ans = INT_MAX; int a[n + 1]; int PrefixSum[n + 1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } PrefixSum[0] = 0; for (int i = 1; i <= n; i++) PrefixSum[i] = PrefixSum[i - 1] ...
7
#include <bits/stdc++.h> #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #pragma GCC target("avx,avx2,fma") using namespace std; const int N = 1e5 + 7; const int INF = 1e9 + 7; vector<vector<long long> > a; vector<long long> rw, cl; int n, m; long long ans; priority_queue<long long> pq, e; int m...
12
#include <bits/stdc++.h> using namespace std; const int sz = 325; struct node { int b, r, i; }; bool cmp(node a, node b) { if (a.b != b.b) return a.b < b.b; return a.r < b.r; } node block[100005]; int a[100005], l[100005], r[100005], ans[100005]; int last[100005], pv[100005], nt[100005]; deque<int> dq[100005]; in...
19
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 10; long long a[N]; map<long long, long long> mp; signed main() { long long n, k, lst = 0, ans = 0; scanf("%lld%lld", &n, &k); long long mov = (1 << k) - 1; mp[0] = 1; for (long long i = 1; i <= n; i++) { scanf("%lld", &a[i]); lon...
11
#include <bits/stdc++.h> using namespace std; int uset[4000100], urank[4000100]; class m_Int { int a; }; list<int> lists[150010]; int u_find(int id) { if (uset[id] == id) return id; uset[id] = u_find(uset[id]); return uset[id]; } void u_union(int b, int a) { int aRoot = u_find(a), bRoot = u_find(b); if (ura...
9
#include <bits/stdc++.h> using namespace std; const int MaxN = 50 + 6.66; const int mod = 1e9 + 7; int dp[2][MaxN][MaxN]; int fact[MaxN]; int ifact[MaxN]; void add(int &x, int y) { x += y; if (x > mod) x -= mod; } void div2(int &x) { if (x % 2) x += mod; x /= 2; } void prep() { fact[0] = 1; for (int i = 1; ...
18
#include <bits/stdc++.h> using namespace std; namespace flyinthesky { bitset<7001> bs[100000 + 5], gg[7005], hh[7005]; int n, q, mu[7005], pri[7005], vis[7005], tot; void clean() { memset(vis, 0, sizeof vis), tot = 0; } int solve() { clean(); mu[1] = 1; for (int i = 2; i <= 7000; ++i) { if (!vis[i]) vis[i] = ...
17
#include <bits/stdc++.h> using namespace std; int f_max(int x, int y) { return x > y ? x : y; } int f_min(int x, int y) { return x < y ? x : y; } int f_abs(int x) { if (x > 0) return x; return -x; } void swap(int &x, int &y) { int t; t = x, x = y, y = t; } bool visit[2001][2001]; int mp[2001][2001][2]; int n, m...
16
#include <bits/stdc++.h> using namespace std; template <typename T> void chmax(T& a, const T& b) { if (a < b) a = b; } template <typename T> void chmin(T& a, const T& b) { if (b < a) a = b; } int N; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; vector<string> S(N); for (int i = (0); i < ...
0
#include <bits/stdc++.h> using namespace std; int main() { int n; int a[100000]; int sortorg[100000], sortinv[100000]; cin >> n; for (int i = 0; i < n; i++) { cin >> a[i]; sortorg[i] = a[i], sortinv[i] = a[i]; } sort(sortorg, sortorg + n); sort(sortinv, sortinv + n, greater<int>()); for (int i...
10
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { if (b == 0) { return a; } return gcd(b, a % b); } long long lcm(long long a, long long b) { return ((a * b) / gcd(a, b)); } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); ; long long n; cin >> n; ...
10
#include <bits/stdc++.h> using namespace std; int main() { int a; cin >> a; vector<int> b(a); vector<int> c(a - 1); vector<int> d(a - 2); for (int i = 0; i < b.size(); i++) { cin >> b[i]; } for (int i = 0; i < c.size(); i++) { cin >> c[i]; } for (int i = 0; i < d.size(); i++) { cin >> d[...
3
#include <bits/stdc++.h> int main() { int n = 0; int m = 0; scanf("%ld %ld", &n, &m); while (n--) { int s = 0; int f = 0; int t = 0; int salida = 0; scanf("%ld %ld %ld", &s, &f, &t); if (s == f) { salida = t; } else { long T = 2 * (m - 1); --s; --f; sali...
5
#include <bits/stdc++.h> using namespace std; const int N = 24; int id, pr[N], sum; int query(int x) { int res = 0; for (int i = 0; i < (1 << id); i++) { int num = 0, s = 1; for (int j = 0; j < id; j++) if (i >> j & 1) { num++; s *= pr[j + 1]; } if (num & 1) res -= x / ...
14
#include <bits/stdc++.h> using namespace std; long long n, m; long long a[1000007], b[1000007]; void mRead() { scanf("%I64d%I64d", &n, &m); int x; for (int i = 0; i < n; ++i) scanf("%I64d", &a[i]); for (int i = 0; i < m; ++i) scanf("%I64d", &b[i]); } long long mSolve() { mRead(); sort(a, a + n); for (int ...
5
#include <bits/stdc++.h> void solve(int x) { if (x == 3) puts("1"); if (x == 7) puts("1"); if (x == 15) puts("5"); if (x == 31) puts("1"); if (x == 63) puts("21"); if (x == 127) puts("1"); if (x == 255) puts("85"); if (x == 511) puts("73"); if (x == 1023) puts("341"); if (x == 2047) puts("89"); if...
7
#include <bits/stdc++.h> using namespace std; const int N = 8; int n, l[N] = {}, r[N] = {}; inline double lessp(int l, int r, int p) { if (p < l) return 0; if (p > r) return 1; return (p - l) * 1.0 / (r - l + 1); } inline double calc(int v) { double p1 = 1; for (int i = 1; i <= n; ++i) p1 *= lessp(l[i], r[i],...
12
#include <bits/stdc++.h> using namespace std; class QuickUnionFind { private: int size_; std::vector<int> g; std::vector<std::vector<int>> v; public: QuickUnionFind() : size_(0), g(std::vector<int>()), v(std::vector<std::vector<int>>()){}; QuickUnionFind(int size__) : size_(size__) { g.resize(siz...
13
#include <bits/stdc++.h> using namespace std; int main() { string s; cin >> s; string t; cin >> t; int beg = -1, end = -1; bool flag1 = true; bool flag2 = true; long int tlen = t.length(); long int slen = s.length(); int ind1 = 0, ind2 = slen - 1; for (int i = 0; i < tlen; ++i) { if (s[ind1] =...
6
#include <bits/stdc++.h> using namespace std; int n, a[110], sum1 = 0, sum2 = 0; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%d", &a[i]); if (a[i] < 0) sum2++; else if (a[i] == 0) sum1++; else printf("%d ", a[i]); } sort(a + 1, a + n + 1); for (int i =...
6
#include <bits/stdc++.h> using namespace std; typedef struct pt { long long x; long long y; }; typedef struct circ { long long r; pt p; }; int n, m, k; pt K[10000]; circ c[10000]; int region[10000]; vector<int> out[10000]; int dist[2000][2000]; bool use[4000]; bool inside(pt p1, circ c1) { return (p1.x - c1.p...
12
#include <bits/stdc++.h> using namespace std; vector<int> a[105]; int n, m, v[105]; void dfs(int s, int l) { v[s] = true; for (int i = 0; i < (int)a[s].size(); i++) if (v[a[s][i]] == 0 && a[s][i] != l) dfs(a[s][i], s); } int main() { cin >> n >> m; int x, y; for (int i = 0; i < m; i++) { cin >> x >> y...
7
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:256000000") using namespace std; mt19937 ggen; inline long long add(long long a, long long b, long long m) { return (a + b) % m; } inline long long sub(long long a, long long b, long long m) { return ((a - b) % m + m) % m; } inline long long mul(long long a, ...
20
#include <bits/stdc++.h> using namespace std; const int mo = 1000000007; int n, m; char s[1005]; long long a[1005]; int f[1005][1005]; int main() { scanf("%d%d", &n, &m); for (int i = (int)(1); i <= (int)(m); i++) { scanf("%s", s + 1); for (int j = (int)(1); j <= (int)(n); j++) if (s[j] == '1') a[j] |...
17
/** * author: tourist * created: 13.03.2021 13:07:39 **/ #include <bits/stdc++.h> using namespace std; template <typename A, typename B> string to_string(pair<A, B> p); template <typename A, typename B, typename C> string to_string(tuple<A, B, C> p); template <typename A, typename B, typename C, typ...
25
#include <bits/stdc++.h> using namespace std; const long long N = 200005; template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << '(' << a.first << ", " << a.second << ')'; } template <class T> ostream &operator<<(ostream &os, const vector<T> &a) { os << '['; for (unsi...
23
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 9; int n, mem[200001][3]; int arr[200000]; vector<int> sets[200000]; vector<int> ids[200000]; int solve(int i, bool took) { if (i == n) return 0; if (mem[i][took] != -1) return mem[i][took]; int ret = 0; if (!took) ret = solve(i + 1, 0); for (i...
7
#include <bits/stdc++.h> using namespace std; int main() { long long n, i, s; long long a = 0, b = 0; cin >> n; for (i = 0; i < n; i++) { cin >> s; if (s == 1) a++; else b += a; } cout << b << endl; return 0; }
8
#include <bits/stdc++.h> using namespace std; int sg[100007]; int bestmove[100007]; int main() { sg[1] = 0; sg[2] = 0; int i, j, t; int n; scanf("%d", &n); set<int> s; int st, en; int h; for (i = 3; i <= n; i++) { s.clear(); for (j = 2; j * (j + 1) / 2 <= i; j++) { if ((2 * i) % j == 0) ...
12
#include <bits/stdc++.h> int main() { int a[5], i, sum = 0; for (i = 0; i < 5; i++) { scanf("%d", &a[i]); } for (i = 0; i < 5; i++) { sum = sum + a[i]; } if (sum % 5 == 0 && sum != 0) printf("%d", (sum / 5)); else printf("-1"); return 0; }
3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, i, a[N], st[N], w, b[N], bx; char op[N][9]; int main() { cin >> n; for (i = 1; i <= 2 * n; ++i) { cin >> op[i]; if (*op[i] == '-') cin >> a[i]; } for (i = 2 * n; i; --i) { if (*op[i] == '-') { if (w && a[i] > st[w]) { ...
9
#include<bits/stdc++.h> using namespace std; int main(){ int t; cin>>t; while(t--){ int n; cin>>n; map<int ,int>m; for(int i=0;i<n;i++){ int x; cin>>x; m[x]++; } priority_queue<pair<int,int>> q; for(auto i:m){ ...
6
#include <bits/stdc++.h> using namespace std; long long dp[1001][1001][2]; vector<long long> v(1001); bool is(long long i, long long n, long long cur, long long modd, bool empt) { if (cur == 0 && empt) { return 1; } if (i == n) return 0; if (dp[i][cur][empt] != -1) return dp[i][cur][empt]; dp[i][cur][empt...
11
#include <bits/stdc++.h> const long long mxn = 1e5 + 7; using namespace std; bool used[mxn]; vector<int> v; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, c, a[mxn]; cin >> n >> c; for (int i = 1; i <= n; i++) { cin >> a[i]; } long long cnt = 0; for (int i = 2; i ...
0
#include <bits/stdc++.h> using namespace std; const int MAXN = 1e3 + 51, MOD = 1e9 + 7; int x, y, res; int dp[MAXN][MAXN]; inline int read() { register int num = 0, neg = 1; register char ch = getchar(); while (!isdigit(ch) && ch != '-') { ch = getchar(); } if (ch == '-') { neg = -1; ch = getchar(...
8
#include <bits/stdc++.h> using namespace std; const int maxn = 3e3 + 7; int n, m; int d[maxn][maxn]; int inq[maxn]; vector<int> E[maxn]; vector<pair<int, int> > fi[maxn]; vector<pair<int, int> > se[maxn]; bool cmp(pair<int, int> x, pair<int, int> y) { if (x.first == y.first) return x.second > y.second; return x.fir...
12
#include <bits/stdc++.h> using namespace std; const long long max_n = 1e5 + 5; long long t, n, k; long long a[max_n]; bool flag; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin >> t; while (t--) { cin >> n >> k; flag = true; for (int i = 0; i < n; ++i) { cin...
12
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; namespace modular { const int mod = 998244353; inline int add(int a, int b) { a += b; while (a >= mod) a -= mod; while (a < 0) a += mod; return a; } inline void add_self(int& a, int b) { a = add(a, b);...
15
/** * author: chaitanya * created: 9:05:19 pm IST, 28 December 2020 **/ #include <bits/stdc++.h> using namespace std; #define intll 1 #define interactive 0 #ifdef chaitanya #include "/home/chaitanya/.templates/header.h" #else #define debug(x...) #endif #if !interactive #define IOS \ io...
16
#include <bits/stdc++.h> using namespace std; int main() { long long total; cin >> total; total -= 10; if (total == 10) { total = (4 * 3) + 3; } else if (total > 0) { if (total <= 11) { total = 4; } else { total = 0; } } if (total < 0) { total = 0; } cout << total << en...
0
#include <bits/stdc++.h> using namespace std; const int MAX = 123456; struct edge { int to, index; edge() {} edge(int to, int index) : to(to), index(index) {} }; int n, length[MAX]; long long useCount[MAX], allCount; double overall; vector<edge> to[MAX]; void input() { scanf("%d", &n); for (int i = 1; i <= n ...
11
#include <bits/stdc++.h> using namespace std; bool solve(int n, vector<int> targets, int nstep, bool print_solution = false) { const int m = targets.size(); set<pair<int, int>> rest_pos; for (int i = 0; i < m; ++i) if (targets[i] > 0) rest_pos.emplace(targets[i], i); vector<int> group_values(m, 0); vector...
23
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1024000000,1024000000") using namespace std; const int mod = (int)1e9 + 7; int n, m, k, BASE; int add[150010 * 4], mx[150010 * 4], b[150010], a[150010]; void get(int x, int l, int r) { if (l > r) return; int L = BASE + l - 1, R = BASE + r + 1; for (; (L ^ R...
18
#include <bits/stdc++.h> int main() { int n, p, q; scanf("%d", &n); scanf("%d", &p); int arr1[p]; for (int i = 0; i < p; i++) { scanf("%d", &arr1[i]); } scanf("%d", &q); int arr2[q]; for (int i = 0; i < q; i++) { scanf("%d", &arr2[i]); } int flag = 1, i; for (i = 1; i <= n; i++) { if...
0
#include <bits/stdc++.h> using namespace std; int main() { int t; scanf("%d", &t); for (int test = 0; test < t; test++) { int n; scanf("%d", &n); int time = 1; for (int i = 0; i < n; i++) { int l, r; scanf("%d %d", &l, &r); int alt = max(time, l); if (alt > r) { pri...
4
#include <bits/stdc++.h> using namespace std; struct node { long long sum; int mn; node() : sum(0), mn(2e9) {} node(long long sum, int mn) : sum(sum), mn(mn) {} }; node merge(node a, node b) { return node(a.sum + b.sum, min(a.mn, b.mn)); } struct STree { vector<node> st; vector<int> lazy; int n; STree(i...
18
#include <bits/stdc++.h> using namespace std; const int N = (int)1e4; int n, ans[N]; int Ask_Please(int a, int b) { cout << "? " << a << " " << b << '\n'; cout.flush(); cin >> a; return a; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n; int mx = 1; for (int i = 2; i <...
8
#include <bits/stdc++.h> using std::cin; using std::cout; using std::endl; using std::string; void __Check(bool condition, const char* expression, int line) { if (!condition) { fprintf(stderr, "Check failed at line %d: %s\n", line, expression); exit(-1); } } template <class Collection, class Key> bool Conta...
8
#include <bits/stdc++.h> using namespace std; inline int readint() { int x = 0; bool f = 0; char c = getchar(); while (!isdigit(c) && c != '-') c = getchar(); if (c == '-') { f = 1; c = getchar(); } while (isdigit(c)) { x = x * 10 + c - '0'; c = getchar(); } return f ? -x : x; } const ...
21
#include <bits/stdc++.h> using namespace std; const int N = 100500; const int INF = 1000000000, mod = 1000000009; const long long LLINF = 1000000000000000000ll; struct cube { int x, y, c; cube() {} cube(int x, int y, int c) : x(x), y(y), c(c) {} bool operator<(const cube &a) const { return c < a.c; } }; vector<...
13
#include <bits/stdc++.h> using namespace std; vector<int> prefix_function(string s) { int n = (int)s.length(); vector<int> pi(n); for (int i = 1; i < n; ++i) { int j = pi[i - 1]; while (j > 0 && s[i] != s[j]) j = pi[j - 1]; if (s[i] == s[j]) ++j; pi[i] = j; } return pi; } vector<int> z_functio...
9
#include <bits/stdc++.h> using namespace std; int m, n; int a[10005]; int c[200]; int ans; void dfs(int x, bitset<120> y, int now) { if (x > m / 2) { ans = (ans + now) % 1000000007; return; } dfs(x + 1, y, now); if (c[x] && !y[x]) { dfs(x + 1, y | y >> x | y << m - x | y << x | y >> m - x, 1...
21
#include <bits/stdc++.h> using namespace std; vector<int> arr[100005]; int vis[100005]; vector<int> v; double res = 0.000000000000; void dfs(int node, int dis, double factor) { vis[node] = 1; bool leaf = 1; int x = 0; for (int i = 0; i < arr[node].size(); i++) { if (!vis[arr[node][i]]) { x += 1; }...
7
#include <bits/stdc++.h> using namespace std; const int MAX_N = 1e6 + 47; int n, k; vector<vector<int>> g(MAX_N); int used[MAX_N]; multiset<int> s[MAX_N]; void solve(int u, int val) { used[u] = 1; bool f = g[u].size() == 1; for (auto v : g[u]) { if (f) { s[u].insert(val); break; } if (used...
16
#include <bits/stdc++.h> using namespace std; const int MAXN = 100005; vector<int> op[MAXN], cl[MAXN]; int l[MAXN], r[MAXN]; int a[MAXN]; int val[MAXN]; int n, m; int t[MAXN * 4]; int tsize; int getAnd(int l, int r) { l += tsize; r += tsize; int res = (1 << 30) - 1; while (l <= r) { if (l & 1) res &= t[l++]...
10
#include <bits/stdc++.h> using namespace std; void getre() { int x = 0; printf("%d\n", 1 / x); } void gettle() { int res = 1; while (1) res <<= 1; printf("%d\n", res); } template <typename T, typename S> inline bool upmin(T &a, const S &b) { return a > b ? a = b, 1 : 0; } template <typename T, typename S> i...
17
#include <bits/stdc++.h> using namespace std; map<int, int> a, b; int main() { int n, m, k, v; scanf("%d %d %d", &n, &m, &k); for (int i = 0; i < n; i++) { scanf("%d", &v); if (a.count(v) == 0) a[v] = 0; a[v]++; } for (int i = 0; i < m; i++) { scanf("%d", &v); if (b.count(v) == 0) b[v] = 0...
8
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; map<long long, long long> x; map<long long, long long> y; map<pair<long long, long long>, long long> same; long long X, Y; for (int i = 0; i < n; ++i) { cin >> X >> Y; ...
6
#include <bits/stdc++.h> using namespace std; map<long long, long long> dic; vector<long long> v; int main() { ios::sync_with_stdio(false); cin.tie(0); long long a, b, k; cin >> a >> b >> k; long long num = 720720; long long cnt = 0; dic[a % num] = cnt; v.push_back(a); long long cl, cv; while (1) { ...
12
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include "bits/stdc++.h" // #include <ext/rope> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> using namespace ...
4
#include <bits/stdc++.h> using namespace std; int main() { long long n; cin >> n; vector<pair<long long int, long long int> > v; for (long long i = 3; i <= n; i++) { v.push_back(make_pair(i, i - 1)); } long long ans = 0; for (auto it : v) { ans += (it.first * it.second); } cout << ans << endl;...
4
#include <bits/stdc++.h> using namespace std; set<pair<pair<int, int>, int> > s; pair<pair<int, int>, int> a[100005]; int ans[100005]; int main() { int n, m; cin >> n >> m; for (int i = 0; i < n; i++) { cin >> a[i].first.first >> a[i].first.second; a[i].second = i; } sort(a, a + n); int t = 0; for...
7
#include <bits/stdc++.h> using namespace std; const int maxn = 15e4; bool visa[maxn + 10], visb[maxn + 10]; int n, cnta[30], cntb[30], posa[30][maxn + 10], posb[30][maxn + 10]; char a[maxn + 10], b[maxn + 10]; int main() { scanf("%d%s%s", &n, a, b); for (int i = 0; i < n; ++i) { if (a[i] == '?') posa[0][+...
7
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 5; const long long MAX = 1e6; const long long logN = (long long)ceil(log2(MAX)); long long T[4 * N][25][2], lazy[4 * N][25]; long long n; long long a[N]; void build(long long node, long long l, long long r, long long bit) { if (l == r) { T[no...
12
#include <bits/stdc++.h> using namespace std; int min(int x, int y) { if (x < y) return x; else return y; } int max(int x, int y) { if (x > y) return x; else return y; } int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } for (int i = 0; i < n - 1...
6
#include <bits/stdc++.h> using namespace std; const int inf = ~0u >> 1, mod = 1e9 + 7; inline int rd() { int x, c, f = 1; while (!isdigit(c = getchar())) f = c != '-'; x = c - '0'; while (isdigit(c = getchar())) x = x * 10 + c - '0'; return f ? x : -x; } int main() { string x; cin >> x; cout << x; rev...
0
#include <bits/stdc++.h> using namespace std; unordered_map<int, int> p, x; int find(int u) { auto it = p.find(u); if (it == p.end()) { x[u] = 0; return u; } int v = it->second, vv = find(v); x[u] ^= x[v]; return p[u] = vv; } void unite(int u, int v, int val) { int a = find(u), b = find(v); if (...
16
#include <bits/stdc++.h> using namespace std; const int p = 1e9 + 7, maxn = 100050, maxm = 105, maxb = 17; int n, m, i, j, u, v, w, tot, dep[maxm], dp2[maxm][55][2], g[55][2]; int dp[1 << maxb], pd[1 << maxb], bc[1 << maxb], K, LK, use[maxm]; map<int, int> mpx, mpy; long long f[maxn], as[maxm], tas[maxm], ans; int pt[m...
23
#include <bits/stdc++.h> #pragma target("avx") #pragma optimize("O3") #pragma optimize("unroll-loops") constexpr int INF = INT_MAX / 2; constexpr long long LINF = LLONG_MAX / 2; constexpr double eps = 1e-9; constexpr double PI = 3.141592653589793238462643383279; template <class T> class prique : public std::priority_qu...
18
#include <bits/stdc++.h> using namespace std; const int INF = 0x3F3F3F3F; const int NEGINF = 0xC0C0C0C0; const double EPS = 1e-8; int cmp_double(double a, double b, double eps = 1e-9) { return a + eps > b ? b + eps > a ? 0 : 1 : -1; } inline void scanint(int& x) { register int c = getchar(); x = 0; int neg = 0;...
2
#include <bits/stdc++.h> using namespace std; int main(void) { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int t, n, input; bool flag; vector<int> student; vector<int> day_count; cin >> t; while (t--) { flag = false; cin >> n; if (n % 2 == 1) { cout << "NO\n"; co...
2
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = 1LL << 62; const long long mx = 100005; const double eps = 1e-10; long long dx[10] = {1, 0, -1, 0}; long long dy[10] = {0, -1, 0, 1}; long long power(long long a, long long b) { if (b == 0) return 1; long long x = ...
9
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18, mod = 1e9 + 7, N = 1e5, MAXX = 1e6 + 1000; long long fact[MAXX]; long long bpow(long long a, long long n) { long long ans = 1; while (n) { if (n % 2) { ans *= a; ans %= mod; n--; } else { a *= a; a %= mod...
12
#include <bits/stdc++.h> using namespace std; int i, n, m, x, y, X[120000], Y[120000], bo[5], px[120000], py[120000]; long long ans; double xx, yy; int main() { scanf("%d", &n); for (i = 1; i <= n; ++i) scanf("%d%d", &x, &y), X[i] = x, Y[i] = y, px[i] = x, py[i] = y; sort(X + 1, X + n + 1); sort(Y + 1, Y + ...
23
#include <bits/stdc++.h> using namespace std; const int N = 1000050; int n, m; int nex[N], to[N], head[N], tot = 0, color[N]; void add(int x, int y) { to[++tot] = y; nex[tot] = head[x]; head[x] = tot; } struct node { int x, c; bool operator<(const node& b) const { return c < b.c; } } a[N]; int main() { ios:...
9
#include <bits/stdc++.h> using namespace std; const int MX = 200005; long long N, M, mod = 1e9 + 7; long long seg(long long x) { long long a = x, b = x + 1; if (a % 2) b /= 2; else a /= 2; a %= mod; b %= mod; return (a * b) % mod; } int main() { long long ans, a, b, sa, sb; cin >> a >> b; sa =...
8
#include <bits/stdc++.h> using namespace std; long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } long long int modInverse(long long int n, long long ...
7
#include <bits/stdc++.h> using namespace std; using LL = long long; const int N = 5e5 + 10; LL a[N], c[N]; bool check(int n, int r, LL k, LL m) { memset(c, 0, sizeof c); for (int i = 1; i <= n; i++) { int lx = max(i - r, 1), rx = min(n + 1, i + r + 1); c[lx] += a[i]; c[rx] -= a[i]; } for (int i = 1;...
12
#include <bits/stdc++.h> using namespace std; int main() { string str, dot = "dot", at = "at"; cin >> str; int n = str.size(); int pos = -1; vector<int> p1, p2; bool ok = true; while (ok) { pos = str.find(dot, pos + 1); if (pos == -1) break; else p1.push_back(pos); } for (int i...
5
#include <bits/stdc++.h> using namespace std; const long long MOD = 1000000007; const int M = 60; int m; void mul(int a[][M], int b[][M]) { static int ret[M][M]; for (int i = 0; i < m; ++i) for (int j = 0; j < m; ++j) { ret[i][j] = 0; for (int k = 0; k < m; ++k) ret[i][j] = (ret[i][j] + (lon...
11