题意:
思路:
比较明显的是我们需要将序列从大到小排序,让后取前
k
k
k个数,再从中选择第
p
o
s
pos
pos小的位置输出当前位置的数即可。
一开始想用
s
e
t
set
set维护,但是
s
e
t
set
set没有找第
k
k
k小的函数,所以就用主席树切了。但是题解给了一个黑科技,来记录一下。
比较全的博客
这个有找第
k
k
k小的函数,所以就变成了一个码量很小的题了。
// Problem: D2. Optimal Subsequences (Hard Version)
// Contest: Codeforces - Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3)
// URL: https://codeforces.com/contest/1262/problem/D2
// Memory Limit: 256 MB
// Time Limit: 3000 ms
//
// Powered by CP Editor (https://cpeditor.org)
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
const int N=1000010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;
int n,m;
int c[N];
PII a[N];
int ans[N];
struct Node {
int k,pos,id;
bool operator < (const Node &W) const {
if(k!=W.k) return k<W.k;
else return pos<W.pos;
}
}q[N];
tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pos;
int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&a[i].X),a[i].X=-a[i].X,a[i].Y=i,c[i]=-a[i].X;
sort(a+1,a+1+n);
scanf("%d",&m);
for(int i=1;i<=m;i++) scanf("%d%d",&q[i].k,&q[i].pos),q[i].id=i;
sort(q+1,q+1+m);
int now=0;
for(int i=1;i<=m;i++) {
while(now<q[i].k) pos.insert(a[++now].Y);
ans[q[i].id]=c[*pos.find_by_order(q[i].pos-1)];
}
for(int i=1;i<=m;i++) printf("%d\n",ans[i]);
return 0;
}
/*
*/