QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#561578#4425. CakewisniewskijWA 4800ms155984kbC++202.7kb2024-09-13 00:08:052024-09-13 00:08:05

Judging History

你现在查看的是最新测评结果

  • [2024-09-13 00:08:05]
  • 评测
  • 测评结果:WA
  • 用时:4800ms
  • 内存:155984kb
  • [2024-09-13 00:08:05]
  • 提交

answer

#include <bits/stdc++.h>

#define ndl '\n'
#define ll long long
#define INF 1000000007
#define st first
#define nd second
#define debug(x) cout << #x << ": " << x << ndl
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define lb lower_bound
#define ub upper_bound
#define all(x) (x).begin(), (x).end()

using namespace std;

ll P{ static_cast<ll>(1e9 + 7) };

void rob() {
    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(2)), b(n, vector<int>(2));
    for (int i = 0;i < n;i++) cin >> a[i][0];
    for (int i = 0;i < n;i++) cin >> a[i][1];
    for (int i = 0;i < n;i++) cin >> b[i][0];
    for (int i = 0;i < n;i++) cin >> b[i][1];
    for (int i = 1;i < n;i += 2) {
        swap(a[i][0], a[i][1]);
        swap(b[i][0], b[i][1]);
    }
    vector<ll> ah(n), bh(n);
    for (int i = 0;i < n;i++) {
        ah[i] = a[i][0] + P * a[i][1];
        bh[i] = b[i][0] + P * b[i][1];
    }

    map<ll, vector<int>> hidb;
    map<ll, int> idx_b;
    vector<int> perm(n);

    for (int i = 0;i < n;i++) {
        if (hidb.find(bh[i]) == hidb.end()) {
            hidb.insert({ bh[i], vector<int>(1, i) });
            idx_b[bh[i]] = 0;
        }
        else {
            hidb[bh[i]].push_back(i);
        }
    }

    bool ok = true;

    for (int i = 0;i < n;i++) {
        if (hidb.find(ah[i]) == hidb.end() || hidb[ah[i]].size() <= idx_b[ah[i]]) {
            ok = false;
            break;
        }
        else {
            perm[i] = hidb[ah[i]][idx_b[ah[i]]++];
        }
    }
    if (!ok) {
        cout << -1 << '\n';
        return;
    }
    int ans = 0;
    vector<int> tmp(n);
    function<void(int, int)> merge_sort = [&](int a, int b) {
        if (a >= b) return;
        int mid_point = (a + b) / 2;
        merge_sort(a, mid_point);
        merge_sort(mid_point + 1, b);
        int i1 = a, i2 = mid_point + 1;
        for (int i = a; i <= b;i++) {
            if (i1 == mid_point + 1) {
                tmp[i] = perm[i2++];
            }
            else if (i2 == b + 1) {
                tmp[i] = perm[i1++];
            }
            else {
                if (perm[i1] <= perm[i2]) {
                    tmp[i] = perm[i1++];
                }
                else {
                    ans += i2 - i;
                    tmp[i] = perm[i2++];
                }
            }
        }
        for (int i = a; i <= b;i++)
            perm[i] = tmp[i];
        };
    merge_sort(0, n - 1);
    cout << ans << '\n';
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int t;
    cin >> t;
    for (int i = 0;i < t;i++)
        rob();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 4800ms
memory: 155984kb

input:

4
500000
471518156 319758862 812815356 520822448 129241996 461169933 796713727 608641317 281180101 953966756 749634941 274104949 996181952 88142916 998544672 125597509 991731126 974767231 338911715 674197249 167602044 682799026 226927279 703198907 216742488 8185420 94921423 690039818 859329736 45428...

output:

0
-1
445698416
-1855464059

result:

wrong answer 3rd lines differ - expected: '124999750000', found: '445698416'