C
Solution
Code
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define itn int
#define memmax 0x7fffffff
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
const ll MOD = 1000000007;
const int intmax = 2147483647;
const double PI = acos(-1.0);
const double eps = 1e-6;
const int INF = 1000000000;
const int maxn = 1e5 + 10;
inline ll read()
{
ll x = 0, f = 1;
char ch = getchar();
while (ch < '0' || ch > '9')
{
if (ch == '-')
f = -1;
ch = getchar();
}
while (ch >= '0' && ch <= '9')
{
x = x * 10 + ch - 48;
ch = getchar();
}
return x * f;
}
inline void write(ll x)
{
char F[200];
ll tmp = x > 0 ? x : -x;
if (x < 0)
putchar('-');
ll cnt = 0;
while (tmp > 0)
{
F[cnt++] = tmp % 10 + '0';
tmp /= 10;
}
while (cnt > 0)
putchar(F[--cnt]);
}
ll t;
ll n;
struct node
{
ll val;
ll ind;
} a[100005], b[100005];
ll c[100005], ans[100005];
bool cmp(node a, node b)
{
return a.val < b.val;
}
void print()
{
for (int i = 1; i <= n; i++)
{
cout << ans[i];
}
cout << endl;
}
void solve()
{
memset(c, 0, sizeof(c));
memset(ans, 0, sizeof(ans));
cin >> n;
for (int i = 1; i <= n; i++)
{
cin >> a[i].val;
a[i].ind = i;
}
for (int i = 1; i <= n; i++)
{
cin >> b[i].val;
b[i].ind = i;
}
sort(a + 1, a + n + 1, cmp);
sort(b + 1, b + n + 1, cmp);
cout << "ans = ";
for (int i = 1; i <= n; i++)
{
c[b[i].ind] = i;
}
ll tmp = n + 1;
for (int i = n; i >= 1; i--)
{
tmp = min(tmp, c[a[i].ind]);
ans[a[i].ind] = 1;
cout << "ans[" << a[i].ind << "] = " << 1 << endl;
if (tmp == i)
{
print();
return;
}
}
}
void run_code()
{
cin >> t;
for (int i = 1; i <= t; i++)
{
solve();
}
}
void run_code_with_time()
{
clock_t start, finish;
double totaltime;
start = clock();
run_code();
finish = clock();
totaltime = (double)(finish - start) / CLOCKS_PER_SEC;
printf("此程序的运行时间为%.36lf秒!\n", totaltime);
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
run_code();
return 0;
}