solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#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];...
11
CPP
#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...
11
CPP
#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...
11
CPP
import bisect def getsum(tree , i): s = 0 i += 1 while i>0: s += tree[i] i -= i & (-i) return s def updatebit(tree , n , i , v): i+= 1 while i <= n: tree[i] += v i += i & (-i) n = int(input()) x = list(map(int , input().split())) v = list(map(int , input().spli...
12
PYTHON3
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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) ...
12
CPP
#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...
12
CPP
#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) { ...
12
CPP
import io import os from collections import Counter, defaultdict, deque, namedtuple # From: https://github.com/cheran-senthil/PyRival/blob/master/pyrival/data_structures/SegmentTree.py class SegmentTree: def __init__(self, data, default=0, func=max): """initialize the segment tree with data""" sel...
12
PYTHON3
import sys,math,itertools from collections import Counter,deque,defaultdict from bisect import bisect_left,bisect_right from heapq import heappop,heappush,heapify, nlargest from copy import deepcopy mod = 10**9+7 INF = float('inf') def inp(): return int(sys.stdin.readline()) def inpl(): return list(map(int, sys.stdin....
12
PYTHON3
#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 ...
12
CPP
#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...
12
CPP
#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 +=...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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, ...
12
CPP
#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 ...
12
CPP
#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) ...
12
CPP
#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...
12
CPP
#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 = ...
12
CPP
#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') { ...
12
CPP
#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 < ...
12
CPP
#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...
12
CPP
#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 |= ...
12
CPP
#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) { ...
12
CPP
import sys input = sys.stdin.readline from heapq import heappush, heappop, heapify def query(f, i): ret = 0 while i: ret += f[i] i -= (i & -i) return ret def update(f, i, d): n = len(f) while i < n: f[i] += d i += (i & -i) n = int(input()) x = list(map(int, input(...
12
PYTHON3
#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 ...
12
CPP
#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...
12
CPP
#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 & -...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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 (...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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 ...
12
CPP
#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 ...
12
CPP
#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 ...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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; ...
12
CPP
#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 ...
12
CPP
#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]...
12
CPP
#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...
12
CPP
#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, ...
12
CPP
#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...
12
CPP
#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....
12
CPP
#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...
12
CPP
#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 ...
12
CPP
import sys input = sys.stdin.readline from heapq import heappush, heappop, heapify def query(f, i): ret = 0 while i: ret += f[i] i -= (i & -i) return ret def update(f, i, d): n = len(f) while i < n: f[i] += d i += (i & -i) n = int(input()) X = list(map(int, input(...
12
PYTHON3
#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,...
12
CPP
#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 -=...
12
CPP
import sys, math import io, os #data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #from bisect import bisect_left as bl, bisect_right as br, insort #from heapq import heapify, heappush, heappop from collections import defaultdict as dd, deque, Counter #from itertools import permutations,combinations def data()...
12
PYTHON3
#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...
12
CPP
#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...
12
CPP
#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,...
12
CPP
from bisect import bisect_right, bisect_left # instead of AVLTree class BITbisect(): def __init__(self, InputProbNumbers): # 座圧 self.ind_to_co = [-10**18] self.co_to_ind = {} for ind, num in enumerate(sorted(list(set(InputProbNumbers)))): self.ind_to_co.append(num) ...
12
PYTHON3
#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}; ...
12
CPP
#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...
12
CPP
import sys input = sys.stdin.readline import bisect def query(f, i): ret = 0 while i: ret += f[i] i -= (i & -i) return ret def update(f, i, d): n = len(f) while i < n: f[i] += d i += (i & -i) n = int(input()) X = list(map(int, input().split())) V = list(map(int, in...
12
PYTHON3
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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] ...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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...
12
CPP
#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() ...
12
CPP
#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 | ...
12
CPP
#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...
12
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 5e5 + 10, MAXM = 2e6 + 10; const int INF = INT_MAX, SINF = 0x3f3f3f3f; const long long llINF = LLONG_MAX; const int MOD = 1e9 + 7, mod = 998244353; long long tr[MAXN], tot, n, t[MAXN]; void add(int x, long long val) { while (x <= n) { tr[x] += val; ...
12
CPP
import sys input = sys.stdin.readline import bisect def query(f, i): ret = 0 while i: ret += f[i] i -= (i & -i) return ret def update(f, i, d): n = len(f) while i < n: f[i] += d i += (i & -i) n = int(input()) X = list(map(int, input().split())) V = list(map(int, in...
12
PYTHON3
#include <bits/stdc++.h> using namespace std; int b[200005], m; long long c[200005][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 x, int k) { long long ret = 0; for (int i ...
12
CPP
#include <bits/stdc++.h> using namespace std; const long long mx = 105; const long long mod = 1000000007; const long long maxn = 1e17; vector<long long> v1; vector<long long> v2; long long get(long long x, long long vt) { long long i, j, k; long long res = 0; for (i = x; i > 0; i -= (i & -i)) { if (vt == 1) {...
12
CPP
#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...
12
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5; int m; long long val[maxn + 11]; int cnt[maxn + 11]; pair<int, int> p[maxn + 11]; vector<int> v; int lowbit(int x) { return x & (-x); } void add(int x, int o) { for (; x <= m; x += lowbit(x)) { cnt[x] += 1; val[x] += o; } } pair<int, long l...
12
CPP
#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...
12
CPP
#include <bits/stdc++.h> using namespace std; long long BIT[200009][4], N = 200009, n, ans, I; struct st { long long x, v; } a[200009]; bool cmp(st a, st b) { if (a.v == b.v) return a.x > b.x; return a.v > b.v; } bool cmp2(st a, st b) { if (a.v == b.v) return a.x > b.x; return a.v > b.v; } set<long long> s; m...
12
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; pair<int, int> p[N]; struct fenwick { long long fen[N]; void add(int first, int d) { for (int i = first + 1; i < N; i += i & -i) { fen[i] += d; } } long long sum(int first) { long long ans = 0; for (int i = first + 1; i; ...
12
CPP
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long>> t; pair<long long, long long> get(long long v, long long l, long long r, long long a, long long b) { if (l > b || a > r) { return {0, 0}; } if (a <= l && r <= b) { return t[v]; } long long m...
12
CPP
class BIT(): def __init__(self, array): self.n = len(array) self.bit = [0] + array self.build() def build(self): for i in range(1, self.n): if i + (i & -i) > self.n: continue self.bit[i + (i & -i)] += self.bit[i] def _sum(self, i): ...
12
PYTHON3
#include <bits/stdc++.h> using namespace std; int b[200005], m; long long c[200005][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 x, int k) { long long ret = 0; for (int i ...
12
CPP
#include <bits/stdc++.h> using namespace std; struct segtree { long long int M = 1, INIT; vector<long long int> dat; segtree(long long int N, long long int num) { INIT = num; while (M < N) M *= 2; for (int i = 0; i < M * 2 - 1; i++) dat.push_back(num); } void update(long long int x, long long int ...
12
CPP
#include <bits/stdc++.h> using namespace std; vector<vector<pair<long long, long long>>> mt(4 * 200005); vector<pair<long long, long long>> a; void buildTree(long long idx, long long second, long long se) { if (second == se) { mt[idx].push_back({a[second].second, a[second].first}); return; } long long mid...
12
CPP
#include <bits/stdc++.h> using namespace std; int num[800005], m; long long b[200005], sum[200005], cnt[200005], tr[800005]; 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; } void build(int l, int r, int ...
12
CPP
#include <bits/stdc++.h> using namespace std; template <class T> class BIT { private: vector<T> dat; int n; public: BIT(int _n) : dat(_n + 1), n(_n) {} T sum(int i) { T s = 0; while (i > 0) s += dat[i], i -= i & -i; return s; } T sum(int l, int r) { return l > r ? 0 : sum(r) - sum(l - 1); } ...
12
CPP
#include <bits/stdc++.h> using namespace std; int n; long long bit[200005][2]; void update(int x, long long val) { for (int i = x; i <= n; i += (i & -i)) bit[i][0] += val; for (int i = x; i <= n; i += (i & -i)) bit[i][1] += 1; } pair<long long, long long> query(int x) { long long ret1 = 0; long long ret2 = 0; ...
12
CPP
#include <bits/stdc++.h> using namespace std; map<int, int> mp; set<int> st; set<int>::iterator it; pair<int, int> arr[200005]; pair<long long, long long> tree[4 * 200005]; void update(int node, int b, int e, int i, long long v) { if (b > i || e < i) return; if (b == e && b == i) { tree[node].first += v; tr...
12
CPP
#include <bits/stdc++.h> using namespace std; struct node { int loc, v; } a[200010]; int n, m, b[200010]; long long c[200010], e[200010]; int cmp(node a, node b) { return a.loc < b.loc; } int lowbit(int x) { return x & -x; } void update(int pos, int delta, long long *d) { for (int i = pos; i <= n; i += lowbit(i)) d...
12
CPP
#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...
12
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fll; const int MAX = 2e5 + 10; vector<pair<int, int>> v(MAX); vector<int> spdv(MAX), compress(MAX); long long n, bit[2][MAX]; void poe(int a, long long x, long long p) { for (; p <= n; p += p & -p) bit[a]...
12
CPP
#include <bits/stdc++.h> using namespace std; long long ts[(int)8e5 + 10], tc[(int)8e5 + 10], n; pair<long long, long long> o[(int)2e5 + 10]; void update(long long i, long long v, long long t = 1, long long nl = 1, long long nr = n) { if (i < nl || nr < i) return; if (nl == nr) { ts[t] += v; tc[...
12
CPP
#include <bits/stdc++.h> using namespace std; int dx[4] = {1, -1, 0, 0}; int dy[4] = {0, 0, 1, -1}; long long gcd(long long a, long long b) { for (; b; a %= b, swap(a, b)) ; return a; } const int N = 200002; pair<long long, long long> segTree[N * 4]; vector<long long> vIdx; void update(int ptr, int s, int e, in...
12
CPP
#include <bits/stdc++.h> using namespace std; template <class T> using minheap = priority_queue<T, vector<T>, greater<T>>; template <typename T> void setmax(T& a, T b) { a = max(a, b); }; template <typename T> void setmin(T& a, T b) { a = min(a, b); }; template <typename T> bool in(T v, T lo, T hi) { return lo <=...
12
CPP