You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.2 KiB
C++
84 lines
2.2 KiB
C++
#define _CRT_SECURE_NO_WARNINGS
|
|
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
|
|
#include <bits/stdc++.h>
|
|
using namespace std;
|
|
#define CRP(t, x) const t &x
|
|
#define OPL(t, x) bool operator<(CRP(t, x)) const
|
|
#define FIL(x, v) memset(x, v, sizeof(x))
|
|
#define CLR(x) FIL(x, 0)
|
|
#define NE1(x) FIL(x, -1)
|
|
#define INF(x) FIL(x, 0x3f)
|
|
#ifndef _DEBUG
|
|
#define _DEBUG 0
|
|
#endif // !_DEBUG
|
|
#define IFD if (_DEBUG)
|
|
typedef long long ll, i64;
|
|
const int N = 3e5 + 50;
|
|
int a[N], cnt[N][2], b[N];
|
|
int ans[N][2];
|
|
int q, n;
|
|
int C[N];
|
|
bool vis[N];
|
|
int lst[N];
|
|
inline int lowbit(int x) { return x & -x; }
|
|
void inc(int x, int v = 1)
|
|
{
|
|
if (x > 0)
|
|
for (; x <= n; x += lowbit(x)) C[x] += v;
|
|
}
|
|
int sum(int x)
|
|
{
|
|
int r = 0;
|
|
if (x > 0)
|
|
for (; x; x -= lowbit(x)) r += C[x];
|
|
return r;
|
|
}
|
|
int main()
|
|
{
|
|
scanf("%d", &q);
|
|
while (q--)
|
|
{
|
|
scanf("%d", &n);
|
|
for (int i = 0; i < n; i++) scanf("%d", a + i);
|
|
n = unique(a, a + n) - a;
|
|
memset(cnt, 0, (n + 1) << 3);
|
|
memset(ans, 0, (n + 1) << 3);
|
|
memset(lst, 0, (n + 1) << 2);
|
|
memcpy(b, a, n << 2);
|
|
sort(b, b + n);
|
|
int lb = unique(b, b + n) - b;
|
|
for (int i = 0; i < n; i++) a[i] = lower_bound(b, b + lb, a[i]) - b + 1;
|
|
memset(C, 0, (n + 1) << 2);
|
|
memset(vis, 0, (n + 1));
|
|
for (int i = 0, dif = 0; i < n; i++)
|
|
{
|
|
inc(lst[a[i]], -1),
|
|
lst[a[i]] = i;
|
|
cnt[i][0] = dif - sum(a[i]);
|
|
if (!vis[a[i]])
|
|
{
|
|
//inc(a[i]);
|
|
vis[a[i]] = true;
|
|
dif++;
|
|
}
|
|
}
|
|
memset(C, 0, (n + 1) << 2);
|
|
memset(vis, 0, (n + 1));
|
|
for (int i = n - 1; i >= 0; i--)
|
|
{
|
|
cnt[i][1] = sum(a[i] - 1);
|
|
if (!vis[a[i]])
|
|
{
|
|
inc(a[i]);
|
|
vis[a[i]] = true;
|
|
}
|
|
}
|
|
IFD
|
|
{
|
|
for (int i = 0; i < n; i++) printf("%d%c", a[i], " \n"[i == n - 1]);
|
|
for (int i = 0; i < n; i++) printf("%d%c", cnt[i][0], " \n"[i == n - 1]);
|
|
for (int i = 0; i < n; i++) printf("%d%c", cnt[i][1], " \n"[i == n - 1]);
|
|
}
|
|
}
|
|
return 0;
|
|
} |