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 84 85 86 87 88 89 90 91 92
|
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <queue> #include <set> #include <vector> using namespace std;
const int INF = ~0u>>1; typedef pair <int,int> P; #define MID(x,y) ((x+y)>>1) #define iabs(x) ((x)>0?(x):-(x)) #define REP(i,a,b) for(int i=(a);i<(b);i++) #define FOR(i,a,b) for(int i=(a);i<=(b);i++) #define pb push_back #define mp make_pair #define print() cout<<"--------"<<endl
#define maxn 51010
int sum[maxn],num[maxn],use[maxn];
struct Segment{ int l,r,len; Segment(){} Segment(int a,int b,int c){ l = a;r = b; len = c; } }seg[maxn]; int nm; int binary(int key){ int l = 1,r = nm -1,ans; while (l <= r){ int mid = MID(l,r); if (key <= sum[mid]){ ans = mid; r = mid - 1; }else l = mid + 1; } return ans; }
int main(){ int T,n,k,q; cin >> T; int t = 0; while (t ++ < T){ scanf("%d%d%d", &n, &k, &q); for (int i = 1; i <= k; i ++){ scanf("%d", &num[i]); use[i] = num[i]; } use[0] = 0;use[k + 1] = INF; sort(use, use + k + 2);
nm = 1;int r,l; seg[0] = Segment(0,0,0); for (int i = 1; i <= k + 1; i ++){ l = use[i-1] + 1; r = use[i] - 1; if (r > n) r = n; if (r - l + 1 > 0) { seg[nm ++] = Segment(l,r,r - l + 1); } }
memset(sum,0,sizeof(sum)); sum[0] = 0; for (int i = 1; i < nm; i ++){ sum[i] = seg[i].len + sum[i - 1]; }
printf("Case %d:n",t); int cnt; for (int i = 0; i < q; i ++){ scanf("%d", &cnt); if (cnt <= k) { printf("%dn", num[cnt]);continue; } cnt -= k; int index = binary(cnt); printf("%dn",seg[index].r - (sum[index] - cnt)); } } return 0; }
|