Codeforces Round #759 (Div. 2, based on Technocup 2022 Elimination Round 3)

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 = ";

    // 初始化排名(按b的结果)
    for (int i = 1; i <= n; i++)
    {
        c[b[i].ind] = i;
    }

    ll tmp = n + 1;

    // a组从大到小遍历
    for (int i = n; i >= 1; i--)
    {
        // 维护当前a组最大值在b中的排名
        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_with_time();

    run_code();

    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值