#include<cstdio> #include<algorithm> #include<vector> #include<cctype> usingnamespacestd; constint maxn = 100002; constint B = 1000; int bucket[maxn / B][B]; int a[maxn],nums[maxn];
inlineintread() { int X=0,w=0; char ch=0; while(!isdigit(ch)) {w|=ch=='-';ch=getchar();} while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); return w?-X:X; } intmain(){ int n = read(), m = read(); for (int i = 0; i < n; i++) { a[i] = read(); bucket[i/B][i%B] = a[i]; nums[i] = a[i]; } sort(nums, nums + n); for (int i = 0; i < n / B; i++) sort(bucket[i], bucket[i] + B); while (m--) { int l = read(), r = read(), k = read(); int ul = 0, ur = n; while (ul + 1 < ur) { int mid = (ul + ur) >> 1; int cnt = 0, tl = l - 1, tr = r; // the number of items less than nums[mid] while (tl < tr && tl % B) cnt += (a[tl++] < nums[mid]); while (tl < tr && tr % B) cnt += (a[--tr] < nums[mid]); while (tl < tr) { int bi = tl / B; cnt += lower_bound(bucket[bi], bucket[bi] + B, nums[mid]) - bucket[bi]; tl += B; } if (cnt >= k) ur = mid; else ul = mid; } printf("%d\n", nums[ul]); } }
constint maxn = 100010; int a[maxn],n,m,nums[maxn]; vector<int> vec[maxn * 20];
voidbuild(int v = 1, int l = 0, int r = n){ if (l >= r) return; if (l + 1 == r) { vec[v].push_back(a[l]); } else { int mid = (l + r) >> 1, chl = v * 2, chr = v * 2 + 1; build(chl, l, mid); build(chr, mid, r); vec[v].resize(vec[chl].size() + vec[chr].size()); merge(vec[chl].begin(), vec[chl].end(), vec[chr].begin(), vec[chr].end(), vec[v].begin()); } }
intquery(int L, int R, int x, int v = 1, int l = 0, int r = n){
if (l >= r || r <= L || R <= l) return0; if (L <= l && r <= R) { int res = lower_bound(vec[v].begin(), vec[v].end(), x) - vec[v].begin(); return res; } int mid = (l + r) >> 1, chl = v * 2, chr = v * 2 + 1; int res= query(L, R, x, chl, l, mid) + query(L, R, x, chr, mid, r); return res; }
intmain(){ n = read(),m = read(); for (int i = 0; i < n; i++) { nums[i] = a[i] = read(); } sort(nums, nums + n); build(); while (m--) { int l = read(), r = read(), k = read(); l--; int ul = 0, ur = n; while (ul + 1 < ur) { int mid = (ul + ur) >> 1; if (query(l, r, nums[mid]) >= k) ur = mid; else ul = mid; } printf("%d\n", nums[ul]); } }
#include<cstdio> #include<cctype> #include<algorithm> usingnamespacestd; constint maxn = 100010; inlineintread() { int X=0,w=0; char ch=0; while(!isdigit(ch)) {w|=ch=='-';ch=getchar();} while(isdigit(ch)) X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); return w?-X:X; } structnode{ int l, r, dat; node(int l = 0, int r = 0, int dat = 0):l(l),r(r),dat(dat){} }T[maxn * 20]; int rt[maxn], a[maxn], b[maxn], sz = 0;
voidupdate(int &o, int x, int last, int l, int r){ // [l, r) o = ++sz; T[o] = T[last]; T[o].dat++; if (l + 1 >= r) return; int mid = (l + r) >> 1; if (x < mid) update(T[o].l, x, T[last].l, l, mid); else update(T[o].r, x, T[last].r, mid, r); }
intquery(int t1, int t2, int l, int r, int k){ // [l, r) if (l + 1 >= r) return l; int cnt = T[T[t2].l].dat - T[T[t1].l].dat, mid = (l + r) >> 1; if (cnt >= k) return query(T[t1].l, T[t2].l, l, mid, k); return query(T[t1].r, T[t2].r, mid, r, k - cnt); }
intmain(){ fill(T, T + maxn * 20, node()); fill(rt, rt + maxn, 0); int N = read(), Q = read(); for (int i = 0; i < N; i++) b[i] = a[i] = read(); sort(b, b + N); int n = unique(b, b + N) - b; for (int i = 0; i < N; i++) { a[i] = lower_bound(b, b + n, a[i]) - b; update(rt[i + 1], a[i], rt[i], 0, n); } while (Q--) { int l = read(), r = read(), k = read(); printf("%d\n", b[query(rt[l - 1], rt[r], 0, n, k)]); } }