solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; long long int n, bit1[200050], bit2[200050]; vector<pair<long long int, long long int> > arr(200050); map<long long int, long long int> mp; long long int get1(int idx) { long long int ans = 0; while (idx > 0) { ans += bit1[idx]; idx -= (idx & -idx); } return...
12
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; pair<int, int> p[N]; long long sum[N]; long long ans = 0; int n; pair<long long, long long> tree[N]; inline int lowbit(int x) { return x & (-x); } void update(int x, int v) { while (x <= n) { tree[x].first++; tree[x].second += v; x += lo...
12
CPP
#include <bits/stdc++.h> using namespace std; mt19937_64 mt_rnd_64(chrono::steady_clock::now().time_since_epoch().count()); long long rnd(long long l, long long r) { return (mt_rnd_64() % (r - l + 1)) + l; } using ll = long long; using ld = long double; using ull = unsigned long long; const double PI = acos(-1.0); co...
12
CPP
import operator import collections from sys import stdin N = int(input()) pos = list(map(int, stdin.readline().split())) speed = list(map(int, stdin.readline().split())) A = [] for i in range(N): A.append((pos[i], speed[i])) # organized A by position from least to greatest # We want to count, at each x_i, the n...
12
PYTHON3
#include <bits/stdc++.h> using namespace std; long long n; pair<long long, long long> a[200001]; long long cnt[200001], sum[200001]; void update(long long x, long long val) { for (; x <= 200000; x += x & (-x)) { cnt[x]++; sum[x] += val; } } long long query(long long x, long long val) { long long ans = 0; ...
12
CPP
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long>> t[2 * 200004]; vector<long long> tpre[2 * 200004]; long long ans = 0; int cntlo = 0, cnthi = 0; void build(int n) { for (int i = n - 1; i > 0; i--) merge(t[i << 1].begin(), t[i << 1].end(), t[i << 1 | 1].begin(), t[i << 1 |...
12
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int n; long long ans = 0; vector<long long> T1(N, 0), T2(N, 0); pair<int, int> a[N]; vector<int> b; void update(vector<long long>& T, int x, long long v) { for (; x <= (int)b.size(); x += (x & (-x))) T[x] += v; } long long get(const vector<long long...
12
CPP
#include <bits/stdc++.h> using namespace std; const long long N = 200005; long long n; pair<long long, long long> x[N]; long long ans; struct seg { long long vals[2 * N]; long long q(long long l, long long r) { long long ret = 0; for (l += n, r += n; l < r; l >>= 1, r >>= 1) { if (l & 1) ret += vals[l...
12
CPP
#include <bits/stdc++.h> using namespace std; struct seg { vector<long long> tree; int n; seg(int n) { tree = vector<long long>(n); for (int i = 0; i < n; i++) tree[i] = 0; } void update(int node, int l, int r, int x, int y) { if (l > r) return; if (x > r || x < l) return; if (l == x && r ...
12
CPP
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n; long long ans; pair<long long, long long> a[N]; bool cmp(pair<long long, long long> x, pair<long long, long long> y) { if (x.second != y.second) { return x.second < y.second; } else { return x.first < y.first; } } vector<long long>...
12
CPP
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long> > v; vector<long long> v1; long long a[200005], b[200005], c[200005], d[200005], n, m; map<long long, long long> mp; long long get(long long f[], long long pos) { long long res = 0; for (; pos >= 0; pos = (pos & (pos + 1)) - 1) res += f...
12
CPP
#include <bits/stdc++.h> using namespace std; template <class c> struct rge { c b, e; }; template <class c> rge<c> range(c i, c j) { return rge<c>{i, j}; } template <class c> auto dud(c* x) -> decltype(cerr << *x, 0); template <class c> char dud(...); struct debug { template <class c> debug& operator<<(const c&...
12
CPP
#include <bits/stdc++.h> using namespace std; int dx[8] = {0, 0, 1, 1, 1, -1, -1, -1}; int dy[8] = {1, -1, -1, 0, 1, -1, 0, 1}; long long bit[1000005], bit1[1000005]; long long sum(long long x) { long long s = 0; while (x > 0) { s += bit[x]; x -= (x & (-x)); } return s; } void update(long long x, long l...
12
CPP
#include <bits/stdc++.h> using namespace std; bool test_cases_exist = false; class FenwickTree { public: vector<long long int> tree; long long int n; FenwickTree(long long int n) { this->n = n; tree.resize(n + 5); } void update(long long int ind, long long int delta) { while (ind <= n) { tr...
12
CPP
#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(int 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 = x; i...
12
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 1000; pair<long long, long long> p[maxn]; vector<long long> v; int getpos(long long V) { return lower_bound(v.begin(), v.end(), V) - v.begin() + 1; } long long C1[2][maxn]; long long C2[2][maxn]; void add(int x, long long K, long long C[][maxn], int...
12
CPP
#include <bits/stdc++.h> using namespace std; struct Scanner { bool hasNext = 1; bool hasRead = 1; int nextInt() { hasRead = 0; int res = 0; char flag = 1, ch = getchar(); while (ch != EOF && !isdigit(ch)) { hasRead = 1; flag = (ch == '-') ? -flag : flag; ch = getchar(); } ...
12
CPP
#include <bits/stdc++.h> using namespace std; template <typename T> using pr = pair<T, T>; const int mod = 1e9 + 7; struct SegTree { vector<pr<long long>> segtree; long long N; SegTree(long long n) { N = 1; while (N < n) N <<= 1; segtree = vector<pr<long long>>(2 * N); } void modify(long long k, l...
12
CPP
#include <bits/stdc++.h> using namespace std; template <typename T> struct BIT { int n; vector<T> bit; BIT(int n_ = 0) : n(n_), bit(n_ + 1) {} T sum(int i) { T ans = 0; for (; i > 0; i -= i & -i) ans += bit[i]; return ans; } void add(int i, T a) { if (i == 0) return; for (; i <= n; i += ...
12
CPP
def main(): import sys input = sys.stdin.readline class Bit: def __init__(self, n): self.size = n self.tree = [0] * (n + 1) def sum(self, i): s = 0 while i > 0: s += self.tree[i] i -= i & -i retur...
12
PYTHON3
import bisect class ft: def __init__(self,n): self.a = [0]*(200000) self.n = n def qry(self,r): ret = 0 while r>=0: ret+=self.a[r] r=(r&(r+1))-1 return ret def upd(self,i,v): while i<self.n: self.a[i]+=v i=(i|(i+...
12
PYTHON3
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; struct FTDown { long long ft[N + 5]; FTDown() { for (int i = 1; i <= N; i++) ft[i] = 0; } void update(int p, long long v) { for (; p <= N; p += (p & -p)) ft[p] += v; } long long get(int p) { long long sum = 0; for (; p; p -...
12
CPP
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 1000; const long long M = 1e5 + 10; const long long inf = 1e9 + 7; const long long Mod = 1e9 + 7; const double eps = 1e-6; int T; pair<int, int> a[N]; int b[N]; int n; pair<long long, long long> sg[4 * N]; void build(int k, int l, int r) { if (l ...
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; int n, T; long long cnt[200010], sum[200010]; pair<int, int> a[200010]; long long getval(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(long long f[], int pos, int val) { pos++; for...
12
CPP
#include <bits/stdc++.h> using namespace std; int n; const int maxn = 2e5 + 10; inline int lowbit(int x) { return x & (-x); } struct point { int x, v; } p[maxn]; int v[maxn]; long long c1[maxn], c2[maxn]; bool comp(point a, point b) { return a.x < b.x; } long long getnum(long long c[], int i) { long long res = 0LL;...
12
CPP
#include <bits/stdc++.h> using namespace std; using namespace std; long long st[800001], st2[800001]; vector<long long> vx[200001], idxs[200001]; long long getMid(long long s, long long e) { return s + (e - s) / 2; } long long SumUtil(long long* st, long long ss, long long se, long long l, long long r...
12
CPP
#include <bits/stdc++.h> using namespace std; template <class Ch, class Tr, class Container> basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& os, Container const& x) { os << "{ "; for (auto& y : x) os << y << " "; return os << "}"; } template <class X, class Y> ostream& o...
12
CPP
#include <bits/stdc++.h> using namespace std; vector<vector<long long> > mtree, msum, mpos; void merge_sort(vector<pair<long long, long long> >& arr, long long l, long long h, long long id) { long long m = (l + h) / 2; if (l == h) { mtree[id].push_back(arr[l].second); msum[id].push_back(arr[...
12
CPP
from operator import itemgetter class BIT():#1-indexed def __init__(self, size): self.table = [0 for _ in range(size+2)] self.size = size def Sum(self, i):#1からiまでの和 s = 0 while i > 0: s += self.table[i] i -= (i & -i) return s def PointAdd(self, i, x):# while i <= self.size: self.table[i] += x ...
12
PYTHON3
#include <bits/stdc++.h> using namespace std; int b[200005], cnt[200005], num[800005], m; long long sum[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
import sys input = sys.stdin.readline n=int(input()) X=list(map(int,input().split())) V=list(map(int,input().split())) XV=[(X[i],V[i]) for i in range(n)] #compression_dict_x={a: ind for ind, a in enumerate(sorted(set(X)))} compression_dict_v={a: ind+2 for ind, a in enumerate(sorted(set(V)))} XV=[(XV[i][0], compress...
12
PYTHON3
#include <bits/stdc++.h> using namespace std; const int INF = 1e9; void update(vector<long long>& v, long long ind, long long val) { ind++; long long n = v.size(); while (ind <= n) { v[ind] += val; ind += ((ind) & (-ind)); } } long long query(vector<long long>& v, long long ind) { ind++; long long r...
12
CPP
#include <bits/stdc++.h> using namespace std; pair<int, long long> a[200005]; int t[200005]; map<int, int> M; pair<int, long long> f[200005]; int n; void update(int gt) { int x = M[gt]; while (x <= n) { f[x] = {f[x].first + 1, f[x].second + gt}; x += (x & -x); } } pair<int, long long> get(int x) { int c...
12
CPP
#include <bits/stdc++.h> using namespace std; template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cerr << name << " : " << arg1 << '\n'; } template <typename Arg1, typename... Args> void __f(const char* names, Arg1&& arg1, Args&&... args) { const char* comma = strchr(names + 1, ','); cerr.write(nam...
12
CPP
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; const long long INF = 1e18; const int maxn = 1e6 + 6; const int mod = 1e9 + 7; const double eps = 1e-9; inline bool read(long long &num) { char in; bool IsN = false; in = getchar(); if (in == EOF) return false; while (in != '-' && (in < '0'...
12
CPP
import math import sys from collections import defaultdict, Counter from itertools import groupby #input = sys.stdin.readline rt = lambda: map(int, input().split()) ri = lambda: int(input()) rl = lambda: list(map(int, input().split())) class Bit: def __init__(self, n): self.size = n self.tree = [...
12
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5; long long Bit[N][2], n; long long get(long long i, long long k) { long long ans = 0; for (i; i > 0; i -= i & (-i)) { ans += Bit[i][k]; } return ans; } void update(long long i, long long val, long long k) { for (i; i <= n; i += i & ...
12
CPP
#include <bits/stdc++.h> using namespace std; const int64_t INF = (int64_t)(2e18); const int64_t inf = (int64_t)(1e9 + 7); struct stree { vector<int64_t> t; int64_t n = 1; stree() {} stree(int64_t nn) { while (n < nn) n *= 2; t.assign(2 * n, 0); } void set(int64_t i, int64_t x) { t[i += n] += x;...
12
CPP
#include <bits/stdc++.h> using namespace std; template <class T> bool uin(T& a, T b) { return a > b ? (a = b, true) : false; } template <class T> bool uax(T& a, T b) { return a < b ? (a = b, true) : false; } template <typename T> class fenwick { public: vector<T> fenw; int n; fenwick(int _n) : n(_n) { fenw.r...
12
CPP
#include <bits/stdc++.h> using namespace std; template <typename Monoid> struct SegmentTree { typedef function<Monoid(Monoid, Monoid)> F; int n; F f; Monoid id; vector<Monoid> dat; SegmentTree(int n_, F f, Monoid id) : f(f), id(id) { init(n_); } void init(int n_) { n = 1; while (n < n_) n <<= 1; ...
12
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 3; const int maxm = 1e6 + 3; const int mod = 1e9 + 7; const int oo = 1e9 + 5; const long double pi = 3.141592653589793238462643383279502884; void input() { if (fopen("abc" ".inp", "r")) { freopen( "abc" "....
12
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; ll ftget(vector<ll> &ft, ll idx) { ll ans = 0; while (idx > 0) { ans += ft[idx]; idx -= (idx & (-idx)); } return ans; } void ftput(vector<ll> &ft, ll idx, ll value) { while (idx < ft.size()) { ft[idx] += value; idx += (idx & (...
12
CPP
# -*- coding: utf-8 -*- import sys from collections import Counter def input(): return sys.stdin.readline().strip() def list2d(a, b, c): return [[c] * b for i in range(a)] def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)] def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for...
12
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long int inf = 1e18, M = 1e9 + 7; const long long int N = 2e5 + 10; vector<pair<long long int, long long int> > tree(4 * N, make_pair(0, 0)); map<long long int, long long int> mp; pair<long long int, long long int> combine( pair<long long int, long long int> ...
12
CPP
#include <bits/stdc++.h> using namespace std; const int M = 200005; int n, m, w[M]; long long ans, c[M][2]; struct node { int x, v; } p[M]; bool cmp(node a, node b) { return a.x < b.x; } long long query(int x, int t) { long long r = 0; for (int i = x; i; i -= i & -i) r += c[i][t]; return r; } void upd(int x, in...
12
CPP
#include <bits/stdc++.h> using namespace std; int n, op; pair<long long, int> tree[201000]; pair<long long, int> q[201000]; long long a[201000]; int lowbits(int x) { return x & (-x); } void add(long long x, int pos) { while (pos <= n) { tree[pos].first += x; tree[pos].second++; pos += lowbits(pos); } } ...
12
CPP
class Fenwick: def __init__(self, size): self.tree = [0] * size self.size = size def add(self, idx, delta): while idx < self.size: self.tree[idx] += delta idx = (idx + 1) | idx def getp(self, right): res = 0 while right != -1: res +...
12
PYTHON3
#include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("no-stack-protector") using namespace std; const int inf = 1e9 + 7; const int max_n = 2e5 + 1; struct fenwick { vector<int> sum; fenwick(int n) { sum.clear(); sum.resize(n, 0); } int f(int v) { return (v & (v + 1)); } int h(int v...
12
CPP
#include <bits/stdc++.h> using rmain = int; using namespace std; long long n; vector<pair<long long, long long>> points; vector<long long> v, cnt, xs; long long LSOne(long long k) { return (k & (-k)); } void update(vector<long long>& f, long long pos, long long val) { for (; pos <= n; pos += LSOne(pos)) f[pos] += val...
12
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const long long mod = 998244353; int T, n; struct node { long long d, v; friend bool operator<(node a, node b) { return a.d < b.d; } } a[maxn]; long long c[maxn], d[maxn]; int b[maxn]; void update(int x, int y) { for (int i = x; i <= n; i += ...
12
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; pair<int, int> p[N]; long long cnt[N << 2], val[N << 2]; void update(int a, int b, int l, int r, int rt, int v) { if (a <= l && b >= r) { val[rt] += v, cnt[rt]++; return; } int mid = l + r >> 1; if (a <= mid) update(a, b, l, mid, rt <<...
12
CPP
def add(sms, cns, n, v, x): while v < n: sms[v] += x cns[v] += 1 v += v & ~(v - 1) def sumtoo(sms, cns, v): sm = 0 cn = 0 while v > 0: sm += sms[v] cn += cns[v] v -= v & ~(v - 1) return sm,cn def go(): n = int(input()) x = list(map(int, inpu...
12
PYTHON3
#include <bits/stdc++.h> using namespace std; struct fenwick { long long N; vector<long long> Bit; fenwick(long long n = 1e5) { N = n; n += 5; Bit.resize(n, 0); } void update(long long id, long long val) { while (id <= N) { Bit[id] += val; id += id & -id; } } long long quer...
12
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; const int MOD = 1e9 + 7; template <class T> bool umin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template <class T> bool umax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template <class T> bool um...
12
CPP
#include <bits/stdc++.h> using namespace std; void FastInputOutput() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); } inline int D() { int t; scanf("%d", &t); return t; } inline long long LLD() { long long t; scanf("%lld", &t); return t; } long long gcd(long long a, long long b) { return b ...
12
CPP
#include <bits/stdc++.h> using namespace std; const int kMaxN = 200001; struct E { int x, v, w; bool operator<(const E &e) const { return x < e.x; } } e[kMaxN]; struct T { long long c, v; } t[kMaxN]; int a[kMaxN]; int n; long long ans; int LowBit(int x) { return x & (-x); } void Calc(int x) { t[0] = {0, 0}; w...
12
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 200200; int n; long long ans, bit[2][MAXN]; pair<int, int> a[MAXN]; void compress() { map<int, int> m; for (int i = 1; i <= n; ++i) m[a[i].second]; int cnt = 1; for (auto& [key, val] : m) val = cnt++; for (int i = 1; i <= n; ++i) a[i].second = m[a...
12
CPP
#include <bits/stdc++.h> using namespace std; struct Pt { int x, v; bool operator<(const Pt &a) const { return x < a.x; } }; struct BIT { vector<long long> bit, cnt; int n; BIT(int sz) { bit.resize(sz + 1); cnt.resize(sz + 1); n = sz; } void add(int x, long long v) { while (x <= n) { ...
12
CPP
import sys int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def SI(): return sy...
12
PYTHON3
#include <bits/stdc++.h> using namespace std; const double PI = acos(-1.0); const double EPS = 1e-6; const int INF = 0x3f3f3f3f; const int MAXN = 200005; int n, m; int maps[MAXN]; long long sum[MAXN][2]; pair<long long, long long> node[MAXN]; inline long long lowbit(long long x) { return x & (-x); } void add(long long ...
12
CPP
#include <bits/stdc++.h> using namespace std; const int INF32 = 1E9; const long long INF64 = 4E18; const long long M = 1E9 + 7; const double EPS = 1E-9; const double PI = 2 * acos(0); vector<long long> suffix_sum(1E6); bool cmp_v(pair<long long, long long> a, pair<long long, long long> b) { return (a.second < b.secon...
12
CPP
#include <bits/stdc++.h> using namespace std; long long gcd(long long x, long long y) { if (!y) return x; return gcd(y, x % y); } const long long MOD = 1e9 + 7; int inf = 1e9 + 7; long long INF = 2e18 + 9; long long power(long long x, long long y) { long long res = 1ll; x %= MOD; if (x == 0) return 0; while...
12
CPP
#include <bits/stdc++.h> using namespace std; const double pi = acos(-1); const int N = 2e5 + 5, mod = 998244353, M = 1e7 + 7; const long long MAX = 5e18; int n; pair<int, int> a[N]; long long ans; struct BIT { long long s[N][2], sum[2]; void init() { memset(s, 0, sizeof s); sum[0] = sum[1] = 0; } void ...
12
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const int MX = 4e5 + 7; int n; long long c[MX][2]; int v[MX]; struct p { int x, v; inline bool operator<(const p& w) const { return x < w.x; } } a[MX]; inline int lowbit(int x) { return x & -x; } void add(int pos, long long k) { while (pos ...
12
CPP
#include <bits/stdc++.h> using namespace std; const long long N = 2e6 + 7; const long long INF = 1e18; long long n, k, q, st[N][2]; pair<long long, long long> p[N]; map<long long, bool> 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; r...
12
CPP
#include <bits/stdc++.h> using namespace std; const int N = 200005; struct { int l, r; long long sum; long long cnt; } A[N * 4]; pair<pair<long long, long long>, int> pt[N]; int n; bool cmp(pair<pair<long long, long long>, int> x1, pair<pair<long long, long long>, int> x2) { return x1.first.first < x2....
12
CPP
import sys input=sys.stdin.readline def getsum(BITTree,i): s = 0 while i > 0: s += BITTree[i] i -= (i & -i) return(s) def updatebit(BITTree , i ,v): while i <= len(BITTree): BITTree[i] += v i += (i & -i) #print(BITTree) n=int(input()) x=[int(i) for i in input()....
12
PYTHON3
#include <bits/stdc++.h> using namespace std; using ll = long long; using ii = pair<int, int>; constexpr int MAXN = 5 + 200000; struct Bit { ll b[MAXN]; Bit() { fill(b, b + MAXN, 0); } void upd(int x, ll val) { for (; x < MAXN; x += (x & -x)) b[x] += val; } ll query(int x) { ll ans = 0LL; for (; x...
12
CPP
#include <bits/stdc++.h> using namespace std; const int MAX_N = 100011; const long long INF = (1 << 29) + 123; const long long MOD = 1000000007; const long double PI = 4 * atan((long double)1); int fenw[2 * MAX_N]; int n; void mod(int i, int v) { while (i <= n) { fenw[i] += v; i += i & -i; } } int query(int...
12
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; struct nod { long long x, v; } a[maxn]; bool cmp(nod p, nod q) { return p.x < q.x; } int L = 0, R = 2e8, rt = 0, tot = 0; class dsegtree { public: struct dsegnode { int l, r; long long sum1, sum2; } node[maxn * 50]; void pushup(int...
12
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5; int N; pair<long long, long long> A[MAXN + 10]; long long ans; vector<long long> comp; long long tree1[MAXN + 10]; void update1(int i, long long v) { for (; i <= N; i += (i & -i)) tree1[i] += v; } long long query1(int i) { long long ret = 0; for ...
12
CPP
import math import bisect class Fenwick: def __init__(self, n): self.data = [[0,0] for i in range(n)] def update(self, pos, dist): while pos<len(self.data): self.data[pos][0] += 1 self.data[pos][1] += dist pos = pos | (pos+1) def query(self, p...
12
PYTHON3
#include <bits/stdc++.h> using namespace std; long long int ans = 0; void merger(vector<pair<long long int, long long int> > &v, long long int l, long long int mid, long long int r) { long long int n1 = mid - l + 1, n2 = r - mid; pair<long long int, long long int> larr[n1], rarr[n2]; long long int lsu...
12
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n, m, pos, v[N]; long long tot, s[N][2]; struct node { long long x, v; } a[N]; bool cmp(node x, node y) { return x.x < y.x; } int lowbit(int x) { return x & (-x); } void update(int x, int val) { while (x <= n) { s[x][0]++; s[x][1] += v...
12
CPP
#include <bits/stdc++.h> using namespace std; 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 |= pos + 1) { f[pos] += val; } } int...
12
CPP
#include <bits/stdc++.h> using namespace std; struct OrderSet { struct Trie { int cnt; int next[2]; Trie() { memset(next, -1, sizeof(next)); cnt = 0; } }; vector<Trie*> trie; OrderSet() { auto u = new Trie(); trie.push_back(u); } bool find(int first) { int cur = 0; ...
12
CPP
#include <bits/stdc++.h> using namespace std; 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 |= pos + 1) { f[pos] += val; } } int...
12
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 4e5 + 1000; pair<long long, long long> p[maxn]; vector<long long> v; int getpos(long long V) { return lower_bound(v.begin(), v.end(), V) - v.begin() + 1; } long long C[2][maxn]; void add(int x, long long K) { while (0 < x && x < maxn) { C[0][x] += 1...
12
CPP
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 10; const long long maxX = 2e8 + 10; long long n; long long sz = 1; pair<long long, long long> p[maxn]; long long segsum[25 * maxn]; long long segtedad[25 * maxn]; long long L[25 * maxn]; long long R[25 * maxn]; long long ans; void in(); void so...
12
CPP
#include <bits/stdc++.h> using namespace std; const long long INF = 1e9 + 7; const int N = 3e5 + 10; void init(vector<pair<int, int>>& vp) { vector<int> v; for (auto& p : vp) v.push_back(p.second); sort(v.begin(), v.end()); for (auto& p : vp) { p.second = lower_bound(v.begin(), v.end(), p.second) - v.begin(...
12
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; const int M = 2e3 + 5; const int mod = 1e9 + 7; const double eps = 1e-8; const double pi = acos(-1); template <class T> inline void read(T &x) { char c; x = 1; while ((c = getchar()) < '0' || c > '9') if (c == '-') x = -1; T res = c - '0';...
12
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int bit[N]; void add(int p, int v) { for (p += 2; p < N; p += p & -p) bit[p] += v; } long long query(int p) { int r = 0; for (p += 2; p; p -= p & -p) r += bit[p]; return r; } int n; pair<int, int> p[N]; long long l[N], r[N]; int ql[N], qr[N]; ...
12
CPP
#include <bits/stdc++.h> using namespace std; long long int g[800010][2]; void up(int l, int r, int n, int x, int i, long long int val) { if (l == r) { g[n][i] = val; } else { int mid = (l + r) / 2; if (x <= mid && x >= l) up(l, mid, 2 * n, x, i, val); else up(mid + 1, r, 2 * n + 1, x, i...
12
CPP
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,-O3") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; const int oo = 2e9; const long long OO = 4e18; const int md = 0x3b800001; co...
12
CPP
''' Hey stalker :) ''' INF = 10 ** 10 def main(): #print = out.append ''' Cook your dish here! ''' n = get_int() points = get_list() speeds = get_list() point_indexes = dict() sorted_indexes = dict() for i, ele in enumerate(points): point_indexes[ele] = i for i, ele in enum...
12
PYTHON3
#include <bits/stdc++.h> using namespace std; template <typename C> class fenwick { vector<C> t; int n; public: fenwick(int _n) : n(_n) { t.resize(n); } fenwick(const vector<C>& a) : n(a.size()) { t.resize(n); for (int i = 0; i < n; ++i) { upd(i, a[i]); } } C get(int k) { C res = 0; ...
12
CPP
#include <bits/stdc++.h> using namespace std; vector<long long> x, v; int idX(int val) { return (lower_bound(x.begin(), x.end(), val) - x.begin()); } int idV(int val) { return (lower_bound(v.begin(), v.end(), val) - v.begin()); } struct FenwickTree { vector<long long> bit; int n; FenwickTree(int n) { this->n ...
12
CPP
#include <bits/stdc++.h> using namespace std; struct FT { vector<long long> f; FT(long long n) { f.resize(n + 1, 0); } long long sum(long long r) { long long res = 0; for (; r >= 0; r = (r & (r + 1)) - 1) { res += f[r]; } return res; } long long sum(long long l, long long r) { return sum...
12
CPP
#include <bits/stdc++.h> #pragma GCC optimize("fast-math") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC diagnostic ignored "-Woverflow" using namespace std; const short INF16 = ~(1 << 15); const int INF32 = 2e9 + 11; const int SZ = (1 << 19); const int SZ2 = int(1e6 + 11); const int mo...
12
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = double; const ll MODBASE = 1000000007LL; const int MAXN = 200010; const int MAXM = 1000; const int MAXK = 16; const int MAXQ = 200010; struct Car { int x, v; Car(int x = 0, int v = 0) : x(x), v(v) {} }; bool operator<(Car a, Car b) { ret...
12
CPP
#include <bits/stdc++.h> using ll = long long; using namespace std; template <class T> class SegmentTree { private: int _size = 1; T _def; std::vector<T> _nodes; std::function<T(T, T)> _op; std::function<T(T, T)> _update_op; public: SegmentTree(int size, T default_value, std::function<T(T, T)> op, ...
12
CPP
#include <bits/stdc++.h> using namespace std; void transform(long long int a[], long long int n) { map<long long int, vector<long long int> > m; for (long long int i = 0; i < (n); i++) m[a[i]].push_back(i); long long int rank = 1; for (auto c : m) { for (auto i : c.second) a[i] = rank; rank++; } } con...
12
CPP
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 9; int n, a[MAX], speed[MAX], b[MAX]; int idx[MAX]; vector<pair<int, int> > v; unordered_map<int, int> startRange; long long tree[(MAX << 2)][2], val; int l, r, idxToUpd; void build(int id, int low, int high, int pos) { if (low == high) { tree[po...
12
CPP
#include <bits/stdc++.h> using namespace std; const int mx = 200005; long long bit[mx][2]; int arr[mx]; int speed[mx]; vector<pair<int, int> > vec; void update(int idx, int val) { for (int i = idx; i < mx; i += (i & -i)) { bit[i][0] += 1LL * val; bit[i][1]++; } } pair<long long, long long> query(int idx) { ...
12
CPP
#include <bits/stdc++.h> using namespace std; struct BIT { vector<long long int> bit; int n; BIT(long long int N) { n = N; bit.assign(n + 1, 0); } void add(int idx, int delta) { while (idx <= n) { bit[idx] += delta; idx += (idx & -idx); } } long long int sum(int idx) { long...
12
CPP
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e6 + 100, mod = 1e9 + 7, inf = 1e16 + 7; pair<long long, long long> a[maxn]; long long get(long long l, long long r) { if (r - l == 1) return 0; long long m = (r + l) / 2; long long ans = 0; ans += get(l, m); ans += get(m, r); long long p...
12
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = (int)2e5 + 100; const int mod = (int)1e9 + 7; int n, c[maxn]; long long ans; pair<int, int> a[maxn]; int main() { scanf("%d", &n); for (auto i = (1); i <= (n); ++i) scanf("%d", &a[i].second), c[i] = a[i].second; for (auto i = (1); i <= (n); ++i) s...
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 z, int p) { if ...
12
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int inf = 0x3f3f3f3f; const long long INF = 0x7f7f7f7f7f7f7f7f; const int mod = 1e9 + 7; const double PI = acos(-1.0); const double eps = 1e-5; int n; pair<long long, long long> a[maxn]; long long b[maxn]; long long s1[maxn], s2[maxn]; int lb...
12
CPP