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
| #include <cstdio> #include <algorithm> #include <vector> #include <iostream> #include <map> #include <queue> #include <set> #include <cstring> #include <string> #include <cstdlib> #include <cmath> using namespace std; const int inf = 1 << 30; const int maxn = 1e6 + 5; typedef long long ll; const int N = 1005; typedef unsigned long long ull; //char s[maxn], str[maxn], s3[maxn]; //char s[N][N]; //ll da[maxn], dab[maxn], daba[maxn], sum[maxn]; int a[maxn]; struct node { int ls, rs, sum; } tr[maxn << 1]; int cnt; void inser(int &k, int L, int R, int pos) { if (!k) k = ++cnt; tr[k].sum++; if (L == R) { return; } int mid = L + R >> 1; if (mid >= pos) inser(tr[k].ls, L, mid, pos); else inser(tr[k].rs, mid + 1, R, pos); } int ask(int k, int L, int R, int ik) { if (L == R) { return L; } int mid = L + R >> 1; int sum = tr[tr[k].ls].sum; if (sum >= ik) return ask(tr[k].ls, L, mid, ik); else return ask(tr[k].rs, mid + 1, R, ik - sum); } int main() { ios::sync_with_stdio(false); cin.tie(0); int n, m, k; int t; cin >> t; while (t--) { memset(a, 0, sizeof a); memset(tr, 0, sizeof(tr)); cin >> m >> n; k = cnt = 0; int x, id = 0; for (int i = 1; i <= n; i++) { cin >> x; inser(k, -inf, inf, x); if (i & 1) { int pos = (1 + i) / 2; a[id++] = ask(k, -inf, inf, pos); } } cout << m << ' ' << (n + 1) / 2 ; for (int i = 0; i <id; i++) { if (i % 10 == 0) cout << endl; if (i % 10 == 0) cout << a[i]; else cout << ' ' << a[i]; } cout<<endl; } }
|