POJ 2104 K-th Number——分块平方分割
区间推荐左闭右开
#include #include #include #include #include using namespace std;const int maxn = 1e5+10;const int len = 1000;int n, m, a[maxn], sa[maxn];vector v[maxn/len];int main() { scanf("%d %d", &n, &m); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); sa[i] = a[i]; v[i/len].push_back(a[i]); } sort(sa, sa+n); for (int i = 0; i < n / len; i++) sort(v[i].begin(), v[i].end()); int l, r, k; while (m--) { scanf("%d %d %d", &l, &r, &k); l--; int ll = -1, rr = n-1; while (rr - ll > 1) { int mid = (ll + rr)/2; int x = sa[mid], y = 0; int lll = l, rrr = r; while (lll < rrr && lll % len != 0) if (a[lll++] <= x) y++; while (lll < rrr && rrr % len != 0) if (a[--rrr] <= x) y++; for (; lll < rrr; lll += len) { int index = lll/len; y += upper_bound(v[index].begin(), v[index].end(), x) - v[index].begin(); } if (y >= k) rr = mid; else ll = mid; } printf("%d\n", sa[rr]); } return 0;}
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
暂时没有评论,来抢沙发吧~