-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransaction.cpp
More file actions
83 lines (68 loc) · 1.57 KB
/
Transaction.cpp
File metadata and controls
83 lines (68 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include<bits/stdc++.h>
#define mod 1000000007
#define F first
#define S second
typedef long long ll;
using namespace std;
int b[100005];
int blocksize = 319;
int root[319][100005];
int main()
{
int t,q;
scanf("%d %d",&t,&q);
for(int i = 0; i<t; ++i)
{
scanf("%d",&b[i]);
}
for(int i = 0; i<319; ++i)
{
for(int j = 0; j<100005; ++j)
{
root[i][j] = 0;
}
}
for(int i = 0; i<blocksize; ++i)
{
for(int j = i*blocksize; j<min(i*blocksize+blocksize,t); ++j)
root[i][b[j]]++;
for(int j = 99999; j>0; j--)
root[i][j] = root[i][j] + root[i][j+1];
}
while(q--)
{
int m,n;
scanf("%d %d",&m,&n);
int count = 0;
for(int i = 0; i<blocksize; i++)
{
count = count + root[i][m];
}
if(count<n)
{
printf("-1\n");
continue;
}
count = 0;
int blockspassed = 0;
while(count + root[blockspassed][m] < n)
{
count = count + root[blockspassed][m];
blockspassed++;
}
int start = blockspassed*blocksize;
int ans = 0;
for(int i = start; i < start + blocksize; i++)
{
if(b[i] >= m)
{
count++;
ans = b[i];
}
if(count == n)
break;
}
printf("%d\n",ans);
}
return 0;
}