solution
stringlengths
11
983k
difficulty
int64
0
21
language
stringclasses
2 values
#include <bits/stdc++.h> using namespace std; bool comp(pair<long long, long long> a, pair<long long, long long> b) { return a.first > b.first || a.first == b.first && a.second < b.second; } bool comp2(pair<long long, long long> a, pair<long long, long long> b) { return a.second < b.second; } signed main() { ios_...
10
CPP
n = int(input()) s = list(map(int, input().split())) for i in range(n): s[i] = (s[i], i) mx = sorted(s, key=lambda y: y[0], reverse=True) m = int(input()) for i in range(m): k, pos = map(int, input().split()) pos -= 1 a = 0 last = mx[0][0] res = [] d = dict() d2 = dict() for x in ran...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const int INF = 2e9; void solve() { int n, k, m, pos; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) cin >> a[i]; cin >> m; for (int _ = 0; _ < m; _++) { cin >> k >> pos; vector<int> ind; set<int> s; for (int i = 0; i < k; i++) { i...
10
CPP
#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) { if (a.second < b.second) return true; return false; } return false; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); int i, j,...
10
CPP
#include <bits/stdc++.h> const double pi = 3.141592653589793238; const int MOD1 = 1e9 + 7; const int MOD2 = 998244353; const int N = 3e5 + 5; using namespace std; bool cmp(pair<long long, long long> a, pair<long long, long long> b) { if (a.first != b.first) return (a.first > b.first); return (a.second < b.second); ...
10
CPP
n = int(input()) c = list(map(lambda x: (int(x[1]),-x[0]),enumerate(input().split()))) so = sorted(c) for i in range(int(input())): k,r = map(int,input().split()) now = so[-k:] now.sort(key = lambda x: -x[1]) print(now[r-1][0])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const long long int INF = (long long int)2e18 + 77; void solve() { int n; cin >> n; int a[n], i; for (i = 0; i < n; i++) cin >> a[i]; map<int, int> N; int M[n][n]; for (i = 0; i < n; i++) { N[a[i]]++; M[n - 1][i] = a[i]; } for (i = n - 2; i >= 0; i...
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n); for (int i = 0; i < n; i++) { cin >> a[i]; } int m; cin >> m; for (int e = 0; e < m; e++) { int k, p; cin >> k >> p; vector<int> b; for (int i = 0; i < k; i++) { b.push_back(a[i]); ...
10
CPP
n=int(input()) a=sorted(zip(list(map(int,input().split())),range(n)),key=lambda x:(x[0],-x[1]),reverse=True) #print(a) m=int(input()) for i in range(m): k,pos=map(int,input().split()) b=sorted(a[:k],key=lambda x:x[1]) #print(b) print(b[pos-1][0])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; long long pw(long long a, long long b) { if (b == 0) return 1; if (b % 2 == 1) return (a * pw((a * a) % 1000000007, b / 2)) % 1000000007; else return (1 * pw((a * a) % 1000000007, b / 2)) % 1000000007; } bool comp(pair<long long, long long> a, pair<long long, ...
10
CPP
from sys import stdin n = int(stdin.readline()) alist = list(map(int, stdin.readline().split())) aindlist = sorted([(elem, i) for i, elem in enumerate(alist)], key = lambda x: (-x[0], x[1])) m = int(stdin.readline()) ans = [] for _ in range(m): k, pos = map(int, stdin.readline().split()) temp = [x[1] for x in a...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e6 + 1; const int INF = 2e9 + 1; const int MOD = (1e9 + 7); void bye(string s = "") { cout << s << '\n'; exit(0); } signed main() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n; cin >> n; vector<int> arr(n); set<pair<...
10
CPP
import itertools import functools from operator import itemgetter def cmp(a, b): # 0 - descending, 1 - ascending # returns: -1, a before b; 1 b before a; 0 no difference if a[0] > b[0]: return -1 elif a[0] < b[0]: return 1 else: if a[1] < b[1]: return -1 ...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; using ll = long long int; int main() { ll t = 1; while (t--) { int n; cin >> n; vector<int> v(n), temp(n); for (int i = 0; i < n; i++) { cin >> v[i]; temp[i] = v[i]; } sort(temp.begin(), temp.end(), greater<int>()); int m; cin...
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int t = 1; while (t--) { int n, x; cin >> n; vector<pair<int, int> > a(n); for (int i = 0; i < n; i++) { cin >> x; a[i] = {-x, i}; } sort(a.begin(), a.end()); in...
10
CPP
n = int(input()) sequence = list(map(int, input().split())) array = list(sequence) array.sort(reverse=True) m = int(input()) for i in range(m): k, pos = map(int, input().split()) D = dict() for elem in array[:k]: if elem in D: D[elem] += 1 else: D[elem] = 1 for el...
10
PYTHON3
n = int(input()) p = list(map(int, input().split())) p = sorted(list(enumerate(p)), key=lambda x: -x[1]) a = [[]] for i in range(n): a.append(sorted(a[-1] + [p[i]], key=lambda x: x[0])) m = int(input()) for _ in range(m): x, y = map(int, input().split()) print(a[x][y - 1][1])
10
PYTHON3
#include <bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; const long long mo = 1e9 + 7; long long sx, sy, ex, ey, dx[6] = {0, 1, 0, -1, 0, 0}, dy[6] = {1, 0, -1, 0, 0, 0}, m, n, k, dz[6]{0, 0, 0, 0, -1, 1}, sg; long long p, no, v, ans, w; int par[55000...
10
CPP
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using mii = map<int, int>; const double Eps = 1e-8; const int Inf = 1e9 + 9; const int Mod = 1e9 + 7; const int N = 1e5 + 9; const int dx4[4] = {0, 1, 0, -1}; const int dy4[4] = {-1, 0, 1, 0}; const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0}; const int...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long mod = 1000000007; const long long inf = LLONG_MAX - 100000; void IO() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout.setf(ios::fixed); } long long pw(long long x, long long y, long long p = inf) { long long res = 1; x = x % p; if (x ...
10
CPP
n = int(input()) A = list(map(int, input().split())) L = A.copy() L2 = L.copy() A.sort() c = int(input()) r = [] def S(x, L): idx = L.index(x) L[idx] = -1 return [idx, x] for i in range(c): k, pos = map(int, input().split()) B = A[:0-k-1:-1] H = list(map(lambda x: S(x, L), B)) H.sort() N = list(map(lamb...
10
PYTHON3
def get_index(lt, vec): max_el = 0 pos = None for i in range(len(vec)): if i not in lt: if max_el < vec[i]: max_el = vec[i] pos = i return pos n = int(input()) vec = [int(x) for x in input().split()] lst = [[vec.index(max(vec))]] for i in range(n-1):...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0); long long int n, m, k, i, j, a[101]; cin >> n; vector<long long int> pr; for (i = 0; i < n; i++) { cin >> a[i]; pr.push_back(a[i]); } sort(pr.rbegin(), pr.rend()); cin >> m; while ...
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n, 0), b(n, 0); for (int i = 0; i < n; ++i) { cin >> a[i]; b[i] = a[i]; } sort(b.begin(), b.end()); int m; cin >> m; for (int i = 0; i < m; ++i) { int k, pos; cin >> k >> pos; int x = b[n - k]...
10
CPP
#include <bits/stdc++.h> using namespace std; int32_t main() { std::ios::sync_with_stdio(false); std::cin.tie(NULL); std::cout.tie(NULL); long long t = 1; while (t--) { long long n; cin >> n; vector<long long> ar(n), br(n); for (long long i = 0; i < n; i++) { cin >> ar[i]; br[i] = ...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long INF = 1e12; long long a_s, b_s; vector<long long> best(vector<long long> a, vector<long long> b) { a_s = 0; b_s = 0; bool flaga = true; bool flagb = true; for (long long i = 0; i < a.size(); ++i) if (a[i] < 0) flaga = false; for (long long i ...
10
CPP
#include <bits/stdc++.h> using namespace std; pair<int, int> a[100]; int ind[100]; bool cmp(int i, int j) { if (a[i].first == a[j].first) return a[i].second < a[j].second; return a[i].first > a[j].first; } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> n; for (int i = 0; i < n; ...
10
CPP
from sys import stdin,stdout from math import gcd,sqrt,factorial,pi from collections import deque,defaultdict input=stdin.readline R=lambda:map(int,input().split()) I=lambda:int(input()) S=lambda:input().rstrip('\n') L=lambda:list(R()) P=lambda x:stdout.write(x) lcm=lambda x,y:(x*y)//gcd(x,y) hg=lambda x,y:((y+x-1)//x)...
10
PYTHON3
#include <bits/stdc++.h> using namespace std; long long n, m, k, l, r, i, j, a[1000001], d[10000001], ans[1000001]; bool tt[1000001]; vector<pair<long long, long long> > v; string s; void build(long long h, long long l, long long r) { if (l == r) { d[h] = 0; return; } long long w = (l + r) / 2; build(h ...
10
CPP
m = int(input()) line = [int(i) for i in input().split()] for i in range(int(input())): false_line = list(line) k, pos = map(int, input().split()) while len(false_line) > k: x = min(false_line) rang = iter(range(-1, -len(false_line)-1, -1)) j = next(rang) while j > -len(false...
10
PYTHON3
import copy b=[] a=[] rezult='' n=int(input()) a=list(map(int,input().split())) m=int(input()) for i in range(1,m+1): k,pos=map(int,input().split()) b=copy.deepcopy(a) b.reverse() for j in range(1,n-k+1): b.remove(min(b)) b.reverse() rezult=rezult+'\n'+str(b[pos-1]) print(rezult)
10
PYTHON3
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); long long int n; cin >> n; vector<long long int> a(n), v1(n); for (long long int i = 0; i < n; i++) cin >> a[i]; v1 = a; sort(a.begin(), a.end(), greater<long long int>()); long long int q; ci...
10
CPP
#include <bits/stdc++.h> using namespace std; int n, A[111]; map<int, set<int>> idxs; set<int> app; int main(void) { scanf("%d", &n); for (int i = 1; i <= n; ++i) { scanf("%d", &A[i]); app.insert(A[i]); idxs[A[i]].insert(i); } int q; scanf("%d", &q); while (q--) { int k, pos; scanf("%d%d...
10
CPP
#include <bits/stdc++.h> using namespace std; signed main() { ios ::sync_with_stdio(false); cin.tie(0); long long n; cin >> n; long long arr[n]; map<long long, long long> mp; for (long long i = 0; i < n; i++) { cin >> arr[i]; } vector<long long> vrr(arr, arr + n); sort(vrr.rbegin(), vrr.rend());...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)1 << 62; const long long MOD = 1e9 + 7; const int iINF = 1 << 30; const double PI = 3.14159265359; int main() { int n; vector<pair<int, int> > a; cin >> n; a.assign(n, {0, 0}); for (int i = 0; i < n; i++) { cin >> a[i].first; ...
10
CPP
#include <bits/stdc++.h> using namespace std; bool mycomparator(pair<long long int, int> p1, pair<long long int, int> p2) { if (p1.first == p2.first) { if (p1.second > p2.second) { return true; } else { return false; } } if (p1.first < p2.first) { return true; } else { return fal...
10
CPP
#include <bits/stdc++.h> using namespace std; void jakos() { ios_base::sync_with_stdio(false); cin.tie(0); } const int mod = 1e9 + 7; const int base = 179; const int INF = 1e9; const int N = 1e5; signed main() { jakos(); int n; cin >> n; vector<pair<int, int>> a; for (int i = 0; i < n; i++) { int b; ...
10
CPP
#include <bits/stdc++.h> using namespace std; constexpr int maxn = 105, inf = 0x3f3f3f3f; int n; int a[maxn], vis[maxn], b[maxn]; int main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; } int m; cin >> m; for (int i = 1; i <= m; i++) { int k, pos; cin >> k >> pos; int cnt = 0; ...
10
CPP
#include <bits/stdc++.h> using namespace std; int main() { long long n, m; cin >> n; long long x[n + 5]; for (long long i = 0; i < n; i++) { cin >> x[i]; } cin >> m; long long ans = 1e+18; deque<long long> y, z; for (long long j = 0; j < m; j++) { long long k, pos; cin >> k >> pos; y.c...
10
CPP
#include <bits/stdc++.h> using namespace std; bool cmp(pair<long long int, int> p, pair<long long int, int> q) { if (p.first > q.first) return 1; else if (p.first < q.first) return 0; else { if (p.second < q.second) return 1; else return 0; } } int main() { ios_base::sync_with_stdi...
10
CPP
#include <bits/stdc++.h> using namespace std; const long long N = 1e5; bool comp(pair<long long, long long> a, pair<long long, long long> b) { if (a.first < b.first) return true; if (a.first > b.first) return false; if (a.second < b.second) return false; return true; } signed main() { ios_base::sync_with_stdi...
10
CPP
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 10; const int mod = 1e9 + 7; int head[N]; int dis[N], ecnt; int fa[N]; int cat[2005][2005]; long long gcd(long long a, long long b) { return a % b == 0 ? b : gcd(b, a % b); } long long qpow(long long base, long long n) { long long ans = 1; while (n...
11
CPP
#include <bits/stdc++.h> using namespace std; const long long INF = (long long)1 << 62; const long long MOD = 1e9 + 7; const int iINF = 1 << 30; const double PI = 3.14159265359; int LSOne(int n) { return n & (-n); } class FenwickTree { private: vector<int> ft; public: FenwickTree(int n) { ft.assign(n + 1, 0); } ...
11
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int n; long long a[N], id[N]; pair<long long, long long> G[N]; void Upd(int x, int y) { while (x <= n) { G[x].first++; G[x].second += y; x += (x & -x); } } pair<long long, long long> Get(int x) { pair<long long, long long> res; res...
11
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int N; int position[maxn]; long long sum1[maxn << 2], sum2[maxn << 2]; void add(long long* bit, int pos, long long val) { while (pos <= N) { bit[pos] += val; pos += pos & (-pos); } } long long query(long long* bit, int pos) { long lo...
11
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; int a[maxn]; class BIT { public: long long a[maxn]; void add(int x, long long c) { for (int i = x; i < maxn; i += i & -i) a[i] += c; } long long sum(int x) { long long res = 0; for (int i = x; i > 0; i -= i & -i) res += a[i]; ...
11
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5; int a[N], p[N], inv[N], n; int f[N + 1]; int read(int idx) { int sum = 0; idx++; while (idx > 0) { sum += f[idx]; idx -= (idx & -idx); } return sum; } void update(int idx, int val) { idx++; while (idx <= n) { f[idx] += val; i...
11
CPP
#include <bits/stdc++.h> using namespace std; struct fenwick { int N; vector<int> bit; fenwick(int n = 1e5) { N = n + 5; bit.assign(N, 0); } void resize(int n) { N = n + 5; bit.assign(N, 0); } void update(int x, int val) { while (x < N) { bit[x] += val; x += x & -x; } ...
11
CPP
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 10; long long sum1[maxn]; long long sum2[maxn]; long long n; long long lowbit(long long x) { return x & -x; } void add(long long *sum, long long x, long long v) { while (x <= n) { sum[x] += v; x += lowbit(x); } } long long query(long...
11
CPP
#include <bits/stdc++.h> using namespace std; const long long maxn = 2e5 + 5; long long c[maxn], d[maxn]; long long n; long long lowbit(long long x) { return x & (-x); } void update(long long i, long long k) { while (i <= n) { c[i] += k; i += lowbit(i); } } long long getsum(long long i) { long long res = ...
11
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; const int oo = 1e9 + 7; int a[maxn], c[maxn], n; int pos[maxn]; long long ans[maxn]; void update(int x) { for (int i = x; i <= n && i; i += i & (-i)) c[i]++; } long long query(int x) { long long ans = 0; while (x) ans = ans + 1ll * c[x], x -=...
11
CPP
#include <bits/stdc++.h> using namespace std; struct Node { Node *l, *r; int count; long long sum; int ask(int k, int ll, int rr) { if (ll == rr) { return count; } int mid = (ll + rr) >> 1; if (k <= mid) { return l ? l->ask(k, ll, mid) : 0; } else { return (l ? l->count : 0...
11
CPP
#include <bits/stdc++.h> using namespace std; long long const inf = 1e9; long long const mod = 1e9 + 7; long double const eps = 1e-9; long long bit[200005]; long long bit2[200005]; long long sumbit[200005]; long long n; void update(long long k) { while (k <= 200000) { bit[k] += 1; k += k & -k; } } long long...
11
CPP
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; int a[MAX], p[MAX], n; long long c1[MAX], c2[MAX]; set<int> st; void add(long long *c, int x, int k) { for (; x <= n; x += x & -x) c[x] += k; } long long query(long long *c, int x) { long long sum = 0; for (; x; x -= x & -x) sum += c[x]; ret...
11
CPP
#include <bits/stdc++.h> using namespace std; const int N = 1e6 + 5; long long pos[N], s1[N], s2[N]; int a[N]; int n; void add(long long s[], int pos, long long v) { while (pos <= n) { s[pos] += v; pos += pos & (-pos); } } long long query(long long s[], int pos) { long long res = 0; while (pos) { re...
11
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; long long sum1[maxn << 2], sum2[maxn << 2]; int N, pos[maxn], a[maxn]; void update(long long* tree, int pos, int l, int r, int id, long long val) { if (l > r || pos < l || pos > r) return; if (pos == l && pos == r) { tree[id] += val; } e...
11
CPP
#include <bits/stdc++.h> using namespace std; long long n, fwk[2][200001], ps[200001] = {}, pv[200001] = {}, to1 = 0, to2 = 0; set<long long> s; set<long long>::iterator it; void upd(int x, int t, long long v) { for (; x <= n; x += x & (-x)) { fwk[t][x] += v; } } long long qry(int x, int t) { long long to = 0...
11
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 7; int a[N]; struct fenwick { long long fen[N]; fenwick() { memset(fen, 0, sizeof fen); } void add(int x, int d) { for (int i = x + 1; i < N; i += i & -i) { fen[i] += d; } } long long sum(int x) { long long ans = 0; for (i...
11
CPP
#include <bits/stdc++.h> using namespace std; const long long inf = 1e9 + 7; const long long INF = 1LL << 60; const long long mod = 1e9 + 7; const long double eps = 1e-8; const long double pi = acos(-1.0); template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } templa...
11
CPP
#include <bits/stdc++.h> using namespace std; const long long maxn = 1e5 + 5; const long long MAXN = 1e6 + 5; long long n, m, t; long long a[MAXN]; long long tree1[MAXN], tree2[MAXN]; long long pos[MAXN]; void add(long long *tree, long long x, long long xx) { while (x <= n) tree[x] += xx, x += (x & (-x)); } long long...
11
CPP
#include <bits/stdc++.h> using namespace std; long long n, fwk[2][200001], ps[200001] = {}, pv[200001] = {}, to1 = 0, to2 = 0; set<long long> s; set<long long>::iterator it; void upd(int x, int t, long long v) { for (; x <= n; x += x & (-x)) { fwk[t][x] += v; } } long long qry(int x, int t) { long long to = 0...
11
CPP
#include <bits/stdc++.h> using namespace std; int p[200005]; long long ret[200005]; long long inv[200005], sum[200005]; void update(long long *pen, int ind, int val) { while (ind < 200005) { pen[ind] += val; ind += ind & (-ind); } } long long query(long long *pen, int ind) { long long ret = 0; while (in...
11
CPP
#include <bits/stdc++.h> using namespace std; const int NN = (int)2e5 + 5; int A[NN]; int pos[NN]; int n; long long tree_cnt[NN]; long long tree_sum[NN]; long long read(long long* tree, int idx) { idx++; long long res = 0; while (idx > 0) { res += tree[idx]; idx -= (idx & (-idx)); } return res; } void...
11
CPP
#include <bits/stdc++.h> using namespace std; const int mod = 1000000007; int n, a[200010], p[200010], c[200010]; long long inv[200010]; set<int> st; set<int>::iterator it; int Lowbit(int x) { return x & (-x); } void Update(int x, int d) { while (x <= n) { c[x] += d; x += Lowbit(x); } } int Getsum(int x) { ...
11
CPP
#include <bits/stdc++.h> const int maxn = 200000 + 10; class BIT { private: int n; int bit[maxn]; public: BIT(int size) { n = size; std::fill(bit, bit + size + 1, 0); } void add(int x, int v) { while (x <= this->n) { bit[x] += v; x += ((x) & (-x)); } } int query(int x) { ...
11
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double PI = acos((long double)-1.0); const double EPS = 1e-10; const int MOD = 1e9 + 7; template <typename T> void cmin(T &x, T y) { if (y < x) x = y; } template <typename T> void cmax(T &x, T ...
11
CPP
#include <bits/stdc++.h> using namespace std; int T, n, m, p, k, a[200010], pos[200010], bit[200010], hd; long long ans = 0; int query(int a) { int tmp = 0; for (int i = a; i >= 1; i -= (i & -i)) tmp += bit[i]; return tmp; } void add(int a, int x) { for (int i = a; i <= n; i += (i & -i)) bit[i] += x; } set<int>...
11
CPP
#include <bits/stdc++.h> using namespace std; const int maxd = 4e5 + 10; long long t1[maxd], t2[maxd], pos[maxd], a[maxd], n; void add(long long* t, long long x, long long v) { for (; x < maxd; x += (x & -x)) t[x] += v; } long long query(long long* t, long long x) { long long ans = 0; for (; x; x -= (x & -x)) ans...
11
CPP
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { return (b == 0 ? a : gcd(b, a % b)); } char vow[] = {'a', 'e', 'i', 'o', 'u'}; int dx[] = {1, -1, 0, 0}; int dy[] = {0, 0, 1, -1}; const int N = 4e5 + 30; const long long int mod = -1e11; int n; int tx[N]; set<long lon...
11
CPP
#include <bits/stdc++.h> using namespace std; const int mod = 1e9 + 7; const int maxn = 2e5 + 233; int ch[maxn]; int a[maxn], n, p[maxn]; long long ans[maxn], sum[maxn]; void add(int x, int v) { for (int i = x; i <= n; i += i & (-i)) ch[i] += v; } int query(int x) { int sum = 0; for (int i = x; i; i -= i & (-i)) ...
11
CPP
#include <bits/stdc++.h> using namespace std; const long long maxn = 200000; long long a[200005], pos[200005]; long long sum1[200005], sum2[200005]; void add(long long *sum1, long long x, long long val) { while (x <= maxn) { sum1[x] += val; x += x & (-x); } } long long sum(long long *sum1, long long pos) { ...
11
CPP
#include <bits/stdc++.h> using namespace std; using vi = vector<int>; using pii = pair<int, int>; using vii = vector<pii>; using ll = long long; int solve(); int main(int argc, char* argv[]) { ::std::ios::sync_with_stdio(false); ::std::cin.tie(0); ::std::cout.tie(0); int t = 1; while (t--) { solve(); } ...
11
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int N; int position[maxn]; long long sum1[maxn << 2], sum2[maxn << 2]; void add(long long* bit, int pos, long long val) { while (pos <= N) { bit[pos] += val; pos += pos & (-pos); } } long long query(long long* bit, int pos) { long lo...
11
CPP
#include <bits/stdc++.h> using namespace std; int n; int a[300005], pos[300005]; int lowbit(int now) { return now & (-now); } long long sum[5][300005]; void add(int flag, int now, int val) { for (int i = now; i <= n; i += lowbit(i)) sum[flag][i] += val; } long long query(int flag, int now) { long long ans = 0; fo...
11
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 0x3f3f3f3f; const long long LINF = 0x3f3f3f3f3f3f3f3fLL; const double PI = acos((long double)-1.0); const double EPS = 1e-10; const int MOD = 1e9 + 7; template <typename T> void cmin(T &x, T y) { if (y < x) x = y; } template <typename T> void cmax(T &x, T ...
11
CPP
n = int(input()) a = [0] + list(map(int, input().split())) pos, pb, ps = [[0] * (n + 1) for x in range(3)] def add(bit, i, val): while i <= n: bit[i] += val i += i & -i def sum(bit, i): res = 0 while i > 0: res += bit[i] i -= i & -i return res def find(bit, sum): ...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; int n; int a[MAXN]; int pos[MAXN]; struct BIT { long long tree[MAXN]; BIT() {} int LB(int x) { return x & -x; } void Modify(int p, long long k) { while (p <= n) { tree[p] += k; p += LB(p); } } long long Query(int p) ...
11
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 1061109567; const long long LINF = 4557430888798830399ll; const int MOD = 1000000007; long long qpow(long long x, long long n) { long long res = 1; while (n) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } stru...
11
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 1061109567; const long long LINF = 4557430888798830399ll; const int MOD = 1000000007; long long qpow(long long x, long long n) { long long res = 1; while (n) { if (n & 1) res = res * x % MOD; x = x * x % MOD; n >>= 1; } return res; } stru...
11
CPP
#include <bits/stdc++.h> using namespace std; const bool debug = true; int p[200001]; int pos[200001]; class seg_tree { int* st; int n; public: seg_tree(int a) { st = new int[2 * a]; for (int i = 0; i < 2 * a; i++) st[i] = 0; n = a; } void set(int x) { x += n; st[x] = 1; x /= 2; ...
11
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1, base = (1 << 19); int n, p[N], inv_t[2 * base + 1], where[N], pref; long long pos_t[2 * base + 1]; void add(int pos) { pos += base; while (pos) { inv_t[pos]++; pos /= 2; } } int sum(int l, int r) { l += base; r += base; int res = i...
11
CPP
#include <bits/stdc++.h> using namespace std; const int MAX_N = 2e5 + 10; int bit[MAX_N], n, pos[MAX_N], x; long long ans = 0; int lowbit(int x) { return x & (-x); } int sum(int x) { int res = 0; while (x < MAX_N) { res += bit[x]; x += lowbit(x); } return res; } void update(int x) { while (x) { bi...
11
CPP
#include <bits/stdc++.h> using namespace std; const int MAX = 2e5 + 5; int a[MAX], p[MAX], n; long long c1[MAX], c2[MAX]; set<int> st; void add(long long *c, int x, int k) { for (; x <= n; x += x & -x) c[x] += k; } long long query(long long *c, int x) { long long sum = 0; for (; x; x -= x & -x) sum += c[x]; ret...
11
CPP
#include <bits/stdc++.h> using namespace std; const int INF = 1061109567; const int MAXN = 201010; int n, median; int v[MAXN]; int ind[MAXN]; long long st[4 * MAXN]; long long adjust[MAXN]; long long inversions[MAXN]; priority_queue<int> maxheap; priority_queue<int, vector<int>, greater<int> > minheap; void update(int ...
11
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long bit[N] = {}; int idx[N] = {}; int n; priority_queue<int> A; priority_queue<int, vector<int>, greater<int>> B; inline long long __abs(int x) { return (x ^ (x >> 31)) - (x >> 31); } long long sum(int x) { int ret = 0; while (x) { ret +...
11
CPP
#include <bits/stdc++.h> const int inf = (1 << 29) - 1; const int maxn = (int)2e5 + 10; const int mod = (int)1e9 + 7; using namespace std; int n; int p[maxn]; long long t[2][maxn]; int rp[maxn]; void upd(int id, int pos, int val) { for (int i = pos; i <= n; i |= i + 1) t[id][i] += val; } long long get(int id, int pos...
11
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 9; long long mid[N], a[N], mark[N], k, f1[N][2], n, g[N], h[N], p, ct, cn, tvn = 1, tedad[N * 4]; string s, s2; long long saghf(long long x) { return (x / 2) + (x % 2); } string binary(int m, int k) { string g = ""; for (long long i = 0; i < k; i...
11
CPP
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; long long bit[N] = {}; int idx[N] = {}; int n; priority_queue<int> A; priority_queue<int, vector<int>, greater<int>> B; long long sum(int x) { int ret = 0; while (x) { ret += bit[x]; x -= (x & -x); } return ret; } void add(int x, int v...
11
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 10; int n; int pos[maxn]; long long sum1[maxn], sum2[maxn]; int lowbit(int x) { return x & -x; } void add(long long *sum, int x, long long v) { while (x <= n) { sum[x] += v; x += lowbit(x); } } long long query(long long *sum, int x) { lo...
11
CPP
#include <bits/stdc++.h> using namespace std; long long ans, n, a[210000], x, sum1, sum2, las; int rd[450000], siz[450000], son[450000][2], v[450000], root, num[450000], cnt; priority_queue<int> q1; priority_queue<int, vector<int>, greater<int> > q2; inline void update(int x) { if (!q2.size() || x > q2.top()) q2....
11
CPP
#include <bits/stdc++.h> const long long maxn = 200000 + 10; class BIT { private: long long n; long long bit[maxn]; public: BIT(long long size) { n = size; std::fill(bit, bit + maxn, 0); } void add(long long x, long long v) { while (x <= this->n) { bit[x] += v; x += ((x) & (-x)); ...
11
CPP
#include <bits/stdc++.h> using namespace std; const long long MAXN = 200000 + 10; long long BIT1[MAXN], BIT2[MAXN]; long long N; void update(long long p, long long num, long long *BIT) { for (; p <= N; p += p & -p) { BIT[p] += num; } } long long query(long long p, long long *BIT) { long long sum = 0; for (;...
11
CPP
#include <bits/stdc++.h> using namespace std; const int MAXN = 2e5 + 5; long long sum1[MAXN], sum2[MAXN], a[MAXN], pos[MAXN]; void add1(long long x, long long y) { if (!x) return; for (; x < MAXN; x += x & -x) { sum1[x] += y; } } long long query1(long long x) { long long ans = 0; for (; x; x -= x & -x) { ...
11
CPP
#include <bits/stdc++.h> using namespace std; const int maxn = 3e5 + 5; const int INF = 0x3f3f3f3f; const int mod = 1e9 + 7; const double Pi = acos(-1); 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; } double dpow(double a, l...
11
CPP
#include <bits/stdc++.h> using namespace std; int s[200005], sum[200005], ara[200005], p[200005], seg[4 * 200005]; void add(int x, int n) { while (x <= n) { sum[x]++; x += (x & -x); } return; } int query(int x) { int ret = 0; while (x) { ret += sum[x]; x -= (x & -x); } return ret; } void u...
11
CPP
from bisect import bisect_right, bisect_left # instead of AVLTree class BITbisect(): def __init__(self, InputProbNumbers): # 座圧 self.ind_to_co = [-10**18] self.co_to_ind = {} for ind, num in enumerate(sorted(list(set(InputProbNumbers)))): self.ind_to_co.append(num) ...
11
PYTHON3
#include <bits/stdc++.h> using namespace std; const int maxn = 2e5 + 7; int n, sum[maxn], r[maxn]; void add(int i) { while (i <= n) { sum[i]++; i += i & (-i); } } int getsum(int i) { int ans = 0; while (i) { ans += sum[i]; i -= i & (-i); } return ans; } int bs(int s, int e, int t) { int mi...
11
CPP
#include <bits/stdc++.h> using namespace std; using ll = long long; using dd = double; using pll = pair<ll, ll>; using tll = tuple<ll, ll, ll>; using vll = vector<ll>; using vdd = vector<dd>; using vpll = vector<pll>; using vtll = vector<tll>; using vvll = vector<vll>; using vvdd = vector<vdd>; using vvpll = vector<vpl...
11
CPP
#include <bits/stdc++.h> using namespace std; const int MX = 2e5 + 5, MXX = 23; const long long mod = 1e9 + 7, inf = 1e18 + 6; int n, a[MX], ind[MX], ver[MX]; void add(int l) { for (int i = l + 1; i < MX; i += i & -i) ver[i]++; } int ask(int pn) { int ans = 0; for (pn++; pn; pn -= pn & -pn) ans += ver[pn]; retu...
11
CPP
#include <bits/stdc++.h> int size = 256 * 1024; int Count(std::vector<int>& tree, int l, int r) { l += size; r += size; int ans = 0; while (l <= r) { if (l % 2) { ans += tree[l]; ++l; } if (r % 2 == 0) { ans += tree[r]; --r; } if (l > r) break; r >>= 1; l >>= ...
11
CPP