solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; template <typename Tp> void read(Tp &x) { x = 0; long long f = 1; char c = getchar(); while (c > '9' || c < '0') { if (c == '-') { f = -1; } c = getchar(); } while (c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + (c ^ 48); c = getchar...
10
CPP
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; const long long INF = 1e16 + 239; const int MAXN = 1e6 + 239; long long a[MAXN]; namespace SegmentTree { int n; long long t[4 * MAXN]; long long mod[4 * MAXN]; void pull(int v) { t[v] = min(t[2 * v + 1], t[2 * v + 2]); } void apply(int v, long ...
10
CPP
#include <bits/stdc++.h> using namespace std; long long n, ar[200005], br[200005], up[800555], dr[100]; pair<long long, long long> tr[800555]; void build(long long, long long, long long), update(long long, long long, long long, long long), upd(long long, long long, long long, long long, long long, long long); i...
10
CPP
#include <bits/stdc++.h> using namespace std; long long bit[200005]; void add(long long idx, long long val) { for (int i = idx; i < 200005; i += (i & (-i))) { bit[i] += val; } } long long query(long long i) { long long ans = 0; for (; i > 0; i -= (i & (-i))) ans += bit[i]; return ans; } long long b[200005...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long MM = 10000000000000001; int n; long long a[200005]; int rs[200005]; long long lazy[4 * 200005]; pair<long long, int> it[4 * 200005]; pair<long long, int> minp(pair<long long, int> A, pair<long long, int> B) { if (A.first < B.first) return A; if (A.first ...
10
CPP
#include <bits/stdc++.h> using namespace std; int n; long long s[200066]; long long c[200066]; long long ans[200066]; long long lowbit(long long x) { return x & (-x); } long long q(long long x) { long long ans = 0; while (x > 0) { ans += c[x]; x -= lowbit(x); } return ans; } void update(long long x, lon...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = (int)2E5; long long arr[MAXN + 1]; long long sum[MAXN + 1]; long long bit[MAXN + 1]; int ans[MAXN + 1]; long long query(int x) { long long ans = 0; while (x > 0) { ans += bit[x]; x -= x & -x; } return ans; } void increment(int x, int amt, in...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MX = 200005; vector<int> v; long long n, a[MX], w[MX], tree[MX * 4 + 5]; long long con(int num, int nodeL, int nodeR) { if (nodeL == nodeR) return tree[num] = w[nodeL]; long long mid = (nodeL + nodeR) / 2; return tree[num] = con(num * 2, nodeL, ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int M = 200010; struct BIT { long long tree[M]; BIT() { memset(tree, 0, sizeof tree); } void update(int idx, int val) { while (idx < M) { tree[idx] += val; idx += idx & (-idx); } } long long query(int idx) { long long sum = 0; whi...
10
CPP
#include <bits/stdc++.h> using namespace std; const int max_n = 200222; const long long inf = 1000111222000111222LL; struct tree { long long mx[4 * max_n], add[4 * max_n]; tree() { memset(mx, 0, sizeof(mx)); memset(add, 0, sizeof(add)); } void push(int v) { if (add[v]) { mx[2 * v] += add[v]; ...
10
CPP
#include <bits/stdc++.h> const int inf = INT_MAX; const int MAX = 3e6 + 9; const long long MOD = 1e9 + 7; const int TOT_PRIMES = 1e6 + 9; const int MAX_A = 71; const int LN = 20; using namespace std; long long bt[MAX]; long long arr[MAX]; void update(int x, long long val) { for (int i = x; i < MAX; i += i & -i) bt[i]...
10
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; inline ll read(); const int M = 500016, MOD = 1000000007; struct BinaryIndexTree { ll bit[M], n; inline void modify(ll p, ll x) { for (; p <= n; p += p & -p) bit[p] += x; } inline ll sum(ll p) { ll res = 0; for (; p; p -= p & -p) re...
10
CPP
# 1208D class segTree(): def __init__(self, n): self.t = [0] * (n << 2) def update(self, node, l, r, index, value): if l == r: self.t[node] = value return mid = (l + r) >> 1 if index <= mid: self.update(node*2, l, mid, index, value) el...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const double PI = 3.141592653589793; const long long I_MAX = 1LL << 60; long long mod = 1000000007; const long long maxN = 2E5; vector<long long> inv(maxN + 5, 1); vector<long long> fac(maxN + 5, 1); void ADD(long long &x, long long y) { x += y; if (x >= mod) x -= mod; ...
10
CPP
import sys input=sys.stdin.readline n=int(input()) s=list(map(int,input().split())) BIT=[0]*(n+1) def update(i,w): while i<=n: BIT[i]+=w i+=(i&-i) def get_sum(i): res=0 while i>0: res+=BIT[i] i-=(i&-i) return res for i in range(1,n+1): update(i,i) ans=[-1]*n for i in ...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int n; long long ar[200005]; long long tree[800005]; long long valr[800005]; long long lazy[800005]; long long ans[200005]; int gl = 0; long long h; void build(int node, int start, int end) { if (start == end) { tree[node] = ar[start]; valr[node] = start; } else...
10
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int maxN = 1e6 + 10; ll tree[4 * maxN]; int n, p[maxN]; ll s[maxN]; void update(int x, int l, int r, int k, int w) { if (l == r) tree[x] = w; else { int mid = (l + r) / 2; if (k <= mid) update(2 * x, ...
10
CPP
#include <bits/stdc++.h> using namespace std; pair<long long, long long> t[4 * 200009]; long long a[200009], lazy[4 * 200009], ans[200009]; void build(long long v, long long tl, long long tr) { if (tl == tr) { t[v] = {a[tl], tl}; } else { long long tm = (tl + tr) / 2; build(v * 2, tl, tm); build(v *...
10
CPP
#include <bits/stdc++.h> using namespace std; long long good_rand() { return rand() * RAND_MAX + rand(); } template <class A> class myvector : public std::vector<A> { public: A &operator[](int pos) { if (pos < 0) pos = 0; while (this->size() <= pos) { this->push_back({}); } return std::vector<A...
10
CPP
#include <bits/stdc++.h> using namespace std; long long n; long long s[200005], p[200005]; long long t[200005]; long long lowbit(long long x) { return x & (-x); if (14209 > 9243) { if (31558 > 31075) { bool ZENBDJUSHQ; ZENBDJUSHQ = 28821; if (21853 > 13000) { if (11380 > 20609) { ...
10
CPP
#include <bits/stdc++.h> using namespace std; inline int read() { int x = 0, f = 1, c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f ^= 1; for (; isdigit(c); c = getchar()) x = x * 10 + c - '0'; return f ? x : -x; } struct BIT { long long sum[200005]; void upd(int x, int v) { for (;...
10
CPP
#include <bits/stdc++.h> using namespace std; const int LIM = 1e5 + 5, MOD = 1e9 + 7; const int maxn = 1000006; long long solve(long long a, long long b) { if ((a == b) || (a == 0)) { return 0; } else { long long res; res = 1 + solve(a % (b / 2), b / 2); return res; } } long long ft[200005]; long ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f, N = 2e5 + 5; inline int read() { int sum = 0, f = 1; char c = getchar(); while (c > '9' || c < '0') { if (c == '-') f = -f; c = getchar(); } while (c >= '0' && c <= '9') sum = sum * 10 + c - 48, c = getchar(); return sum * f; ...
10
CPP
#include <bits/stdc++.h> #pragma GCC optimize "O3" using namespace std; const int inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const int N = 2e5 + 5; const int M = 1 << 18; pair<long long, int> tree[M * 2 + 5]; long long lazy[M * 2 + 5]; int n, ans[N]; void push(int v) { tree[v * 2].first += lazy[v]; ...
10
CPP
#include <bits/stdc++.h> using namespace std; using pii = pair<long long, int>; const int maxn = 2e5 + 5; int n; long long a[maxn], s[maxn], t[maxn << 2]; void build(int l, int r, int rt) { if (l == r) { t[rt] = l; return; } int m = l + r >> 1; build(l, m, rt << 1); build(m + 1, r, rt << 1 | 1); t[r...
10
CPP
#include <bits/stdc++.h> using namespace std; int ans[200005], n; long long a[200005], aib[200005]; inline void Update(int p, int val) { while (p <= n) { aib[p] += val; p += p & (-p); } } inline long long Sum(int p) { long long s = 0; while (p >= 1) { s += aib[p]; p -= p & (-p); } return s; ...
10
CPP
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:640000000") using namespace std; const double eps = 1e-9; const double pi = acos(-1.0); const int maxn = (int)2e5 + 10; long long a[maxn]; int res[maxn]; long long t[4 * maxn]; void build(int idx, int l, int r) { if (l == r) { t[idx] = l; } else { int...
10
CPP
#include <bits/stdc++.h> using namespace std; vector<long long> tree; vector<long long> s; vector<long long> p; long long build(long long L, long long R, long long v) { if (R - L == 1) { return tree[v] = L + 1; } else { return tree[v] = build(L, (L + R) / 2, v * 2 + 1) + build((L + R) /...
10
CPP
#include <bits/stdc++.h> #pragma comment(linker, "/STACK:1000000000") using namespace std; const int maxn = (int)2e5 + 10; int n; long long v[maxn]; long long t[4 * maxn]; void change(int it, int l, int r, int pos, int x) { if (l == r) { t[it] = x; } else { int m = (l + r) >> 1; if (pos <= m) { ch...
10
CPP
#include <bits/stdc++.h> using namespace std; int T; long long n; long long a[333333]; long long twosum[333333]; long long tree[(1LL << 18) * 3]; long long ans[333333]; set<long long> s; void update(long long x, long long y) { x += (1LL << 18); while (x > 0LL) { tree[x] += y; x /= 2LL; } } long long sum(i...
10
CPP
#include <bits/stdc++.h> using namespace std; int n, ans[200100]; long long s[200100]; pair<long long, int> seg[800100]; long long lazy[800100]; void build(int l, int r, int ind) { if (l == r) { seg[ind] = {s[l], l}; return; } int mid = (l + r) / 2; build(l, mid, ind * 2); build(mid + 1, r, ind * 2 + ...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long inf = 0x3f3f3f3f; const long long INF = 0x3f3f3f3f3f3f3f3f; const long long mod = 1e9 + 7; long long tree[200050 << 2], lazy[200050 << 2], a[200050]; void pushup(long long rt) { tree[rt] = min(tree[rt << 1], tree[rt << 1 | 1]); } void pushdown(long long rt) ...
10
CPP
#include <bits/stdc++.h> using namespace std; struct BIT { int size; vector<long long> bit; BIT() { size = 0; } BIT(int s) { size = s; bit.resize(size + 1); init(); } void init() { for (int i = 1; i <= size; i++) bit[i] = 0; } long long query(long long i) { long long ret = 0; whi...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long inf = 1e18; const long long maxn = 2e5 + 10; long long n, a[maxn], ans[maxn]; long long read() { long long x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= ...
10
CPP
#include <bits/stdc++.h> using namespace std; vector<long long> bit(200001); void update(long long x, long long y, long long n) { for (long long i = x; i <= n; i = i + (i & (-i))) bit[i] += y; } int search(long long x, int n) { long long ans = 0, sum = 0; for (int i = 21; i >= 0; i--) { if (ans + (1LL << i) <...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; int n, ans[MAXN], mark[MAXN]; long long s[MAXN], tree[MAXN]; void add(int x, int val) { for (; x <= n; x += x & -x) tree[x] += val; } long long ask(int x) { long long res = 0; for (; x; x &= x - 1) res += tree[x]; return res; } int main() {...
10
CPP
#include <bits/stdc++.h> std::vector<long long> a; const long long INF = 1000000000000000000LL; int lm = -1; std::vector<long long> ts; long long fill(int l, int r, int i) { if (l == r) { ts[i] = a[l]; return a[l]; } int m = (l + r) / 2; ts[i] = fill(l, m, i * 2) + fill(m + 1, r, i * 2 + 1); return ts...
10
CPP
#include <bits/stdc++.h> using namespace std; long long A[300001]; long long tree[300001 * 4 + 2], prop[4 * 300001 + 2], ans[300001]; void create(long long node, long long b, long long e) { if (b == e) { tree[node] = A[b]; return; } long long l = 2 * node; long long r = l + 1; long long m = (b + e) / ...
10
CPP
#include <bits/stdc++.h> using namespace std; using LL = long long; using PII = pair<int, int>; template <class T> struct Fenwick { vector<T> v; Fenwick(size_t n) : v(n + 1) {} void add(size_t i, T x) { for (++i; i < v.size(); i += i & -i) v[i] += x; } T sum(size_t i) { for (v[0] = T(); i; i -= i & -i...
10
CPP
#include <bits/stdc++.h> using namespace std; struct BIT { int n, N_MAX; vector<long long> v; BIT(int n) { this->n = n + 100; N_MAX = n - 1; v.assign(n + 110, 0); } void upd(int p, int x) { while (p <= n) v[p] += x, p += p & -p; } long long que(int p) { long long ans = 0; while (p)...
10
CPP
#include <bits/stdc++.h> using namespace std; void rset(); void init_test(); void solve(); signed main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed; cout.precision(20); init_test(); return 0; } template <typename T> void chmin(T& a, T b) { if (a > b) a = b; } template <typename T> void chmax...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, b[N]; long long BIT[N], a[N]; int lowbit(int x) { return x & (-x); } void Add(int x, int y) { while (x <= n) { BIT[x] += y; x += lowbit(x); } } long long Sum(int x) { long long ans = 0; while (x) { ans += BIT[x]; x -= low...
10
CPP
#include <bits/stdc++.h> using namespace std; long long int bit[200005]; int n; void update(int j, int x) { for (; j < 200005; j += j & (-j)) bit[j] += x; } long long int query(int j) { if (j == 0) return 0; long long int x = 0; for (; j > 0; j -= (j) & (-j)) x += bit[j]; return x; } int next_ele(long long in...
10
CPP
# TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! # TAIWAN NUMBER ONE!!!!!!!!!!!!!!!!!!! from sys import stdin, stdout from collections import defaultdict from collections import deque import math import copy #T = int(input()) N = int(input()) #s1 = input() #s2 = input() #N,Q = [int(x) for...
10
PYTHON3
import math import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys mod = 10 ** 9 + 7 mod1 = 998244353 # ------------------------------warmup---------------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 #sys.setrecursionlim...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n; long long sum[N], ans[N], cur; long long seg[1 << 20]; set<int> nw; void update(int i, int v, int ni = 0, int ns = 0, int ne = n) { if (ns > i || ne < i || ns > ne) return; if (ns == ne && ns == i) { seg[ni] += v; return; } if (...
10
CPP
#include <bits/stdc++.h> using namespace std; int n, a[200005]; long long s[200005]; pair<long long, int> sg[800005]; long long lz[800005]; void Build(int nod, int l, int r) { sg[nod] = {0, r}; if (l == r) return; int mid = (l + r) / 2; Build(2 * nod, l, mid); Build(2 * nod + 1, mid + 1, r); } void Sift(int n...
10
CPP
#include <bits/stdc++.h> using namespace std; namespace fast { inline char nc() { static char buf[100000], *L = buf, *R = buf; return L == R && (R = (L = buf) + fread(buf, 1, 100000, stdin), L == R) ? EOF : *L++; } template <class orz> inline void qread(orz &x) { x = 0; char ch = nc();...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, ans[N]; long long a[N], bit[N]; void update(int pos) { for (int i = pos; i < N; i += (i & -i)) { bit[i] += pos; } } long long query(int pos) { long long res = 0; for (int i = pos; i; i -= (i & -i)) { res += bit[i]; } return ...
10
CPP
def update(x,val): while x<=n: BIT[x]+=val x+=(x&-x) def query(x): s=0 while x>0: s=(s+BIT[x]) x-=(x&-x) return s n=int(input()) BIT=[0]*(n+1) for i in range(1,n+1): update(i,i) arr=list(map(int,input().split())) answers=[0]*(n) #print(BIT) for i in range(n-1,-1,-1): ...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long maxn = 1000005; const long long inf = 0x3f3f3f3f3f3f3f3f; const long long MOD = 100000007; const double eps = 1e-10; long long qpow(long long a, long long b) { long long tmp = a % MOD, ans = 1; while (b) { if (b & 1) { ans *= tmp, ans %= MOD; ...
10
CPP
#include <bits/stdc++.h> #pragma GCC optimize("unroll-loops") #pragma GCC optimize("O3") #pragma GCC optimize("fast-math") #pragma GCC optimize("Ofast") using namespace std; const int INF = 1e9 + 10; const long long INFll = 2e18; const int BASE1 = 179; const int BASE2 = 653; const long long MOD = 998244353; const int M...
10
CPP
#include <bits/stdc++.h> using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); int grand(int x) { return uniform_int_distribution<int>(0, x - 1)(rng); } long long getInt() { bool minus = false; long long result = 0; char ch; ch = getchar(); while (true) { if (ch == '-')...
10
CPP
#include <bits/stdc++.h> using namespace std; int t, n; long long s[200005]; long long T[200005 << 2]; void build(int u, int l, int r) { T[u] = 0; if (l == r) { T[u] = l; return; } build((u << 1), l, ((l + r) >> 1)); build((u << 1 | 1), ((l + r) >> 1) + 1, r); T[u] = T[(u << 1)] + T[(u << 1 | 1)]; }...
10
CPP
#include <bits/stdc++.h> using namespace std; int n; long long s[200001]; int used[200001]; long long stree[800001]; int result[200001]; long long update(int node, int l, int r, int index, long long diff) { if (r < index || index < l) return stree[node]; if (r == l) { stree[node] += diff; return stree[node]...
10
CPP
#include <bits/stdc++.h> using namespace std; template <class T> bool mini(T &a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool maxi(T &a, T b) { return a < b ? (a = b, true) : false; } const int N = 2e5 + 5; int n, ans[N]; long long bit[N], p[N]; void up(int i, int val) { assert(i > 0); ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const long long INF = 1e18; int n; long long a[maxn], ans[maxn]; long long tree[maxn << 2], laz[maxn << 2]; void pushup(int rt) { tree[rt] = min(tree[rt << 1], tree[(rt << 1) | 1]); } void build(int l, int r, int rt) { if (l == r) { tree[rt] ...
10
CPP
#include <bits/stdc++.h> inline long long minn(long long a, long long b) { if (a < b) return a; return b; } const int MAXN = 2e5 + 5; const long long INF = 1ll << 60; int n; long long mi[MAXN << 2], tag[MAXN << 2]; inline void pushdwn(int k) { mi[k << 1] -= tag[k]; tag[k << 1] += tag[k]; mi[k << 1 | 1] -= tag...
10
CPP
#include <bits/stdc++.h> using namespace std; struct S { int a, b; S() {} S(int _a, int _b) { a = _a; b = _b; } const bool operator<(const S &o) const { return a < o.a; } }; string exm; inline void exf(void) { cout << exm << "\n"; exit(0); } template <typename T> inline void showAll(vector<T> &v, ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 200005; long long a[N]; pair<long long, long long> seg[4 * N]; void build(long long ind, long long l, long long r) { if (l > r) return; if (l == r) { seg[ind] = {a[l], l}; return; } long long mid = (l + r) / 2; build(2 * ind + 1, l, mid); b...
10
CPP
#include <bits/stdc++.h> using namespace std; long long n; long long s[200001], up[200001]; long long d[200001], c[200001]; long long ans[200001]; inline long long lowbit(long long x) { return x & -x; } inline long long getup(long long x) { long long ans = 0; for (; x; x -= lowbit(x)) ans += c[x]; return ans; } i...
10
CPP
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; template <class T, class U> inline void add_self(T &a, U b) { a += b; if (a >= mod) a -= mod; if (a < 0) a += mod; } template <class T, class U> inline void min_self(T &x, U y) { if (y < x) x = y; } template <class T, class U> inline void ma...
10
CPP
from sys import setrecursionlimit as SRL, stdin SRL(10 ** 7) rd = stdin.readline rrd = lambda: map(int, rd().strip().split()) n = int(rd()) bit = [0] * 200005 def add(x, val): while x <= n: bit[x] += val x += (x & -x) def query(x): num = 0 for i in range(30, -1, -1): if num+(1...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 10; const long long inf = 1e15 + 10; const long long mod = 1e9 + 7; set<int> s; long long a[M], ans[M]; long long sum[4 * M], lazy[4 * M]; int v[M * 4]; void pushup(int x) { sum[x] = min(sum[x << 1], sum[x << 1 | 1]); } void built(int l, int r, int i) { ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int MN = 200010; int n; long long ft[MN]; void update(int pos, long long by) { while (pos < n) ft[pos] += by, pos |= pos + 1; } long long query(int pos) { long long ans = 0; while (pos >= 0) ans += ft[pos], pos = (pos & (pos + 1)) - 1; return ans; } int main()...
10
CPP
#include <bits/stdc++.h> using namespace std; int n, p[200005], mnpos[1 << 19]; long long s[200005], mn[1 << 19], add[1 << 19]; void pushup(int u) { mn[u] = mn[u << 1 | 1], mnpos[u] = mnpos[u << 1 | 1]; if (mn[u << 1] < mn[u]) mn[u] = mn[u << 1], mnpos[u] = mnpos[u << 1]; } void build(int u, int l, int r) { if (l...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 200001; long long pre[N] = {}; void add(long long p, long long x) { for (long long i = p; i <= N; i += (i & -i)) pre[i] += x; } long long query(long long p) { long long ans = 0; for (long long i = p; i > 0; i -= i & (-i)) ans += pre[i]; return ans; } i...
10
CPP
#include <bits/stdc++.h> using namespace std; void solve(); int32_t main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; int t = 1; for (int i = 1; i <= t; ++i) solve(); cerr << "Time taken: " << ((clock() * 1000) / CLOCKS_PER_SEC) << "ms\n"; } const long long int N = 2e5 + 2; long long int t...
10
CPP
def sumsegtree(l,seg,st,en,x): if st==en: seg[x]=l[st] else: mid=(st+en)>>1 sumsegtree(l,seg,st,mid,2*x) sumsegtree(l,seg,mid+1,en,2*x+1) seg[x]=seg[2*x]+seg[2*x+1] def query(seg,st,en,val,x): if st==en: return seg[x] mid=(st+en)>>1 if seg[2*x]>=val:...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; struct BIT { int n, N_MAX; vector<long long> v; BIT(int n) { this->n = n + 100; N_MAX = n; v.assign(n + 110, 0); } void upd(int p, int x) { while (p <= n) v[p] += x, p += p & -p; } long long que(int p) { long long ans = 0; while (p) ans...
10
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; const long long inf = 1e14; int n; long long a[maxn], ans[maxn]; struct SegmentTree { long long tr[maxn << 2], tag[maxn << 2]; void pushup(int rt) { tr[rt] = min(tr[rt << 1], tr[rt << 1 | 1]); } void build(int rt, int l, int r) { tag[rt]...
10
CPP
#include <bits/stdc++.h> using namespace std; inline long long read() { long long 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 << 3) + (x << 1) + (ch ^ '0'); ch = getchar(); } return x * f...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long BIT[N], s[N]; int n; int ans[N]; void update(int x, int delta) { for (; x <= n; x += x & -x) BIT[x] += delta; } long long query(int x) { long long sum = 0; for (; x > 0; x -= x & -x) sum += BIT[x]; return sum; } int searchNumber(long...
10
CPP
#include <bits/stdc++.h> using namespace std; template <class X, class Y> bool minimize(X &x, const Y &y) { X eps = 1e-9; if (x > y + eps) { x = y; return true; } else return false; } template <class X, class Y> bool maximize(X &x, const Y &y) { X eps = 1e-9; if (x + eps < y) { x = y; retu...
10
CPP
#include <bits/stdc++.h> using namespace std; long long n; long long s[200010]; long long a[200010]; long long cnt[200010]; long long p[200010]; long long lb(long long x) { return x & (-x); } void ins(int x, int y) { for (long long i = x; i <= n; i += lb(i)) { p[i] += y; } return; } long long gs(int x) { lo...
10
CPP
#include <bits/stdc++.h> using namespace std; long long dx[] = {1, 0, -1, 0}; long long dy[] = {0, 1, 0, -1}; long long gcd(long long x, long long y) { if (y == 0) return x; else return gcd(y, x % y); } long long expo(long long n, long long m, long long p) { long long r = 1; n = n % p; while (m > 0) {...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; long long arr[N]; int n; int lowbit(int x) { return x & -x; } void addv(int p, long long val) { while (p <= n) { arr[p] += val; p += lowbit(p); } } void add(int l, int r, long long val) { addv(l, val); addv(r + 1, -val); } long long g...
10
CPP
#include <bits/stdc++.h> using namespace std; struct Node { long long l, r, rt, lz, minn, maxx; } node[1008611]; long long a[200861], sum[400861]; long long ans[200861]; void build(long long l, long long r, long long rt) { long long mid = (l + r) / 2; node[rt].l = l, node[rt].r = r; node[rt].lz = 0; if (l == ...
10
CPP
#include <bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") const int MAXN = 2e5 + 20; const int SIZE = (1 << 19) + 20; long long s[MAXN]; int ans[MAXN]; struct Segment_tree { struct Node { int sl, sr; long long val; } tree[SIZE]; inline void update(int root) { tree[root].val = tree[(r...
10
CPP
from operator import add class Stree: def __init__(self, f, n, default, init_data): self.ln = 2**(n-1).bit_length() self.data = [default] * (self.ln * 2) self.f = f for i, d in init_data.items(): self.data[self.ln + i] = d for j in range(self.ln - 1, 0, -1): ...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; template <class T> bool tomin(T &x, T y) { return y < x ? x = y, 1 : 0; } template <class T> bool tomax(T &x, T y) { return x < y ? x = y, 1 : 0; } template <class T> void read(T &x) { char c; x = 0; int f = 1; while (c = getchar(), c < '0' || c > '9') if (c...
10
CPP
#include <bits/stdc++.h> using namespace std; long long int bit[200005]; int n; void update(int j, int x) { for (; j < 200005; j += j & (-j)) bit[j] += x; } long long int query(int j) { if (j == 0) return 0; long long int x = 0; for (; j > 0; j -= (j) & (-j)) x += bit[j]; return x; } int next_ele(long long in...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long mxN = 2e5 + 10; long long a[mxN], v[mxN]; long long N; long long ans[mxN]; void upd(long long x, long long v) { for (long long i = x; i <= N; i += i & -i) a[i] += v; } long long sum(long long x) { long long S = 0; for (long long i = x; i; i -= i & -i) ...
10
CPP
_ = input() x = [int(i) for i in input().split()] res = [] from math import log class SegmentTree(object): def __init__(self, nums): self.arr = nums self.l = len(nums) self.tree = [0] * self.l + nums for i in range(self.l - 1, 0, -1): self.tree[i] = self.tree[i << 1]...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; long long n; class fenwicktree { public: long long n; long long b[200005]; fenwicktree(long long N) { n = N; for (long long i = 0; i <= n; i++) b[i] = 0; } long long sum(long long idx) { long long ret = 0; for (idx; idx > 0; idx -= (idx & -idx)) r...
10
CPP
#include <bits/stdc++.h> const int N = 1e6 + 10; const long long int INF = 1e18; const int MOD = 998244353; const int lgN = 20; using namespace std; long long int tree[4 * N], lz[4 * N], v[N], w[N]; void build(int node, int st, int en) { lz[node] = 0; if (st == en) { tree[node] = v[st]; return; } int m ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 200004; long long s[N], p[N]; int n, a[N]; void add(int x, int v) { for (int i = x; i <= n; i += (i & -i)) s[i] += v; } long long que(int x) { long long ans = 0; for (int i = x; i; i -= (i & -i)) ans += s[i]; return ans; } int main() { scanf("%d", &n...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long N = 2 * 1e5 + 3; const long long INF = INT_MAX; const long long NEINF = INT_MIN; const long long MOD = 1e9 + 7; long long Add(long long x, long long y) { return (x + y) % MOD; } long long Mul(long long x, long long y) { return (x * y) % MOD; } long long BinP...
10
CPP
#include <bits/stdc++.h> using namespace std; struct BigNum { vector<long long> value; void set(long long x) { value = *(new vector<long long>); value.push_back(x); } void duplicate(BigNum other) { value = other.value; } void add(BigNum other) { vector<long long> o = other.value; if (o.size() ...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long inf = 1e17; struct node { long long ans, sub; node() : ans(0), sub(0){}; }; struct SegmentTree { long long N; vector<node> st; vector<long long> a; long long left(long long p) { return p << 1; } long long right(long long p) { return (p << 1) + ...
10
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; ll n; ll a[200001]; ll sum[200001]; ll bit[200001]; ll p[200001]; template <typename T> inline T read() { T x = 0; T multiplier = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') { multiplier = -1; } ch = ...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 222222; int p[N], a[N], streee[N << 2]; long long s[N], stree[N << 2]; int n; void supdate(int x, int v, int l, int r, int pos) { if (l == r) { streee[pos] += v; return; } int m = l + (r - l) / 2; if (x <= m) { supdate(x, v, l, m, pos * 2 +...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const long long inf = 1e18; long long a[N], ans[N]; struct node { int l, r; long long lazy; long long v; }; node e[N * 5]; void build(int root, int l, int r) { e[root].l = l; e[root].r = r; e[root].lazy = e[root].v = 0; if (l == r) { ...
10
CPP
#include <bits/stdc++.h> using namespace std; vector<long long> s; vector<pair<long long, long long>> tree; void build(long long l, long long r, long long v) { if (r - 1 == l) { tree[v] = {s[l], l}; return; } long long m = (r + l) / 2; build(l, m, v * 2 + 1); build(m, r, v * 2 + 2); auto a = tree[v ...
10
CPP
#include <bits/stdc++.h> using namespace std; long long int a[200005]; pair<long long int, long long int> tree[4 * 200005]; long long int lazy[4 * 200005]; void build(long long int node, long long int st, long long int en) { if (st == en) { tree[node] = {a[st], st}; return; } long long int mid = (st + en)...
10
CPP
#include <bits/stdc++.h> using namespace std; inline long long read() { long long s = 0, w = 1; char ch = getchar(); while (!isdigit(ch)) { if (ch == '-') w = -1; ch = getchar(); } while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar(); return s * w; } inline void write(long long x) { if (x < 0...
10
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; const int maxN = 1e6 + 10; ll tree[4 * maxN]; int n, p[maxN]; ll s[maxN]; void update(int x, int l, int r, int k, int w) { if (l == r) tree[x] = w; else { int mid = (l + r) / 2; if (k <= mid) update(2 * x, ...
10
CPP
#include <bits/stdc++.h> using namespace std; long long n, m, q, x, k, t, y, w = 2, z, a[200500], ans[200500], bit[400500]; long long get(int i) { long long ret = 0; while (i) ret += bit[i], i -= (i & -i); return ret; } void update(int i, int val) { while (i <= 2 * n) bit[i] += val, i += (i & -i); } int main() ...
10
CPP
#include <bits/stdc++.h> using namespace std; template <typename T> class fenwick { public: vector<T> fenw; int n; fenwick(int _n) : n(_n) { fenw.resize(n); } void modify(int x, T v) { while (x < n) { fenw[x] += v; x |= (x + 1); } } T get(int x) { T v{}; while (x >= 0) { v...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long INF = 1e16 + 5; const int N = 1e6 + 5; long long first[N]; long long lazy[N] = {0}; long long s[N]; int ans[N]; void pull(int v) { first[v] = min(first[2 * v + 1], first[2 * v + 2]); } void apply(int v, long long val) { first[v] += val; lazy[v] += val; }...
10
CPP