text stringlengths 49 983k |
|---|
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll n;
ll a[200001];
ll sum[200001];
ll bit[200001];
ll p[200001];
template <typename T>
inline T read() {
T x = 0;
T multiplier = 1;
char ch = getchar();
while (ch < '0' || ch > '9') {
if (ch == '-') {
multiplier = -1;
}
ch = ... |
#include <bits/stdc++.h>
using namespace std;
const int N = 222222;
int p[N], a[N], streee[N << 2];
long long s[N], stree[N << 2];
int n;
void supdate(int x, int v, int l, int r, int pos) {
if (l == r) {
streee[pos] += v;
return;
}
int m = l + (r - l) / 2;
if (x <= m) {
supdate(x, v, l, m, pos * 2 +... |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const long long inf = 1e18;
long long a[N], ans[N];
struct node {
int l, r;
long long lazy;
long long v;
};
node e[N * 5];
void build(int root, int l, int r) {
e[root].l = l;
e[root].r = r;
e[root].lazy = e[root].v = 0;
if (l == r) {
... |
#include <bits/stdc++.h>
using namespace std;
vector<long long> s;
vector<pair<long long, long long>> tree;
void build(long long l, long long r, long long v) {
if (r - 1 == l) {
tree[v] = {s[l], l};
return;
}
long long m = (r + l) / 2;
build(l, m, v * 2 + 1);
build(m, r, v * 2 + 2);
auto a = tree[v ... |
#include <bits/stdc++.h>
using namespace std;
long long int a[200005];
pair<long long int, long long int> tree[4 * 200005];
long long int lazy[4 * 200005];
void build(long long int node, long long int st, long long int en) {
if (st == en) {
tree[node] = {a[st], st};
return;
}
long long int mid = (st + en)... |
#include <bits/stdc++.h>
using namespace std;
inline long long read() {
long long s = 0, w = 1;
char ch = getchar();
while (!isdigit(ch)) {
if (ch == '-') w = -1;
ch = getchar();
}
while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar();
return s * w;
}
inline void write(long long x) {
if (x < 0... |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int maxN = 1e6 + 10;
ll tree[4 * maxN];
int n, p[maxN];
ll s[maxN];
void update(int x, int l, int r, int k, int w) {
if (l == r)
tree[x] = w;
else {
int mid = (l + r) / 2;
if (k <= mid)
update(2 * x, ... |
#include <bits/stdc++.h>
using namespace std;
long long n, m, q, x, k, t, y, w = 2, z, a[200500], ans[200500], bit[400500];
long long get(int i) {
long long ret = 0;
while (i) ret += bit[i], i -= (i & -i);
return ret;
}
void update(int i, int val) {
while (i <= 2 * n) bit[i] += val, i += (i & -i);
}
int main() ... |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
class fenwick {
public:
vector<T> fenw;
int n;
fenwick(int _n) : n(_n) { fenw.resize(n); }
void modify(int x, T v) {
while (x < n) {
fenw[x] += v;
x |= (x + 1);
}
}
T get(int x) {
T v{};
while (x >= 0) {
v... |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e16 + 5;
const int N = 1e6 + 5;
long long first[N];
long long lazy[N] = {0};
long long s[N];
int ans[N];
void pull(int v) { first[v] = min(first[2 * v + 1], first[2 * v + 2]); }
void apply(int v, long long val) {
first[v] += val;
lazy[v] += val;
}... |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int N = 2e5 + 20;
int n, s[N], a[N], fen[N];
inline void add(int p, int val) {
for (p++; p < N; p += p & -p) fen[p] += val;
}
inline int get(int p) {
int sum = 0;
for (; p; p -= p & -p) su... |
#include <bits/stdc++.h>
using namespace std;
const long long N = 3e5;
long long n, t[N], a[N], res[N];
set<long long> st;
void upd(long long i) {
long long d = i;
for (i; i < N; i |= i + 1) t[i] += d;
}
long long sum(long long l, long long r) {
long long s = 0;
for (; r >= 0; r &= r + 1, r--) s += t[r];
l--;... |
#include <bits/stdc++.h>
using std::size_t;
template <typename T, typename Op = std::plus<T>>
class SegmentTree {
std::vector<T> arr;
int n;
Op op;
public:
template <class InputIterator>
SegmentTree(size_t n_, InputIterator begin);
SegmentTree(size_t n_, const T& value = T());
const T& operator[](size_t... |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, eps = 1e-10;
int n;
long long a[N];
long long tree[N];
int ans[N];
long long sum(int x) {
long long res = 0;
while (x) {
res += tree[x];
x -= (x & (-x));
}
return res;
}
void add(int x, long long sum) {
while (x <= n) {
tree[x] ... |
#include <bits/stdc++.h>
using namespace std;
int n;
long long IM = -999999999999;
typedef struct nde {
int ll;
int rl;
long long val;
int pos;
long long prv;
struct nde* l;
struct nde* r;
struct nde* pr;
} prt;
prt* getnew() {
prt* p = new prt();
p->prv = 0;
return p;
}
prt* createTree(long long ... |
#include <bits/stdc++.h>
using namespace std;
void ECHO(string _s) {
cout << endl;
(void)_s;
}
template <typename T, typename... Args>
void ECHO(string _s, T x, Args... args) {
int _i;
string _s2 = "";
for (_i = 0; _i < (int)(_s).size(); ++_i) {
if (_s[_i] == ',') break;
if (_s[_i] != ' ') _s2 += _s[_... |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b) {
long long res = 1;
a = a % 1000000007;
while (b > 0) {
if (b & 1) {
res = (res * a) % 1000000007;
b--;
}
a = (a * a) % 1000000007;
b >>= 1;
}
return res;
}
long long fermat_inv(long long y) { ... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
const long long inf = 1e11;
struct Node {
int l, r, num;
long long tag;
long long val;
} node[4 * maxn];
long long a[maxn];
int ans[maxn];
void up(int no) {
if (node[no << 1].val < node[no << 1 | 1].val) {
node[no].val = node[no << 1].va... |
#include <bits/stdc++.h>
using namespace std;
const long long maxN = 2 * 100224;
struct BIT {
long long data[maxN] = {0};
void update(long long idx, long long val) {
while (idx < maxN) {
data[idx] += val;
idx += idx & -idx;
}
}
void update(long long l, long long r, long long val) {
updat... |
#include <bits/stdc++.h>
struct BIT {
int n;
long long a[200005];
int lowbit(int x) { return x & -x; }
void build(int size) { n = size; }
void update(int x, int val) {
for (; x <= n; x += lowbit(x)) a[x] += val;
}
long long query(int x) {
long long ret = 0;
for (; x; x -= lowbit(x)) ret += a[x... |
#include <bits/stdc++.h>
using namespace std;
long long n, s[200005], tree[800005], lazy[800005], ans[200005];
void pushdown(long long ind, long long l, long long r) {
if (l != r && lazy[ind] != 0) {
lazy[2 * ind] += lazy[ind];
tree[2 * ind] += lazy[ind];
lazy[2 * ind + 1] += lazy[ind];
tree[2 * ind +... |
#include <bits/stdc++.h>
using namespace std;
bool cur1;
int n;
int ans[200005];
long long S[200005];
struct Bittree {
long long sum[200005];
inline void update(int x, int v) {
while (x <= n) {
sum[x] += v;
x += x & (-x);
}
}
inline long long query(int x) {
long long res = 0;
while (... |
#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
using namespace std;
void redirectIO() {
ios::sync_with_stdio(false);
cin.tie(0);
}
long long mVal[1100000];
long long upd[1100000];
long long s[210000];
void refr(int a) { mVal[a] = mVal[a * 2] + mVal[a * 2 + 1] + upd[a]; }
void push(int a) {
m... |
#include <bits/stdc++.h>
using namespace std;
long long int N = 1e13 + 7;
long long int n;
vector<long long int> s(200004), p(200004), lazy(800004);
vector<long long int> tree(800004);
void build(long long int node, long long int l, long long int r) {
if (l == r) {
tree[node] = s[l];
return;
}
long long i... |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9, PI = acos(-1.);
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int N = 2e5 + 5;
int n;
long long mi[4 * N], pos[4 * N], v[N], lz[4 * N];
void build(int p, int l, int r) {
if (l == r) {
mi[p] = ... |
#include <bits/stdc++.h>
long long int min2(long long int a, long long int b) { return a > b ? a : b; }
long long int max2(long long int a, long long int b) { return a < b ? a : b; }
class node {
public:
int left, right;
long long int num, min;
bool isMinLeft;
bool willPropagate;
node *leftchild, *rightchild... |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const double EPS = 1e-9;
const long long MOD = (long long)(1e9 + 7);
const long long MAXV = (long long)(2e5 + 10);
const long long MAXE = (long long)(1e6 + 10);
long long seg[MAXV * 4];
long long lazy[MAXV * 4];
long long A[MAXV * 4];
void build(... |
#include <bits/stdc++.h>
using namespace std;
const long long INF = ~0ull >> 1;
long long _min[2000005 * 5], add[2000005 * 5];
int n;
long long s[2000005];
int ans[2000005];
void pushup(int o) { _min[o] = min(_min[o << 1], _min[o << 1 | 1]); }
void pushdown(int o) {
if (add[o]) {
add[o << 1] += add[o];
add[o ... |
#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 10;
const long long INF = 0x3f3f3f3f3f3f3f3f;
long long n, tag[N << 2], ans[N], pos;
long long a[N], val[N << 2];
inline void pushup(long long o) { val[o] = min(val[o << 1], val[o << 1 | 1]); }
inline void apply(long long o, long long x) { val[o] +... |
#include <bits/stdc++.h>
using namespace std;
long long a[3000000], tree[4 * 3000000], ans[4 * 3000000];
int n;
void update(int indx, int left, int right, int pos, long long val) {
if (left > pos || right < pos) return;
if (left == right) {
tree[indx] += val;
return;
}
int mid = (left + right) >> 1;
u... |
#include <bits/stdc++.h>
using namespace std;
long long power(long long a, long long b, long long m) {
a %= m;
long long ret = 1;
while (b) {
if (b & 1) ret = ((ret % m) * (a % m)) % m;
a = ((a % m) * (a % m)) % m;
b >>= 1;
}
return ret;
}
const int N = 2e5 + 5;
long long n, bit[N + 3], a[N + 2], ... |
#include <bits/stdc++.h>
const long long inf = 0x3f3f3f3f;
const long long inn = 0x80808080;
using namespace std;
const long long maxm = 2e5 + 5;
long long mi[maxm << 2];
long long laz[maxm << 2];
long long p[maxm];
long long n;
void pushup(long long node) { mi[node] = min(mi[node * 2], mi[node * 2 + 1]); }
void pushdo... |
#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, i, e, f, g, n, m, k, l, A[200005], B[200005], mid, le, ri,
BITree[4000005], ans, fix[200005];
long long getSum(long long index) {
long long sum = 0;
while (index > 0) {
sum += BITree[index];
index -= index & (-index);
}
return sum;
... |
#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> tree[4 * 200005 + 1];
long long lo[4 * 200005 + 1], hi[4 * 200005 + 1], a[200005],
delta[4 * 200005 + 1], ans[200005];
void init(long long i, long long a, long long b) {
lo[i] = a;
hi[i] = b;
if (a == b) return;
long long m = (a + b) /... |
#include <bits/stdc++.h>
#pragma GCC optimize "03"
using namespace std;
const long long int N = 2e5 + 5;
const long long int mod = 1e9 + 7;
const long long int inf = 1e18 + 9;
long long int a[N];
long long int t[4 * N], lzy[4 * N];
void build(long long int nd, long long int s, long long int e) {
if (s == e)
t[nd]... |
#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-9, PI = acos(-1.);
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const int N = 2e5 + 5;
int n, ans[N];
long long mi[4 * N], pos[4 * N], v[N], lz[4 * N];
void build(int p, int l, int r) {
if (l == r) {
... |
#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 5;
long long n, a[N], c[N], p[N];
inline long long read() {
long long ret = 0, f = 0;
char c = getchar();
while (!isdigit(c)) {
if (c == '-') f = 1;
c = getchar();
}
while (isdigit(c)) {
ret = ret * 10 + c - 48;
c = getcha... |
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
long long n = 1, n2, s[200010], ans[200010], dat[800010];
void INIT(long long k, long long lb, long long ub) {
if (lb == ub) return;
INIT(k * 2 + 1, lb, (lb + ub) / 2);
INIT(k * 2 + 2, (lb + ub) / 2 + 1, ub);
dat[k] = dat[k * 2 + 1] + ... |
#include <bits/stdc++.h>
using namespace std;
const int maxn = 200200;
long long mn[4 * maxn], ps[4 * maxn], ls[4 * maxn];
void push(int i, int l, int r) {
if (ls[i]) {
mn[i] += ls[i];
if (l != r) {
ls[2 * i] += ls[i];
ls[2 * i + 1] += ls[i];
}
ls[i] = 0;
}
}
void pull(int i) {
long lo... |
#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
bool b = 0;
char c;
while (!isdigit(c = getchar()) && c != '-')
;
if (c == '-') c = getchar(), b = 1;
x = c - 48;
while (isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - 48;
if (b) x = -x;
}
template <typ... |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 2e5 + 5, M = 2 * N + 5;
int n;
long long tree[1 << 19], a[N];
void build(int i, int l, int r) {
if (l == r) {
tree[i] = l;
return;
}
int mid = (l + r) / 2;
build(i * 2, l, mid);
build(i * 2 + 1, mid + 1, r);
tree[... |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long a[200007];
long long bit[200007];
long long ans[200007];
long long query(long long id) {
long long res = 0;
while (id) {
res += bit[id];
id -= (id & (-id));
}
return res;
}
void add(long long id, long long val) {
while (id <= n) {
... |
#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; ++i) {
cin >> v[i];
}
vector<int> v2 = v;
sort(v.rbegin(), v.rend());
int m;
cin >> m;
for (int i = 0; i < m; ++i) {
int k, ind;
cin >> k >> in... |
#include <bits/stdc++.h>
using namespace std;
vector<int> s[110][110], answer[110];
long long dp[110][110];
long long val[110];
int arr[110];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> arr[i];
}
for (int i = 1; i <= n; ++i) {
for (... |
#include <bits/stdc++.h>
using namespace std;
class SegmentTree {
public:
vector<vector<long long> > a;
long long n;
SegmentTree(vector<long long>& arr) {
n = arr.size();
a.resize(4 * n);
build(1, 0, arr.size(), arr);
}
void build(long long v, long long vl, long long vr, vector<long long>& arr) {... |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long double error = 2e-6;
const long double PI = acosl(-1);
inline long long int MOD(long long int x, long long int m = mod) {
long long int y = x % m;
return (y >= 0) ? y : y + m;
}
const int inf = 1e9;
const long long int infl ... |
#include <bits/stdc++.h>
using namespace std;
long long a[105], ans[105], b[105];
signed main() {
long long n, i;
cin >> n;
for (i = 0; i < n; i++) {
cin >> a[i];
b[i] = a[i];
}
long long m;
cin >> m;
while (m--) {
long long k, t = 0, c = 0, pos;
cin >> k >> pos;
sort(b, b + n);
me... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
vector<pair<int, int>> ps(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
ps[i] = make_pair(a[i], i);
}
sort(ps.begin(), ps.end(), [](pair<int, int>& a, pair<int, int>& b) {
if (a.first == b.first) {
... |
#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void amin(T &a, U b) {
a = (a > b ? b : a);
}
template <typename T, typename U>
inline void amax(T &a, U b) {
a = (a > b ? a : b);
}
const int N = (1 << 21) + 5;
int fenw[N];
void update(int i, int val) {
for (; i < N; i += i &... |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9;
bool cmp(pair<int, int> a, pair<int, int> b) {
return a.first > b.first || (a.first == b.first && a.second < b.second);
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<pair<int, int>>... |
#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int>> v;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++) {
cin >> a[i];
v.push_back({-a[i], i});
}
sort(v.begin(), v.end());
int m;
cin >> m;
for (int i = 0; i < m; i++) ... |
#include <bits/stdc++.h>
using namespace std;
int a[200001];
pair<int, int> aTmp[200001];
int b[200001];
int kthLargest(int n, int k) {
vector<int> c(n);
for (int i = 0; i < n; ++i) {
c[i] = b[i];
}
sort(c.begin(), c.end());
return c[k - 1];
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(0);... |
#include <bits/stdc++.h>
using namespace std;
bool comp(const pair<int, int>& a, const pair<int, int>& b) {
if (a.first == b.first)
return a.second > b.second;
else
return a.first < b.first;
}
int main() {
int n;
cin >> n;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].fi... |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
vector<int> a(n + 1);
for (int i = 1; i <= n; i++) cin >> a[i];
vector<int> aS = a;
sort(aS.rbegin(), aS.rend());
int m;
cin >> m;
while (m--) {
int k... |
#include <bits/stdc++.h>
using namespace std;
bool cmp(int a, int b) { return a > b; }
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int n, m;
cin >> n;
vector<int> a(n), a_f(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
a_f[i] = a[i];
}
sort(a_f.begin(), a_f.end(), cmp);
... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int m;
cin >> m;
while (m--) {
int k, pos;
cin >> k >> pos;
pos--;
vector<vector<int>> ans(k);
vector<long long> sums(k);
int last = ... |
#include <bits/stdc++.h>
using namespace std;
long long n, m, k;
pair<long long, long long> arr[200000];
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
if (a.first == b.first) return a.second < b.second;
return a.first > b.first;
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
c... |
#include <bits/stdc++.h>
using namespace std;
long long int ivalue(string s) {
long long int x = 0;
stringstream obj(s);
obj >> x;
return x;
}
const long long int M = 1e9 + 7;
const long long int N = 1e5 + 5;
const long long int inf = 2e18;
long long int mod(long long int x) { return (x % M); }
long long int mo... |
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
long long n, m, a1, b1;
cin >> n;
vector<int> a(n);
priority_queue<pair<int, int>> y;
for (int i = 0; i < n; i++) {
cin >> a[i];
y.push({a[i], -i});
}
vector<vector<int>> e(n);
for ... |
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimization("03")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int maxn = 200001;
const int maxe = 20;
int a[maxn], b[maxn], c, k, pa[maxn], x, y, q, sol, d, d2, mod = 1000000007, j;
int m, n;
char h;
set<int> se;
string s;
pair<int... |
#include <bits/stdc++.h>
using namespace std;
bool compare(pair<int, int> p1, pair<int, int> p2) {
if (p1.first == p2.first) {
if (p1.second < p2.second)
return true;
else
return false;
} else if (p1.first < p2.first)
return false;
else
return true;
}
int main() {
ios_base::sync_with... |
#include <bits/stdc++.h>
using namespace std;
void itval(istream_iterator<string> it) {}
template <typename T, typename... Args>
void itval(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << endl;
itval(++it, args...);
}
template <typename T>
inline void print(T x) {
cout << x << "\n";... |
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = ... |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using ii = pair<int, int>;
using vii = vector<ii>;
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vii a(n);
for (int i = 0; i < (n); i++) cin >> a[i].first, a[i].second ... |
#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(time(0));
bool comp(pair<int, int> &a, pair<int, int> &b) {
return a.first < b.first || (a.first == b.first && a.second > b.second);
}
int main() {
int n;
cin >> n;
vector<int> g(n);
vector<pair<int, int> > v(n);
for (int i = 0; i < n; i++) {
cin... |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 * 10;
long long arr[200];
vector<pair<long long, long long>> sortedVec, vec2;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
if (a.first > b.first) return true;
if (b.first > a.first) return false;
if (a.second > b.se... |
#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;
}
};
long long int gcd(long long int a, long long int b) {
if (a ... |
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int>& a, pair<int, int>& b) {
if (a.first > b.first)
return true;
else if (a.first == b.first)
return a.second < b.second;
return false;
}
bool cmp2(pair<int, int>& a, pair<int, int>& b) { return a.second < b.second; }
void solve() {
int n... |
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> p1, pair<int, int> p2) {
if (p1.first != p2.first)
return p2.first > p1.first;
else
return p2.second < p1.second;
}
void solve() {
int n, x;
cin >> n;
vector<pair<int, int>> v(n);
for (int i = 0; i < n; i++) {
cin >> x;
v... |
#include <bits/stdc++.h>
const int LG = 21;
const int N = 400005;
const long long MOD = 1e9 + 7;
const long long INF = 1e9;
const long long INFLL = 1e18;
using namespace std;
int cx[4] = {-1, 0, 1, 0};
int cy[4] = {0, -1, 0, 1};
string Yes[2] = {"No", "Yes"};
string YES[2] = {"NO", "YES"};
long long inq(long long x, lo... |
#include <bits/stdc++.h>
using namespace std;
string gh = "here";
bool cmp(pair<int, int> a, pair<int, int> b) {
if (a.first > b.first) {
return true;
} else if (a.first == b.first and a.second < b.second) {
return true;
}
return false;
}
bool cmp2(pair<int, int> a, pair<int, int> b) {
if (a.second < ... |
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 200000;
int fen[N + 1];
void add(int x) {
++x;
while (x <= N) {
++fen[x];
x += x & -x;
}
}
int kth(int k) {
int x = 0;
for (int i = 18; i >= 0; --i)
if (x + (1 << i) <= N && fen[x + (1 << i)] <= k) {
x += (1 << i);
k -= fe... |
#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 9;
const long long mod = 1e9 + 7;
vector<bool> prime(MAX, 1);
vector<int> spf(MAX, 1);
vector<int> primes;
void sieve() {
prime[0] = prime[1] = 0;
spf[2] = 2;
for (long long i = 4; i < MAX; i += 2) {
spf[i] = 2;
prime[i] = 0;
}
primes... |
#include <bits/stdc++.h>
using namespace std;
void ios1() {
ios_base::sync_with_stdio(0);
cout.tie(0);
cin.tie(0);
}
bool cmd(pair<long long, int> a, pair<long long, int> b) {
if (a.first > b.first)
return 0;
else if (a.first < b.first)
return 1;
else
return (a.second > b.second);
}
int main() {... |
#include <bits/stdc++.h>
using namespace std;
bool mycomp1(pair<int, int> a, pair<int, int> b) {
if (a.first != b.first) {
return (a.first < b.first);
} else {
return (a.second > b.second);
}
}
bool mycomp2(pair<int, int> a, pair<int, int> b) {
return (a.second < b.second);
}
void solve() {
int n, m;
... |
#include <bits/stdc++.h>
using namespace std;
set<pair<int, int> > t;
int a[200105];
vector<pair<int, int> > vec[200105];
int ans[200105];
int seg[200105 << 2];
void build(int t, int i, int j) {
if (i == j) {
seg[t] = 1;
return;
}
int left = t << 1, right = left | 1, mid = (i + j) >> 1;
build(left, i, m... |
#include <bits/stdc++.h>
const long long MAX = 2e5 + 5;
using namespace std;
long long fen[MAX], a[MAX];
bool cnt[MAX];
bool compare(const pair<long long, long long> &x,
const pair<long long, long long> &y) {
if (x.second == y.second) return x.first < y.first;
return x.second > y.second;
}
void f_inser... |
#include <bits/stdc++.h>
using namespace std;
hash<string> hfn;
const int inf = 2e9;
const long long mod = 1e9 + 7;
const long double eps = 1e-8;
const long long biginf = 2e18;
bool comp(pair<int, int> a, pair<int, int> b) {
if (a.first == b.first) return a.second > b.second;
return a.first < b.first;
}
void solve(... |
#include <bits/stdc++.h>
using namespace std;
bool cmp(pair<int, int> p1, pair<int, int> p2) {
if (p1.first == p2.first) {
return p1.second < p2.second;
} else {
return p1.first > p2.first;
}
}
int fc(int k, int pos, vector<pair<int, int> > a, vector<int> b) {
vector<int> y;
for (int i = 0; i < k; i++... |
#include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
vector<long long> v(n), so(n);
for (long long i = 0; i < n; ++i) {
cin >> v[i];
so[i] = v[i];
}
sort(so.begin(), so.end());
long long m;
cin >> m;
for (long long i = 0; i < m; ++i) {
long long k, pos;
c... |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 123, MAXN = 2e5 + 47;
long long p = 41;
template <class T>
istream& operator>>(istream& in, vector<T>& a) {
for (auto& i : a) in >> i;
return in;
}
template <class T>
ostream& operator<<(ostream& out, vector<T>& a) {
for (auto& i : a) out <... |
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 1;
const int N = 1e6 * 3;
const double EPS = 1 / 1e10;
vector<int> v, v1;
set<pair<long long, long long> > second;
bool cmp(pair<long long, long long> a, pair<long long, long long> b) {
return (a.first > b.first) || (a.first == b.first && a.second < ... |
#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long long md = 1e9 + 7;
long long n, q, a, i, k, pos;
vector<pair<long long, long long> > v, ans;
bool comp(pair<long long, long long> a, pair<long long, long long> b) {
if (a.first == b.first)
return a.second < b.second;
else
... |
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int, int> a, pair<int, int> b) {
if (a.first == b.first) return a.second > b.second;
return a.first < b.first;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n;
vector<int> a_f(n);
vector<pair<int, int... |
#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long double error = 2e-6;
const long double PI = acosl(-1);
inline long long int MOD(long long int x, long long int m = mod) {
long long int y = x % m;
return (y >= 0) ? y : y + m;
}
const int inf = 1e9;
const long long int infl ... |
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int m;
cin >> m;
while (m--) {
map<int, pair<int, vector<int>>> mp;
int k, pos;
cin >> k >> pos;
vector<int> temp;
mp[0] = make_pair(0, t... |
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, mod = 1e9 + 7;
int a[N];
vector<pair<int, int> > vec;
bool cmp(pair<int, int> a, pair<int, int> b) {
if (a.first != b.first)
return a.first > b.first;
else
return a.second < b.second;
}
void solve() {
int k, pos;
cin >> k >> pos;
ve... |
#include <bits/stdc++.h>
using namespace std;
long long N = 200000;
vector<bool> visited(N + 1, false);
bool isprime(long long x) {
for (long long i = 2; i <= sqrt(x); i++) {
if (x % i == 0) return false;
}
return true;
}
void findfact(long long x, map<long long, vector<long long>>& m) {
for (long long i = ... |
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL INF = INT_MAX;
const int N = 1e5 + 7;
const LL MOD = 1e9 + 7;
void ArrayIn(int size, int a[]) {
for (int i = 0; i < size; i++) scanf("%d", &a[i]);
}
void ArrayOut(int size, int a[]) {
for (int i = 0; i < size; i++) printf("%d ", a[i]);
p... |
#include <bits/stdc++.h>
using namespace std;
const long long int no = 3e6 + 5, modulo = 1e9 + 7, inf = 1e18, N = 3e3 + 1;
long long int ar[no], br[no], cr[no];
void solve() {
long long int n = 0, m = 0, a = 0, b = 0, c = 0, d = 0, x = 0, y = 0, z = 0,
w = 0, k = 0;
cin >> n;
vector<long long int>... |
#include <bits/stdc++.h>
using namespace std;
const long double pi = 2 * acos(0.0);
struct arr {
long long index, val;
};
struct query {
long long n, ind, index, ans;
};
bool compare(arr a1, arr a2) {
if (a1.val == a2.val) return (a1.index < a2.index);
return (a1.val > a2.val);
}
bool compare2(arr a1, arr a2) {... |
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e12;
int main() {
int n;
cin >> n;
vector<int> a(n), s;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
s = a;
sort(s.begin(), s.end());
int m;
cin >> m;
for (int i = 0; i < m; ++i) {
int k, pos;
cin >> k >> pos;
int c = 0;
... |
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 123, MAXN = 5e5 + 47, MEGAINF = 1e18 + 228;
template <class T>
inline istream& operator>>(istream& in, vector<T>& a) {
for (auto& i : a) in >> i;
return in;
}
template <class T>
inline ostream& operator<<(ostream& out, vector<T>& a) {
for (... |
#include <bits/stdc++.h>
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
const int maxn = 100100;
using namespace std;
int ans[110][110];
struct node {
int nub, pos;
} a[110];
bool cmp(node c, node b) {
if (c.nub == b.nu... |
#include <bits/stdc++.h>
using namespace std;
namespace kotespace {
template <class T>
class duplet {
private:
public:
T x, y;
duplet(){};
duplet(T a, T b) : x(a), y(b){};
bool operator<(const duplet P) const {
return (x < P.x || (x == P.x && y < P.y));
}
bool operator>(const duplet P) const {
ret... |
#include <bits/stdc++.h>
using namespace std;
const int N = 5e3 + 2, mod = 1e9 + 7;
void solve() {
int n;
cin >> n;
vector<pair<int, int> > a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].first;
a[i].second = i;
}
sort(a.begin(), a.end(), [](pair<int, int> i, pair<int, int> j) {
if (i.first == j... |
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using ld = long double;
void solve();
bool comp(const pair<int64_t, int64_t> &a, const pair<int64_t, int64_t> &b) {
if (a.first != b.first) return (a.first < b.first);
return (a.second > b.second);
}
int32_t main() {
ios_base::sync_with_stdio(0);
... |
#include <bits/stdc++.h>
bool choice_first(std::vector<size_t> a, std::vector<size_t> b) {
uint64_t sum_a, sum_b;
sum_a = sum_b = 0;
for (auto elem : a) {
sum_a += elem;
}
for (auto elem : b) {
sum_b += elem;
}
return sum_a > sum_b || (sum_a == sum_b && a < b);
}
int main() {
std::ios_base::sync... |
#include <bits/stdc++.h>
using namespace std;
const int Z = (int)3e3 + 228;
const int N = (int)3e5 + 228;
const int INF = (int)1e9 + 228;
const int MOD = (int)1e9 + 7;
int a[N];
map<int, int> cnt;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> b;
for (int ... |
#include <bits/stdc++.h>
using namespace std;
int n, q, arr[101], sr[101];
vector<int> dp[101];
multiset<int> s;
int main() {
cin >> n;
for (long long i = 0; i < n; i++) {
cin >> arr[i];
sr[i] = arr[i];
}
sort(sr, sr + n, [](int a, int b) { return a > b; });
for (long long i = 1; i <= n; i++) {
fo... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.