QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#138946#4425. Cakeckiseki#WA 758ms26456kbC++172.1kb2023-08-12 14:45:392023-08-12 14:45:43

Judging History

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

  • [2023-08-12 14:45:43]
  • 评测
  • 测评结果:WA
  • 用时:758ms
  • 内存:26456kb
  • [2023-08-12 14:45:39]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define all(x) begin(x), end(x)
#ifdef CKISEKI
#define safe cerr << __PRETTY_FUNCTION__ << " line " << __LINE__ << " safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
template <typename ...T>
void debug_(const char *s, T ...a) {
    cerr << "\e[1;32m(" << s << ") = (";
    int cnt = sizeof...(T);
    (..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
    cerr << "\e[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        cerr << (f++ ? ", " : "") << *L;
    cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) safe
#define orange(...) safe
#endif


struct P {
    int x, y, id;
};

void solve() {
    int n;
    cin >> n;
    vector<P> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i].x;
    }
    for (int i = 0; i < n; i++) {
        cin >> a[i].y;
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i].x;
    }
    for (int i = 0; i < n; i++) {
        cin >> b[i].y;
    }

    for (int i = 0; i < n; i++) if (i & 1) {
        swap(a[i].x, a[i].y);
        swap(b[i].x, b[i].y);
    }

    for (int i = 0; i < n; i++)
        a[i].id = b[i].id = i;

    auto u = a;
    auto cmp = [](P a, P b) {
        return tie(a.x, a.y, a.id) < tie(b.x, b.y, b.id);
    };
    sort(u.begin(), u.end(), cmp);

    vector<int> it(n);
    vector<int> p(n);

    for (int i = 0; i < n; i++) {
        int j = lower_bound(u.begin(), u.end(), b[i], cmp) - u.begin();
        if (j < n)
            j += it[j]++;
        if (j >= n || tie(b[i].x, b[i].y) != tie(u[j].x, u[j].y)) {
            cout << -1 << '\n';
            return;
        }
        p[i] = u[j].id;
        debug(i, p[i]);
    }

    int64_t r = 0;
    vector<int> B(n + 1);
    for (int i = n - 1; i >= 0; i--) {
        for (int x = p[i] + 1; x > 0; x -= x & -x)
            r += B[x];
        for (int x = p[i] + 1; x <= n; x += x & -x)
            B[x] += 1;
    }
    cout << r << '\n';
}

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    int T;
    cin >> T;
    while (T--)
        solve();
    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 758ms
memory: 26456kb

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
-1
-1

result:

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