这题为什么过不了
查看原帖
这题为什么过不了
1134636
FRZ_29楼主2024/5/19 08:00
#include <iostream>
#include <vector>

using namespace std;

const int N = 505;

int n, c[N * N];

long long ans;
vector<int> situation[2];

void merge(int k, int l, int mid, int r)
{
    int x = l, y = mid + 1;
    for (int i = l; i <= r; i++)
    {
        if (y > r || x <= mid && situation[k][x] < situation[k][y])
            c[i] = situation[k][x++];
        else 
            ans += mid - x + 1, c[i] = situation[k][y++];
    }
    for (int i = l; i <= r; i++)
        situation[k][i] = c[i];
}

void mergesort(int k, int l, int r)
{
    if (l == r)
        return ;
    int mid = l + r >> 1;
    mergesort(k, l, mid);
    mergesort(k, mid + 1, r);
    merge(k, l, mid, r);
}

long long calc(int k)
{
    ans = 0;
    mergesort(k, 0, n * n - 1);
    return ans;
}

void solve()
{
    situation[0].clear();
    situation[1].clear();
    for (int i = 1, x; i <= n; i++)
        for (int j = 1; j <= n; j++)
        {
            cin >> x;
            if (x)
                situation[0].push_back(x); 
        }
    for (int i = 1, x; i <= n; i++)
        for (int j = 1; j <= n; j++)
        {
            cin >> x;
            if (x)
                situation[1].push_back(x); 
        }
    cout << (situation[0].size() && (calc(1) - calc(0) & 1) ? "NIE\n" : "TAK\n");
}

int main()
{
    while (cin >> n)
        solve();
    return 0;
}

在acwing上通过了,但在luogu过不了?

2024/5/19 08:00
加载中...