text
stringlengths
49
983k
#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, ...
#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...
#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...
#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) { ...
#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...
#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...
#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...
#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 ...
#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...
#include <bits/stdc++.h> using namespace std; const long long mod = 1e9 + 7; const long long INF = 4e18 + 10; long long power(long long a, long long b, long long in_mod) { long long ans = 1; long long prod = a; while (b) { if (b % 2) ans = (ans * prod) % in_mod; prod = (prod * prod) % in_mod; b /= 2; ...
#include <bits/stdc++.h> using namespace std; const int Z = (int)1e3 + 228; const int N = (int)2e5 + 228; const int INF = (int)1e9 + 228; const int MOD = (int)998244353; const long long LLINF = (long long)1e18 + 228; const long double eps = (long double)1e-6; pair<long long, long long> t[4 * N]; void update(int v, int ...
#include <bits/stdc++.h> using namespace std; const int mxn = 2e5 + 100; pair<int, long long> a[mxn]; long long r[mxn], b1[mxn], b2[mxn], ans; void add(long long *b, int idx, int val, int n) { for (; idx <= n; idx += idx & -idx) b[idx] += val; } long long ask(long long *b, int idx) { long long ret = 0; for (; idx...
#include <bits/stdc++.h> using namespace std; long long ans, n, a1[202020], a2[202020], od[202020]; pair<long long, long long> p[202020]; map<long long, long long> mp; void gx1(long long x, long long v) { for (long long i = x; i < 200200; i += i & -i) { a1[i] += v; } } void gx2(long long x, long long v) { for...
#include <bits/stdc++.h> using namespace std; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1}; int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1}; vector<pair<long long int, long long int> > vec; int n; long long int tree[(int)(2 * 1e5 + 1)], tree2[(int)(2 * 1e5 + 1)]; void atualiza(i...
#include <bits/stdc++.h> using namespace std; struct hash_pair { template <class T1, class T2> size_t operator()(const pair<T1, T2>& p) const { auto hash1 = hash<T1>{}(p.first); auto hash2 = hash<T2>{}(p.second); return hash1 ^ hash2; } }; bool prime[10000001]; long long P = 1000000007 - 2; long long ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; long long int savev[maxn]; struct node { long long int x, v; node(){}; node(long long int x, long long int v) : x(x), v(v){}; bool operator<(const node& n) const { return x < n.x; } } save[maxn]; map<long long int, long long int> getv; lon...
#include <bits/stdc++.h> using namespace std; long long max(long long a, long long b) { return a > b ? a : b; } void swap(long long& a, long long& b) { long long tmp = a; a = b; b = tmp; } long long t, n; long long x[200006], v[200006]; pair<long long, long long> xv[200006]; long long prfxSum[200006]; pair<long l...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; struct Node { int x, v; bool operator<(const Node &rhs) const { return x < rhs.x; } } p[maxn]; int b[maxn], n, to; long long t[maxn], tt[maxn]; inline int lowbit(int x) { return x & -x; } void update(long long *t, int x, int v) { for (; x <=...
#include <bits/stdc++.h> using namespace std; void dout() { cerr << '\n'; } template <typename Head, typename... Tail> void dout(Head H, Tail... T) { cerr << " " << H; dout(T...); } mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int N = 2e5 + 7; int n, m, cnt[N]; long long sum[N]; pair<i...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int n; pair<int, int> a[maxn]; int m; vector<int> v; struct fenwick { long long val[maxn]; void init() { fill(begin(val), end(val), 0); } void upd(int x, int k) { for (; x < maxn; x += x & -x) val[x] += k; } long long get(int x) { ...
#include <bits/stdc++.h> using namespace std; int N; pair<signed long long, signed long long> P[202020]; pair<signed long long, signed long long> Q[202020]; template <class V, int ME> class BIT { public: V bit[1 << ME]; V operator()(int e) { if (e < 0) return 0; V s = 0; e++; while (e) s += bit[e -...
#include <bits/stdc++.h> using namespace std; bool comp(pair<long long, long long> p1, pair<long long, long long> p2) { if (p1.second == p2.second) return p1.first < p2.first; return p1.second < p2.second; } signed main() { long long n; cin >> n; vector<pair<long long, long long> > v(n); for (long long i = ...
#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...
#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 (long long i = 0; i < n; i++) { scanf("%lld", &o[i].second); } for (long long i = 0; i < n; i++) { scanf("%lld", &o[i].fir...
#include <bits/stdc++.h> using namespace std; const long long maxn = 200000 + 50; const long long LIM = 17; const long long INF = (long long)1e9 + 7; long long N; long long h[maxn]; long long sum[maxn << 1], cnt[maxn << 1]; struct node { long long x, v; } a[maxn]; bool cmp(const node& a, const node& b) { return a.x <...
#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...
#include <bits/stdc++.h> using namespace std; struct tree { tree* l; tree* r; long long sum; long long cnt; tree() { l = r = nullptr; sum = cnt = 0; } }* rt = new tree; tree* get_l(tree* v) { if (!v->l) { v->l = new tree; } return v->l; } tree* get_r(tree* v) { if (!v->r) { v->r = ne...
#include <bits/stdc++.h> using namespace std; const int MAX_SIZE = 200010; pair<int, int> arr[MAX_SIZE], backup[MAX_SIZE]; long long prefix[MAX_SIZE]; int N; void sortX(int l, int r) { if (l >= r) return; int mi = (l + r) / 2; sortX(l, mi); sortX(mi + 1, r); int i = l, j = mi + 1, k = l; while (i <= mi && j...
#include <bits/stdc++.h> int xx[200000], vv[200000]; int compare_v(const void *a, const void *b) { int i = *(int *)a; int j = *(int *)b; return vv[i] - vv[j]; } int compare_x(const void *a, const void *b) { int i = *(int *)a; int j = *(int *)b; return xx[i] - xx[j]; } void sort(int *ii, int n, int (*compare...
#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> bt[N]; pair<long long, long long> query(int first) { ...
#include <bits/stdc++.h> using namespace std; struct treap { treap* l = nullptr; treap* r = nullptr; long long int pos; long long int vel; long long int y; long long int sum; int ch; static long long int s(treap* A) { if (A == nullptr) return 0; return A->sum; } static int c(treap* A) { ...
#include <bits/stdc++.h> using namespace std; struct Node { int X, V; inline friend bool operator<(Node x, Node y) { if (x.V == y.V) { return x.X < y.X; } return x.V < y.V; } } p[200000]; map<int, int> A; set<int> B; int ct; long long c1[200001]; int c2[200001]; inline void Add(int x, int d) { ...
#include <bits/stdc++.h> using namespace std; long long n, m, ans[200005 << 2], tag[200005 << 2], cnt[200005 << 2], tagg[200005 << 2]; struct p { long long x, v, vv; } a[200005]; int cmp(p a, p b) { return a.v < b.v; } int cmpp(p a, p b) { return a.x < b.x; } inline long long ls(long long x) { return x << 1; } in...
#include <bits/stdc++.h> using namespace std; struct data { long long x, v, pos; } p[200005]; struct seg { long long val, cnt; } f[1000005]; long n; bool cmp(data a, data b) { if (a.v == b.v) return a.x < b.x; else return a.v < b.v; } bool cmp2(data a, data b) { return a.x < b.x; } void update(long id, ...
#include <bits/stdc++.h> using namespace std; long long int MOD = 100000007; long long int MX = 1000000000; long long int n; pair<long long int, long long int> a[200200]; map<long long int, long long int> sor; map<long long int, long long int> val; long long int tree[600005]; long long int lazy[600005]; long long int t...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f; long long fwk[maxn], cnt[maxn]; void upd(int p, int c) { for (; p < maxn; p += p & -p) fwk[p] += c, cnt[p]++; } void qry(int p, long long& sum, long long& c) { sum = c = 0; for (; p; p -= p & -p) sum += fwk[p...
#include <bits/stdc++.h> using namespace std; constexpr long long maxN = 2e5 + 43; long long n; vector<pair<long long, long long>> point; vector<long long> val, cnt, cval; 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 += LSOn...
#include <bits/stdc++.h> using namespace std; int MOD = 1000000000 + 7; long long int inverse(long long int i) { if (i == 1) return 1; return (MOD - ((MOD / i) * inverse(MOD % i)) % MOD + MOD) % MOD; } long long int calc(vector<pair<long long int, long long int>>& v1, int st, int fn) { if (fn -...
#include <bits/stdc++.h> #pragma GCC optimize(2) using namespace std; using ll = long long; using ull = unsigned long long; using pli = pair<ll, int>; using pii = pair<int, int>; constexpr ll mod = 1e9 + 7; constexpr int N = 200010; struct node { ll x; int v, id; bool operator<(const node &o) const { return x < o...
#include <bits/stdc++.h> using namespace std; const int M = 2e5 + 5; int n, t[M], k; long long ans; struct node { long long p; int v; } a[M]; struct BIT { long long s[M]; void add(int i, long long x) { for (; i <= k; i += i & -i) s[i] += x; } long long ask(int i) { long long res = 0; for (; i > ...
#include <bits/stdc++.h> using namespace std; int dx[] = {0, 0, 1, -1, -1, -1, 1, 1}; int dy[] = {1, -1, 0, 0, -1, 1, 1, -1}; template <class T> inline T biton(T n, T pos) { return n | ((T)1 << pos); } template <class T> inline T bitoff(T n, T pos) { return n & ~((T)1 << pos); } template <class T> inline T ison(T n...
#include <bits/stdc++.h> using namespace std; long long bit1[200005], bit2[200005]; inline void upd(long long idx, long long val, long long bit[]) { while (idx < 200005) { bit[idx] += val; idx += (idx & -idx); } } inline long long que(long long idx, long long bit[]) { long long ans = 0; while (idx > 0) ...
#include <bits/stdc++.h> using namespace std; long long n; pair<long long, long long> p[200005]; long long v[200005]; map<long long, long long> m; long long f0[200005]; long long f1[200005]; void up0(long long x, long long val) { for (long long i = x; i <= 200000; i += i & -i) f0[i] += val; } void up1(long long x, lo...
#include <bits/stdc++.h> int dr[] = {2, 2, -2, -2, 1, -1, 1, -1}; int dc[] = {1, -1, 1, -1, 2, 2, -2, -2}; int dr1[] = {0, 0, 1, 1, 1, -1, -1, -1}; int dc1[] = {1, -1, 1, 0, -1, 0, 1, -1}; int dr2[] = {0, 0, 1, -1}; int dc2[] = {1, -1, 0, 0}; using namespace std; long long a[200005]; long long dp[200005]; long long tr[...
#include <bits/stdc++.h> using namespace std; int tab_x[200000 + 5]; int tab_v[200000 + 5]; long long D_dist[550000 + 5]; int D_ile[550000 + 5]; int zakresy[550000 + 5][2]; int max_pot = 1; int QUERRY_ile(int L, int R, int w) { if (zakresy[w][0] > R || L > zakresy[w][1]) return 0; if (L <= zakresy[w][0] && zakresy[...
#include <bits/stdc++.h> using namespace std; const long long md = 1e9 + 7; const int xn = 2e5 + 10; const int xm = 5e5; const int SQ = 750; const int sq = 1e3 + 10; const long long inf = 1e18 + 10; long long power(long long a, long long b) { return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2) % md ...
#include <bits/stdc++.h> using namespace std; long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); } long long ppow(long long a, long long b, long long mod) { a %= mod; long long ans = 1; while (b) { if (b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return ans; } ...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 15; int tot = 1, N; const int L = -2e8; const int R = 2e8; struct Node { int l, r, num; long long sum; Node() { l = 0, r = 0, num = 0, sum = 0; } } E[maxn * 40]; struct Point { long long x, v; bool operator<(const Point &T) const { return x ...
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 10; const int MOD = 998244353; const int INF = 0x3f3f3f3f; struct Node { int x; int v; } a[MAXN]; bool cmp(Node a, Node b) { if (a.v == b.v) { return a.x < b.x; } return a.v < b.v; } int N, M; vector<int> dic; int main() { int now; l...
#include <bits/stdc++.h> using namespace std; void coordinatecompress(vector<int> &data) { int n = data.size(); vector<pair<int, int> > tempdata(n); for (int i = 0; i < n; i++) tempdata[i] = {data[i], i}; sort(tempdata.begin(), tempdata.end()); data[tempdata[0].second] = 0; for (int i = 1; i < n; i++) d...
#include <bits/stdc++.h> using namespace std; vector<pair<long long, long long>> v; long long arr[200005]; map<long long, long long> mp; map<long long, long long> rmp; pair<long long, long long> bit[200005]; set<long long> s; void insert(long long ind) { for (long long i = ind; i < 200005; i += i & -i) bit[i].fir...
#include <bits/stdc++.h> #pragma comment(linker, "/stack:200000000") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") using namespace std; using ll = long long; using ull = unsigned long long; using pii = pair<int, int>; using ...
#include <bits/stdc++.h> using namespace std; const long long mx = 2 * 1e5 + 5; const long long mod = 1e9 + 7; long long sum[mx]; long long num[mx]; void update(int pos, int value) { while (pos <= mx) { sum[pos] += value; num[pos]++; pos += (pos & -pos); } } pair<int, long long> query(int pos) { long ...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 10; struct node { long long a; long long t; } w[N]; bool cmp(node a, node b) { return a.a < b.a; } long long c[N][2], cnt[N], n; long long lowbit(long long x) { return x & (-x); } void add(long long x, long long val) { while (x <= n) c[x][0]+...
#include <bits/stdc++.h> using namespace std; class STlazy { private: int n; vector<long long> node, lazy; public: STlazy(vector<long long> v) { int siz = v.size(); n = 1; while (n < siz) n *= 2; node.resize(2 * n - 1, 0); lazy.resize(2 * n - 1, 0); for (int i = 0; i < siz; i++) node[n ...
#include <bits/stdc++.h> using namespace std; const long long maxn = 200005; map<long long, long long> g; map<long long, long long> invG; long long tree[8][maxn]; long long sum(long long k, long long t) { long long res = 0; for (long long i = k; i >= 1; i -= i & -i) res += tree[t][i]; return res; } void add(long ...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 22, inf = 1e9 + 7; int n; long long s[4 * N], cursum; vector<pair<int, int> > t[4 * N]; vector<long long> p[4 * N]; pair<int, int> a[N]; void build(int v, int tl, int tr) { if (tl == tr) { s[v] = a[tl].first; t[v].push_back({a[tl].second, a[tl]...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; long long c1[maxn], c2[maxn]; void add(long long *c, int x, int y) { for (; x < maxn; x += x & -x) c[x] += y; } long long ask(long long *c, int x) { long long ret = 0; for (; x > 0; x -= x & -x) ret += c[x]; return ret; } struct node { i...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, i; pair<int, int> dot[N]; long long mergeMoving(pair<int, int> arr[], pair<int, int> temp[], int left, int right); long long merge(pair<int, int> arr[], pair<int, int> temp[], int left, int mid, int right)...
#include <bits/stdc++.h> using namespace std; const long long N = 2e5 + 5, MOD = 1e9 + 7; pair<long long, long long> a[N]; vector<pair<long long, long long> > tree[4 * N]; void build(long long node, long long st, long long en) { if (st == en) { tree[node].push_back({a[st].first, a[st].first}); return; } l...
#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; ...
#include <bits/stdc++.h> using namespace std; int main() { long long n, i; cin >> n; pair<long long, long long> p[n]; long long a[n]; for (i = 0; i < n; i++) { cin >> a[i]; p[i].second = a[i]; } for (i = 0; i < n; i++) cin >> p[i].first; sort(a, a + n); sort(p, p + n); map<long long, long lo...
#include <bits/stdc++.h> #pragma GCC optimize(2) #pragma GCC optimize(3) using namespace std; inline int read() { int x = 0, neg = 1; char op = getchar(); while (!isdigit(op)) { if (op == '-') neg = -1; op = getchar(); } while (isdigit(op)) { x = 10 * x + op - '0'; op = getchar(); } return...
#include <bits/stdc++.h> using namespace std; const long long maxn = 6e6; const long long inf = 1e9; const long long maxv = 2e8 + 100; void init() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); } struct point { long long x, v; point() {} }; vector<point> foo; unordered_map<long long, pair<long long, ...
#include <bits/stdc++.h> using namespace std; const int N = 1000007, inf = 0x3f3f3f3f; int x[N], v[N]; pair<long long, int> seg[N + N]; pair<long long, int> soma(pair<long long, int> x, pair<long long, int> y) { return pair<long long, int>(x.first + y.first, x.second + y.second); } pair<long long, int> query(int l, i...
#include <bits/stdc++.h> using namespace std; long long int tree[800005], sree[800005]; struct sc { long long int a, b; }; bool comp(sc x, sc y) { if (x.a < y.a) return 1; return 0; } void update(long long int node, long long int s, long long int e, long long int ind, long long int val) { if (s == e...
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n, tot; long long ans, ans1, ans2; struct dot { long long x, v, nv; } a[maxn]; struct node { long long cnt, d; } T[maxn * 4]; bool cmp1(dot x, dot y) { return x.v < y.v; } bool cmp2(dot x, dot y) { return x.x < y.x; } void pushup(int x) { ...
#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"; const int max_x = 100000000; ...
#include <bits/stdc++.h> using namespace std; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; int dddx[] = {1, -1, 0, 0, 1, 1, -1, -1}; int dddy[] = {0, 0, 1, -1, 1, -1, 1, -1}; struct FenwickTree { vector<long long int> bit; int n; FenwickTree(int n) { this->n = n; bit.assign(n, 0); } long long i...
#include <bits/stdc++.h> using namespace std; using ll = long long; template <class T, class U> using Pa = pair<T, U>; template <class T> using vec = vector<T>; template <class T> using vvec = vector<vec<T>>; template <typename Monoid, typename F> class SegmentTree { private: int sz; vector<Monoid> seg; const F ...
#include <bits/stdc++.h> using namespace std; const long long int N = 2e5 + 2; struct Fenwick { long long int BIT[N] = {}; void update(long long int idx, long long int val) { for (long long int i = idx; i < N; i += (i & -i)) { BIT[i] += val; } } long long int query(long long int k) { long long...
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 10; int n, i; pair<int, int> dot[N]; long long mergeMoving(pair<int, int> arr[], pair<int, int> temp[], int left, int right); long long merge(pair<int, int> arr[], pair<int, int> temp[], int left, int mid, int right)...
#include <bits/stdc++.h> using namespace std; const long long maxn = 500007; long long n, C1[maxn], C2[maxn]; long long ans, p1[maxn], p2[maxn]; pair<long long, long long> fk[maxn]; bool cmp2(long long u, long long v) { if (fk[u].second < fk[v].second) { return 1; } else { if (fk[u].second == fk[v].second &...
#include <bits/stdc++.h> using namespace std; const int N = 200000; long long BIT1[200001]; long long cnt1[200001]; map<long long, long long> r, l; pair<long long, long long> arr[200001]; int n; void upd1(long long idx, long long val) { for (; idx <= N; idx = (idx | (idx + 1))) { BIT1[idx] += val; cnt1[idx]++...
#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 ...
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long mod = 1e9 + 7; const long long maxn = 500010; long long T, n, m, p[maxn], v[maxn], mxval = 0, tree[maxn], cnt[maxn], ans = 0; struct node { int pos, val, v; } a[maxn]; void add(int pos, long long val) { pos += n; cnt[pos] +=...
#include <bits/stdc++.h> using namespace std; long long query(int a, vector<long long>& ft) { long long res = 0; for (; ~a; a = (a & (a + 1)) - 1) { res += ft[a]; } return res; } void update(int a, int val, vector<long long>& ft) { for (; a < ft.size(); a = a | (a + 1)) { ft[a] += val; } } int main(...
#include <bits/stdc++.h> using namespace std; pair<long long, long long> st[800005]; void update(long long node, long long beg, long long end, long long pos, long long dist) { if (beg == end) { st[node].first += 1; st[node].second += dist; return; } long long mid = beg + (end - beg) / 2; ...
#include <bits/stdc++.h> using namespace std; pair<long long, long long> ara[200005]; map<long long, long long> mark; long long seg[4 * 300005], seg2[4 * 300005]; long long query(long long qlo, long long qhi, long long lo, long long hi, long long pos) { if (qlo > hi || qhi < lo || qlo > qhi) return 0;...
#include <bits/stdc++.h> using namespace std; const int MOD = 1000000007; const int INF = 1000000007; const int MAXN = (int)2e5 + 1; void setIO(string name) { ios_base::sync_with_stdio(0); cin.tie(0); freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } pair<pair<long lo...
#include <bits/stdc++.h> using namespace std; int cnt[400000], cnt1[400000], a[400000], b[400000], number[800000]; map<int, int> mp; vector<pair<int, int> > v; int q(int ind) { int sum = 0; while (ind > 0) { sum += number[ind]; ind -= ind & (-ind); } return sum; } void u(int ind, int n) { int sum = 0;...
#include <bits/stdc++.h> using namespace std; long long query(vector<long long>& ft, int pos) { long long ans = 0; while (pos > 0) { ans += ft[pos - 1]; pos -= (pos & (-pos)); } return ans; } void update(vector<long long>& ft, int pos, long long val, int& ceil) { while (pos <= ceil) { ft[pos - 1] ...
#include <bits/stdc++.h> using namespace std; long long n; int tc = 0; int solve(); int main() { ios_base::sync_with_stdio(0); if (tc < 0) { cout << "TC!\n"; cin.ignore(1e8); } else if (!tc) cin >> tc; while (tc--) solve(); return 0; } int solve() { long long l, r; cin >> n >> l >> r; l--; ...
#include <bits/stdc++.h> using namespace std; void solve() { int64_t n, l, r; cin >> n >> l >> r; l--, r--; int64_t cnt = 0; int64_t start = 1; int64_t num = n - 1; while (start < n) { if (l < cnt + 2 * num && r >= cnt) { for (int64_t i = 0; i < 2 * num; i++) { if (l <= cnt + i && cnt + ...
#include <bits/stdc++.h> using namespace std; int T; int N; long long L, R; int main() { scanf("%d", &T); while (T--) { scanf("%d%lld%lld", &N, &L, &R); if (L == R && L == 1LL * N * (N - 1) + 1) { printf("1\n"); continue; } long long i = N - 1; for (; i; i--) { if (L > 2 * i) ...
#include <bits/stdc++.h> #pragma GCC optimize("Ofast") using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); long long n, pstart, pend; int t; cin >> t; for (int testcases = 1; testcases <= t; testcases++) { cin >> n >> pstart >> pend; bool completestart = true; b...
#include <bits/stdc++.h> const int N = 3 * 1e5 + 5; const long long MOD = 1000000007; const long long inf = 1e18; using namespace std; long long power(long long x, long long y, long long p) { long long res = 1; x = x % p; if (x == 0) return 0; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; ...
#include <bits/stdc++.h> #pragma GCC target("avx2") #pragma GCC optimization("O3") #pragma GCC optimization("unroll-loops") #pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") using namespace std; long long binpow(long long base, long long exp, int mod) { long long res = 1; while (exp > 0) { if (ex...
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); int t; cin >> t; while (t--) { long long n, l, r; cin >> n >> l >> r; vector<long long> pre(n + 1); for (int i = 1; i <= n; i++) { pre[i] = pre[i - 1] + 2 * (n - i); } pre[n]++; ...
#include <bits/stdc++.h> using namespace std; int main() { int t; cin >> t; while (t--) { long long n, l, r; cin >> n >> l >> r; long long s = 0; long long i; for (i = 1; i <= n - 1; i++) { s += 2 * (n - i); if (l <= s) { s = s - 2 * (n - i); break; } } ...
#include <bits/stdc++.h> using namespace std; void solve() { long long n, l, r; cin >> n >> l >> r; if (l == n * (n - 1LL) + 1LL) { cout << 1 << '\n'; return; } long long suma = 0LL; long long trenutni = (long long)n - 1LL; while (trenutni > 0) { if (suma + 2 * trenutni >= l) break; suma +...
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007, N = 1e5 + 5, M = 1e5 + 5, INF = 0x3f3f3f3f; long long powmod(long long a, long long b) { long long res = 1; a %= mod; assert(b >= 0); for (; b; b >>= 1) { if (b & 1) res = res * a % mod; a = a * a % mod; } return res; } ...
#include <bits/stdc++.h> using namespace std; const int maxc = 1e5; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { long long k = 0; long long n, l, r; cin >> n >> l >> r; for (long long i = 2 * (n - 1); i; k += i, i -= 2) { for (long long j =...
#include <bits/stdc++.h> using namespace std; struct R { long long int nd, i; }; int main() { long long int n, l, r, st; scanf("%*d"); while (~scanf("%lld %lld %lld", &n, &l, &r)) { long long int p, i, j, nd; vector<R> v; v.push_back({1, 1}); for (p = 1, i = 2, j = n - 1; i < n; i++, j--) v.push...
#include <bits/stdc++.h> using namespace std; const long long N = 300010; long long t, n, a[N], b[N], x[N]; int main() { scanf("%lld", &t); while (t--) { long long l, r; scanf("%lld", &n); scanf("%lld%lld", &l, &r); long long tot = r - l + 1; long long high = n - 1, low = 1, mid, s = -1; whi...
#include <bits/stdc++.h> using namespace std; vector<int> func(int n, long long l, long long r) { long long start = 1; long long end = 2 * 1ll * (n - 1); vector<int> ans; if (start <= l && l <= end) { while (l <= r && l <= end) { if (l % 2 == 1) { ans.push_back(1); } else { ans.p...
#include <bits/stdc++.h> using namespace std; const long long mod = 998244353; const int N = 2e5 + 2; int main() { int t; scanf("%d", &t); while (t--) { long long n, l, r; scanf("%lld", &n); scanf("%lld", &l); scanf("%lld", &r); long long cur = 0, val = 2 * (n - 1), ind = 1; while (cur + v...
#include <bits/stdc++.h> using namespace std; long long n, t, l, r, o, e, pos; long long Find(long long k) { long long t = k; if (t % 2 == 1) t = (t + 1) / 2; else t /= 2; for (long long i = 0; i <= n - 1; i++) { if (n * i - i * (i + 1) / 2 < t && t <= n * (i + 1) - (i + 1) * (i + 2) / 2) retu...
#include <bits/stdc++.h> using namespace std; template <typename S, typename T> ostream& operator<<(ostream& out, pair<S, T> const& p) { out << '(' << p.first << ", " << p.second << ')'; return out; } template <typename T> ostream& operator<<(ostream& out, vector<T> const& v) { long long l = v.size(); for (long...
#include <bits/stdc++.h> using namespace std; void solve() { long long int i, j, n, m, k; long long int l, r; cin >> n >> l >> r; bool var1 = 0; long long int var2 = 0, var = 0; if (r == (n * (n - 1LL)) + 1LL) { var1 = 1; r--; } else { long long int o = 0; while (o < 2) o++; } long lon...