text
stringlengths
49
983k
#include <bits/stdc++.h> using namespace std; const int maxn = 6e5 + 7; int n, k; string s; int l[maxn][2], r[maxn], cnt[maxn]; int getroot(int x) { return r[x] == x ? x : r[x] = getroot(r[x]); } int calc(int x) { int y = x <= k ? x + k : x - k; x = getroot(x); y = getroot(y); if (x == 0 || y == 0) { return...
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 10; vector<int> g[maxn]; int f[maxn], d[maxn], L[maxn], R[maxn], fix[maxn], gt[maxn], ans = 0; int n, k; char str[maxn]; int calc(int x) { if (fix[x]) return gt[x] ? R[x] : L[x]; else return min(L[x], R[x]); } int find(int x) { if (f[x] ...
#include <bits/stdc++.h> using ll = long long; using namespace std; const int maxn = 6e5 + 5; int fa[maxn], val[maxn], ans; vector<int> V[maxn]; int n, k; string s; void init() { for (int i = 0; i < maxn; ++i) fa[i] = i; } int getfa(int x) { return x == fa[x] ? x : fa[x] = getfa(fa[x]); } void merge(int x, int y) { ...
#include <bits/stdc++.h> enum class LampConstraint { Distinct, Same }; enum class LampSetState { On, Off, PhantomA, PhantomB }; bool isLampSetStateKnown(LampSetState st) { return st == LampSetState::On || st == LampSetState::Off; } typedef struct Edge { int nodeId; LampConstraint cons; Edge(int nodeId_, LampCon...
#include <bits/stdc++.h> using namespace std; struct perem { int t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); int n, k, m, c, vas, vvas, cc = 1000000, kl; string s; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0); cin >> n >> k >> s; vector<vector<int>> la(n, v...
#include <bits/stdc++.h> using namespace std; struct DS { int n; vector<int> s; vector<int> count; DS(int n) : n(n), s(n, -1), count(n, 0) {} int find(int i) { return s[i] < 0 ? i : (s[i] = find(s[i])); } int counted(int i) { return count[find(i)]; } void mark(int i, int x) { count[find(i)] += x; } int ...
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const int inf = 0x3f3f3f3f; const int MAXN = 0x7fffffff; const long long INF = 0x3f3f3f3f3f3f3f3fLL; void file() {} const int N = 3e5 + 5; int fat[N * 2], Size[N * 2], n, k; vector<int> vec[N]; int find(int x) { return fat[x] == x ? x : fat[x] ...
#include <bits/stdc++.h> using namespace std; using pii = pair<int, int>; const int lim = 1000 * 1000 + 5; int nbElem, nbSub; vector<int> subset[lim]; int side[lim]; int isIn[lim][2]; string ini; int rep = 0; int drepr[lim]; int dsz[lim]; int cnt[lim][2]; int dfind(int x) { if (drepr[x] != x) drepr[x] = dfind(drepr[x...
#include <bits/stdc++.h> using namespace std; const int N = 6e5 + 5; int pre[N], si[N], num[N / 2], n, m; bool vis[N]; char s[N]; vector<vector<int> > v(N / 2); int findd(int x) { if (pre[x] == x) return x; pre[x] = findd(pre[x]); if (vis[x]) vis[pre[x]] = 1; return pre[x]; } inline int id(int x) { return x > m...
#include <bits/stdc++.h> using namespace std; const int maxn = 300005; int dp[maxn][2], fa[maxn * 2], cnt[maxn * 2], n, k; char buf[maxn]; int Find(int x) { return x == fa[x] ? x : fa[x] = Find(fa[x]); } int calc(int x) { int y; if (x <= k) y = x + k; else y = x - k; x = Find(x), y = Find(y); if (x ==...
#include <bits/stdc++.h> using namespace std; vector<int> v[600005]; int k; int mx[600005], a[300005], fa[600005]; int find(int x) { if (fa[x] != x) { fa[x] = find(fa[x]); } return fa[x]; } void mer(int x, int y) { int fx = find(x), fy = find(y); if (fx != fy) { mx[fx] += mx[fy]; fa[fy] = fx; } ...
#include <bits/stdc++.h> using namespace std; const int N = 6e5 + 10; const long long inf = 1e9 + 10; int f[N], vist[N]; char s[N]; long long val[N]; vector<int> vec[N]; int find(int x) { if (f[x] == x) return x; f[x] = find(f[x]); return f[x]; } void myunion(int x, int y) { if (x < y) { f[y] = x; val[x...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] ? fa[u] = find(fa[u]) : u; } void uni(int a, int b) { if (find(a) == find(b)) return; val[find(b)] += val[find(a)]; fa[find(a)] = find(b...
#include <bits/stdc++.h> using namespace std; int n, m, k, x; vector<int> vec[300010]; char c[300010]; int fa[300010 << 1], sz[300010 << 1]; int lim[300010 << 1]; int find(int x) { if (fa[x] == x) return x; return fa[x] = find(fa[x]); } int main() { scanf("%d%d%s", &n, &k, c + 1); for (int i = 1; i <= k; i++) {...
#include <bits/stdc++.h> using namespace std; int val[300000 + 100], sum[300000 + 100][2], head[300000 + 100]; int f[300000 + 100]; vector<int> V[300000 + 100]; int n, k; int ans; int findd(int x) { if (f[x] == x) return x; int F = f[x]; f[x] = findd(f[x]); val[x] = val[x] ^ val[F]; return f[x]; } char s[3000...
#include <bits/stdc++.h> using namespace std; int n, k; string s; vector<int> a[300001]; int p[1000001]; long long f[1000001]; const int Max = 6e5; const int T = 3e5; int root(int u) { if (u == p[u]) return u; return p[u] = root(p[u]); } void Merge(int u, int v) { u = root(u); v = root(v); int ru = root(u); ...
#include <bits/stdc++.h> using namespace std; const int N = 6E5 + 10; int n, k, l[N][2]; int fa[N], sc[N]; string s; int find(int x) { if (x == fa[x]) return x; return fa[x] = find(fa[x]); } int cal(int x) { int y = x <= k ? x + k : x - k; int xx = find(x), yy = find(y); if (xx == 0 || yy == 0) return sc[xx +...
#include <bits/stdc++.h> using namespace std; const int maxn = 300000 + 10; const int apsz = 26; const int INF = 10000007; const unsigned long long mod = 97; const int maxm = 10000 + 10; struct rev { int c0, c1, tag; void maintain() { c0 = min(c0, INF); c1 = min(c1, INF); } }; rev info[maxn]; int dsu[maxn...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] == u ? fa[u] : fa[u] = find(fa[u]); } void uni(int a, int b) { if (find(a) == find(b)) return; val[find(b)] += val[find(a)]; fa[find(a)]...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] == u ? fa[u] : fa[u] = find(fa[u]); } void uni(int a, int b) { if (a == b) return; val[b] += val[a]; fa[a] = b; } int mix(int a) { retur...
#include <bits/stdc++.h> using namespace std; const int MAXN = 810000; int fa[MAXN], val[MAXN], vec[MAXN][3]; int n, k, ans; char str[MAXN]; int getfa(int x) { if (fa[x] == x) return x; return fa[x] = getfa(fa[x]); } void merge(int x, int y) { int p = getfa(x), q = getfa(y); if (p == q) return; fa[p] = q; v...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 69; int n, k; string initial; int dsu[N]; int sz[N]; int szsame[N]; int parity[N]; int restrict[N]; vector<int> belong[N]; int curr = 0; int getVal(int u) { if (restrict[u] == 0) return szsame[u]; if (restrict[u] == 1) return (sz[u] - szsame[u]); r...
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } inline long long read1(...
#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 n, k, pa[600010], ct[600010], siz[600010], ans = 0; vector<long long> g[300010]; string s; long long find(long long x) { if (x == pa[x]) return x; pa[x] = find(pa[x]); ...
#include <bits/stdc++.h> using namespace std; const int maxn = (int)3e5 + 10; int par[maxn << 1], num[maxn << 1]; inline void makeSet(int size) { for (int i = 1; i <= size; i++) { par[i] = i; } } inline int find(int x) { int k, j, r; r = x; while (r != par[r]) { r = par[r]; } k = x; while (k != ...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10, inf = 0x3f3f3f3f; int n, K, m, x, pos[N][2], ans, fa[N], val[N]; char s[N]; int getfa(int x) { return fa[x] == x ? x : fa[x] = getfa(fa[x]); } void add(int x, int y) { int fx = getfa(x), fy = getfa(y); if (fx != fy) fa[fx] = fy, val[fy] += val[fx...
#include <bits/stdc++.h> using namespace std; struct perem { long long t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); long long n, k, m, c, vas, cc = 1000000; vector<long long> vv; string s; vector<vector<long long>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.ti...
#include <bits/stdc++.h> using namespace std; template <class t> inline t read(t &x) { x = 0; char c = getchar(); bool f = 0; while (!isdigit(c)) f |= c == '-', c = getchar(); while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar(); if (f) x = -x; return x; } template <class t> inline void wr...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] ? fa[u] = find(fa[u]) : u; } void uni(int a, int b) { if (find(a) == find(b)) return; val[find(b)] += val[find(a)]; fa[find(a)] = find(b...
#include <bits/stdc++.h> using namespace std; const int N = 300000 + 10; char s[N]; int par[N], diff[N]; pair<int, int> find(int x) { if (par[x] == x) return {x, 0}; auto r = find(par[x]); par[x] = r.first, diff[x] ^= r.second; return {par[x], diff[x]}; } int f[N][2], col[N], ans; int get(int x) { if (col[x] ...
#include <bits/stdc++.h> using namespace std; int test = 0; const int MAXN = 300009; const long long MOD = 119 << 23 | 1; class { public: vector<int> V[MAXN]; int fa[MAXN * 2], cnt[MAXN * 2]; int n, m; int curset[MAXN * 2], ans; int findfa(int x) { if (fa[x] == x) return x; return fa[x] = findfa(fa[x...
#include <bits/stdc++.h> using namespace std; struct perem { int t = 0, l = 1, p = -1, q = 0; }; ifstream fin("AAtest.in.txt"); int n, k, m, c, vas, cc = 1000000, kl; vector<int> vv; string s; vector<vector<int>> la; vector<perem> pr; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cerr.tie(0);...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 10; const int INF = 1e9 + 7; struct node { int l, r; node(int _l = 0, int _r = 0) : l(_l), r(_r){}; void operator+=(node x) { l = min(l + x.l, INF); r = min(r + x.r, INF); } int get() { return min(l, r); } } val[N]; int root[N], rev[N];...
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5, inf = 1e9; int n, kk, s, x, k[N][2]; char ch[N]; int fa[N << 1], val[N << 1]; int find(int u) { return fa[u] ? fa[u] = find(fa[u]) : u; } void uni(int a, int b) { if (find(a) == find(b)) return; val[find(b)] += val[find(a)]; fa[find(a)] = find(b...
#include <bits/stdc++.h> template <class V> int get_p(V& p, int j) { if (p[j] == j) return j; if (p[j] < 0) return p[j] = -get_p(p, -p[j]); return p[j] = get_p(p, p[j]); } int get_min(bool a_j, int S_j, bool coa_j, int coS_j) { if (!coa_j) return S_j; if (!a_j) return coS_j; return std::min(S_j, coS_j); } v...
#include <bits/stdc++.h> using namespace std; struct FenwickTree { int n; vector<long long> num; FenwickTree() : n(0) {} FenwickTree(int _n) { n = _n; num.assign(n, 0); } void add(int i, int val) { for (; i < n; i |= i + 1) num[i] += val; } long long sum(int i) { long long ret = 0; f...
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; int arr[n]; int v[n]; for (int i = 0; i < n; i++) cin >> arr[i]; for (int i = 0; i < n; i++) cin >> v[i]; map<int, int> mp; vector<pair<int, int> > vi; vector<pair<int, int> > vf; for (int i = 0; i < n; i++) { vi.push_ba...
#include <bits/stdc++.h> using namespace std; int n, T; pair<int, int> a[200010]; long long getval(vector<long long> &f, int pos) { pos++; long long ans = 0; for (int i = pos; i > 0; i -= (i & -i)) ans += f[i]; return ans; } void upd(vector<long long> &f, int pos, int val) { pos++; for (int i = pos; i < int...
#include <bits/stdc++.h> using namespace std; using namespace std::chrono; class st { int size; vector<int> c; vector<long long> a; public: st(int n) { size = 1; while (size < n) size *= 2; c.assign(2 * size, 0); a.assign(2 * size, 0); } void set(int i, long long v, int x, int lx, int rx) ...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; const long long MOD = 1e+9 + 7; const long long INF = 0x7f7f7f7f7f7f7f7f; const int INFi = 0x7f7f7f7f; const long long MAXN = 2e+5 + 8; vector<long long> adj[MAXN]; lon...
#include <bits/stdc++.h> using namespace std; const long long mxn = 1e6 + 7; const long long mod = 1e9 + 7; const long long inf = 1e18 + 7; int dx[] = {+1, -1, 0, 0}; int dy[] = {0, 0, -1, +1}; pair<int, int> p[mxn]; map<long long, long long> f, s; int n; int a[mxn], ls[mxn]; long long ans; void upd1(int x, int val) { ...
#include <bits/stdc++.h> using namespace std; struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; bool prime[10000001]; long long P = 1000000007 - 2; long long ...
#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; using namespace std; const int maxn = 1e+5; struct abc { long long pos; long long sp; } ver[maxn * 2 + 5]; in...
#include <bits/stdc++.h> using namespace std; int n, c[200005]; long long ans; struct t { long long x, y; int z; } a[200005]; int lowbit(int x) { return x & (-x); } void update(int x) { for (int i = x; i <= n; i += lowbit(i)) c[i]++; } int query(int x) { int s = 0; for (int i = x; i >= 1; i -= lowbit(i)) s +=...
#include <bits/stdc++.h> #pragma optimization_level 3 #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx") using namespace std; const long long N = 1e6 + 5; const long long M = 1e8; const long long mod = 1e9 + 7; const long long INF...
#include <bits/stdc++.h> using namespace std; pair<int, int> a[200005]; vector<int> g; struct node { long long w, num; } tree[1000005]; void update(int x, long long val, int l, int r, int k = 1) { if (l == r and l == x) { tree[k].w++; tree[k].num += val; return; } int mid = l + r >> 1; if (x <= mi...
#include <bits/stdc++.h> using namespace std; void dout() { cerr << '\n'; } template <typename Head, typename... Tail> void dout(Head H, Tail... T) { cerr << " " << H; dout(T...); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 2e5 + 7; int n, m, cnt[N]; long long sum[N]; pair<i...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5, MOD = 1e9 + 7; pair<long long, long long> a[N]; pair<long long, long long> tree[4 * N]; bool compare(pair<long long, long long> p1, pair<long long, long long> p2) { return p1.first < p2.first; } void update(long long node, long long st, long l...
#include <bits/stdc++.h> using namespace std; using LL = long long; struct Point { LL x, v; bool operator<(const Point &rhs) const { if (v == rhs.v) return x < rhs.x; else return v < rhs.v; } }; Point p[200010]; LL n, x2[200010], idx[200010], c[200010], s[200010]; void update(LL *arr, LL pos, ...
#include <bits/stdc++.h> using namespace std; int n, tot, cnt, v[200001]; long long ans, c1[200001], c2[200001]; struct node { int x, v; inline bool operator<(const node &a) const { return x < a.x; } } s[200001]; inline int read() { int k = 0, f = 1; char c; while ((c = getchar()) < '0' || c > '9') if (c ...
#include <bits/stdc++.h> using namespace std; const long long N = 3e5 + 5; pair<long long, long long> p[N], a[N]; long long n; long long fwt[N], cntf[N]; long long len; void add(long long *b, long long x, long long v) { while (x <= len) { b[x] += v; x += x & -x; } } long long get(long long *b, long long x) ...
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9; long long f[200005], ans, bit[200005], s[200005]; map<long long, long long> m; long long t, n; pair<long long, long long> a[200005]; long long get(long long first, long long second) { long long re = 0, cnt = 0; for (long long i = second; i > 0...
#include <bits/stdc++.h> using namespace std; int n; struct dd { int gt; int x; int v; }; vector<dd> a; struct Data { long long sum; int sl; }; Data it[200009 * 8]; Data ans; long long res; void update(int i, int l, int r, int pos, int data) { if (l > pos || r < pos) return; if (l == r) { it[i].sum = ...
#include <bits/stdc++.h> using namespace std; const long long N = 1000010; const long long mod = 998244353; const long long inf = 1e9; const long double eps = 1e-16; const long double pi = acos(-1); inline long long rd() { long long p = 0; long long f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { ...
#include <bits/stdc++.h> using namespace std; long long n; pair<long long, long long> pos[200005]; struct FenwickTree { vector<long long> bit; long long n; FenwickTree(long long n) { this->n = n; bit.assign(n, 0); } FenwickTree(vector<long long> a) : FenwickTree(a.size()) { for (size_t i = 0; i < ...
#include <bits/stdc++.h> using namespace std; vector<long> inverse(vector<long>& perm) { long n = perm.size(); vector<long> ret(n); for (long i = 0; i < n; ++i) { ret[perm[i]] = i; } return ret; } vector<long> assignPermutation(const vector<long>& uniqs) { long n = uniqs.size(); vector<pair<long, long...
#include <bits/stdc++.h> using namespace std; int lowbit(int x) { return x & (-x); } long long get(vector<long long>& f, int pos) { long long res = 0; for (; pos >= 0; pos = (pos & (pos + 1)) - 1) res += f[pos]; return res; } void upd(vector<long long>& f, int pos, int val) { for (; pos < int(f.size()); pos |= ...
#include <bits/stdc++.h> using namespace std; long long n, ans, tree[800002], tree1[800002]; map<long long, long long> mp, mp1; pair<long long, long long> a[300005]; vector<long long> v; void inc1(int idx, int val) { for (int i = idx; i <= n; i += i & (-i)) { tree[i] += val; } } void inc2(int idx, int val) { ...
#include <bits/stdc++.h> using namespace std; struct Node { int l, r; int cnt = 0; long long sum = 0; int left = -1; int right = -1; } NIL; vector<Node> st; Node merge(Node x, Node y) { Node z; z.cnt = x.cnt + y.cnt; z.sum = x.sum + y.sum; return z; } void add(int u, int x, int v) { if (not(st[u].l ...
#include <bits/stdc++.h> using namespace std; int n; long long f1[200005], f2[200005], kc; pair<long long, long long> a[200005]; bool cmp1(pair<long long, long long> x, pair<long long, long long> y) { return x.first < y.first; } bool cmp2(pair<long long, long long> x, pair<long long, long long> y) { return x.second...
#include <bits/stdc++.h> using namespace std; using ll = long long; using vi = vector<int>; using vvi = vector<vi>; using pii = pair<int, int>; static int MAX_N = 200000, n; vector<ll> bitx(MAX_N + 1), bit1(MAX_N + 1); ll sum(int i, vector<ll> &bit) { ll res = 0; while (i > 0) { res += bit.at(i); i -= i & -...
#include <bits/stdc++.h> using namespace std; void fio() {} void pti() { double timeuse = clock() * 1000.0 / CLOCKS_PER_SEC; cerr << "Timeuse " << timeuse << "ms" << endl; } void end() { exit(0); } namespace io { const int SIZ = 55; int que[SIZ], op, qr; char ch; template <class I> inline void gi(I& w) { ch = get...
#include <bits/stdc++.h> #pragma optimize("O3") using namespace std; const long long MOD = 1e9 + 9; const long long INF = 1e9 + 7; const int base = 2e5 + 1; const long long MAX = 1e15 + 1; const double EPS = 1e-9; const double PI = acos(-1.); const int MAXN = 2 * 1e5 + 47; mt19937 rng(chrono::steady_clock::now().time_s...
#include <bits/stdc++.h> using namespace std; pair<long long int, long long int> final[200001]; void up(long long int i, long long int x, long long int j) { while (i < 200001) { j == 0 ? final[i].first += x : final[i].second += x; i += (i & (-i)); } } long long int q(long long int i, long long int j) { lo...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const int inf = 0x3f3f3f3f; const int MOD = 1e9 + 7; const double eps = 1e-4; const double pi = acos(-1.0); void debug() { cerr << '\n'; } template <typename T, typename... Ts> void debug(T x, Ts... y) { cerr << "\033[31m" << x << "\033[0m"; if (...
#include <bits/stdc++.h> using namespace std; inline int lowbit(int x) { return x & (-x); } long long getsum(vector<long long> &V, int pos) { long long ret = 0; for (; pos; pos -= lowbit(pos)) ret += V[pos]; return ret; } void add(vector<long long> &V, int pos, int k) { for (; pos < (int)V.size(); pos += lowbit...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int x[N]; long long ans; pair<int, int> a[N]; int main(void) { std::ios::sync_with_stdio(false); int n; cin >> n; for (int i = 0; i < n; i++) cin >> a[i].second, x[i] = a[i].second; for (int i = 0; i < n; i++) cin >> a[i].first; sort(a, a...
#include <bits/stdc++.h> using namespace std; int b[200005], m; long long tr[800005][2]; struct node { int x, v; bool operator<(const node t) const { return x < t.x; } } a[200005]; int lsh(long long x) { return lower_bound(b + 1, b + 1 + m, x) - b; } long long query(int l, int r, int x, int y, int k, int p) { if ...
#include <bits/stdc++.h> using namespace std; const long long int infinity = 9e18; pair<long long int, long long int> t1[4 * 200005] = {}; pair<long long int, long long int> t2[4 * 200005] = {}; struct SegmentTree { void update(pair<long long int, long long int> t[], int v, int tl, int tr, int pos, int ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int n; int b[maxn]; struct node { int x, v; } a[maxn]; bool cmp(node q1, node q2) { return q1.v == q2.v ? q1.x < q2.x : q1.v < q2.v; } struct BIT { long long c[maxn][2]; void init() { memset(c, 0, sizeof(c)); } int lowbit(int x) { return x ...
#include <bits/stdc++.h> using namespace std; const int maxn = 1e6 + 5; pair<int, int> p[maxn]; int n; long long d[maxn]; long long e[maxn]; void add(long long *c, int i, int k) { while (i <= n) { c[i] += k; i += i & (-i); } } long long sum(long long *c, int i) { long long res = 0; while (i > 0) { r...
#include <bits/stdc++.h> using namespace std; int II() { int q; scanf("%d", &q); return q; } long long LII() { long long q; scanf("%lld", &q); return q; } const long long Mx = 200005; long long N; vector<long long> tree[Mx * 4], cum[Mx * 4]; vector<pair<long long, long long> > v(Mx + 1); void update(long lo...
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; using db = double; using vi = vector<int>; const int inf = 0x3f3f3f3f; const db eps = 1e-8; const int mod = 1e9 + 7; ll qpow(ll a, ll b) { ll ret = 1; while (a) { if (b & 1) ret = ret * a % mod; a = a * a % mod; ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 200010; const long long N = 200000; long long n; struct Node { long long v, x; bool operator<(const Node& b) const { return x < b.x; } } p[maxn]; struct BIT { long long b[maxn]; inline long long lowbit(long long x) { return x & (-x); } void ...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const int N = 2e5 + 2; const int inf = 2e9; const long long linf = 4e18; long long val[N], cnt[N]; void upd(int x, long long v) { int z = 0; if (v < 0) z--; else z++; for (; x < N; x += x & (-x)) { cnt[x] += z; val[x]...
#include <bits/stdc++.h> using namespace std; template <class T> struct fen { vector<T> fenwick; long long size; fen(long long sz) { size = sz; fenwick.resize(size); for (long long i = 0; i < size; i++) fenwick[i] = 0; } fen(vector<T> arr) { size = arr.size(); fenwick.resize(size); for...
#include <bits/stdc++.h> using namespace std; long long int get(vector<long long int> &arr, long long int ind, long long int n) { long long int ans = 0; for (; ind > 0; ind -= (ind & (-ind))) ans += arr[ind]; return ans; } void upd(vector<long long int> &arr, long long int ind, long long int x, ...
#include <bits/stdc++.h> long double pi = acos(-1.0); const int mod = 1e9 + 7; using namespace std; const int N = 2e5 + 5; vector<long long> F(N), F2(N); long long sum(int r, vector<long long> &t) { long long result = 0; for (; r >= 0; r = (r & (r + 1)) - 1) result += t[r]; return result; } void inc(int i, long l...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization("unroll-loops") using namespace std; using namespace chrono; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << "\n"; } template <typename Arg1, typename....
#include <bits/stdc++.h> using namespace std; struct Point { long long x; long long v; }; vector<Point> points; long long SUM; void add_pairwise_dist(long long start, long long end) { int m, i, j; if (start == end) return; m = start + (end - start) / 2; add_pairwise_dist(start, m); add_pairwise_dist(m + 1...
#include <bits/stdc++.h> using namespace std; const int N = 200000; int x[N + 5], v[N + 5], _v[N + 5]; pair<int, int> point[N + 5]; template <typename T, int N> struct Binary_Indexed_Tree { int n; T sumv[N + 5]; void init(int _n) { n = _n; memset(sumv, 0, (n + 4) * sizeof(T)); } void build(T A[], int ...
#include <bits/stdc++.h> template <class C> inline void log_c(const C& c) {} template <class C> inline int sz(const C& c) { return static_cast<int>(c.size()); } using namespace std; using pii = pair<int, int>; using num = int64_t; using pll = pair<num, num>; const std::string eol = "\n"; using Ft = map<int, pair<int,...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, x[N], v[N]; vector<pair<int, int>> p; long long bit1[N], bit2[N], ans; void add(int p, int v, long long *bit) { for (p += 2; p < N; p += p & -p) bit[p] += v; } long long query(int p, long long *bit) { long long r = 0; for (p += 2; p; p -=...
#include <bits/stdc++.h> using namespace std; void dout() { cerr << '\n'; } template <typename Head, typename... Tail> void dout(Head H, Tail... T) { cerr << " " << H; dout(T...); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 2e5 + 7; int n, m, cnt[N]; long long sum[N]; pair<i...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10, inf = 1e9; const long long mod = (long long)1e9 + 7; set<int> setV; map<int, int> idV; pair<int, int> p[N]; int n; int treenum[N], num; long long treesum[N], sum; long long qry(long long tree[], int id) { long long ans = 0LL; for (; id; id -= (id...
#include <bits/stdc++.h> using namespace std; long long powmod(long long a, long long b, long long mod) { if (b == 0 || a == 1) { if (mod == 1) return 0; else return 1; } if (b % 2 == 0) { long long k = powmod(a, b / 2, mod); return (k * k) % mod; } else { long long k = powmod(a,...
#include <bits/stdc++.h> using namespace std; long long int max(long long int a, long long int b) { if (a > b) return a; else return b; } long long int min(long long int a, long long int b) { if (a < b) return a; else return b; } const int dx[4] = {-1, 1, 0, 0}; const int dy[4] = {0, 0, -1, 1}; ...
#include <bits/stdc++.h> template <class T> T sqr(T x) { return x * x; } template <class T> T lcm(T a, T b) { return a / __gcd(a, b) * b; } const long long mod = 1e9 + 7, oo = 1e12, N = 2e5 + 5; using namespace std; long long n, b[N], res, bit1[N], bit2[N]; pair<long long, long long> a[N]; inline long long lowbit(l...
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { std::cerr << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); std::cerr...
#include <bits/stdc++.h> using namespace std; pair<long long, long long> o[(int)2e5 + 10]; long long n, ts[(int)2e5 + 10], tc[(int)2e5 + 10]; int main(void) { scanf("%lld", &n); for (int i = 0; i < n; i++) { scanf("%lld", &o[i].second); } for (int i = 0; i < n; i++) { scanf("%lld", &o[i].first); } s...
#include <bits/stdc++.h> using namespace std; const long long N = 1e5 + 7; int n; vector<pair<int, int>> p; vector<int> vv1; long long get(vector<long long> &f, int pos) { long long res = 0; for (; pos >= 0; pos = (pos & (pos + 1)) - 1) { res += f[pos]; } return res; } void upd(vector<long long> &f, int pos...
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 1; const int NN = 1e3 + 1; const long long MOD = 1e9 + 7; const long long oo = 1e18 + 7; const int BASE = 10000; void solve() { int n; cin >> n; vector<int> x(n + 1); for (int i = 1; i <= n; i++) { cin >> x[i]; } vector<int> v(n + 1); f...
#include <bits/stdc++.h> using namespace std; int n; long long BIT[515151]; int BIT2[515151]; map<int, int> hs; void update(int x, int y) { for (int i = x; i <= 5e5; i += (i & (-i))) BIT[i] += y, BIT2[i]++; } long long query(int x) { long long tmp = 0; for (int i = x; i >= 1; i -= (i & (-i))) tmp += BIT[i]; ret...
#include <bits/stdc++.h> using namespace std; const int N = 200009; int n, b[N], p[N], tot; long long c1[N], c2[N]; struct P { int x, v; bool operator<(const P &A) const { return x < A.x; } } a[N]; int lowbit(int x) { return x & (x ^ (x - 1)); } void add(int x, int k, long long c[]) { while (x <= tot) { c[x] ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; long long positions[maxn], speeds[maxn]; pair<long long, long long> pairs[maxn]; map<long long, long long> m; bool comp(pair<long long, long long>& a, pair<long long, long long>& b) { if (a.second == b.second) return a.first < b.first; return a...
#include <bits/stdc++.h> using namespace std; pair<long long, long long> a[200005]; long long sum[1000005], cnt[1000005]; long long querysum(long long pos) { long long ret = 0; for (; pos >= 0; pos = (pos & (pos + 1)) - 1) { ret += sum[pos]; } return ret; } long long querycnt(long long pos) { long long re...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 20; int n; pair<int, int> p[N]; struct node { long long sum, count; node(long long s = 0, long long c = 0) : sum(s), count(c) {} } bit[N]; void update(int x, int delta) { for (; x <= n; x += x & -x) { auto &[sum, count] = bit[x]; sum += del...
#include <bits/stdc++.h> using namespace std; long long read() { long long a = 0, b = getchar(), c = 1; while (!isdigit(b)) c = b == '-' ? -1 : 1, b = getchar(); while (isdigit(b)) a = a * 10 + b - '0', b = getchar(); return a * c; } long long n, ans, p[200005]; pair<long long, long long> a[200005]; int main() ...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 500; long long n, t1[N], t2[N]; void upd1(long long val, long long pos) { while (pos < n) { t1[pos] += val; pos = (pos | (pos + 1)); } } void upd2(long long val, long long pos) { while (pos < n) { t2[pos] += val; pos = (pos | ...
#include <bits/stdc++.h> using namespace std; void __print(int x) { cerr << x; } void __print(long x) { cerr << x; } void __print(long long x) { cerr << x; } void __print(unsigned x) { cerr << x; } void __print(unsigned long x) { cerr << x; } void __print(unsigned long long x) { cerr << x; } void __print(float x) { cer...