QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#876770#7937. Fast XORtingtassei903#WA 62ms6580kbC++232.4kb2025-01-31 12:49:412025-01-31 12:49:41

Judging History

This is the latest submission verdict.

  • [2025-01-31 12:49:41]
  • Judged
  • Verdict: WA
  • Time: 62ms
  • Memory: 6580kb
  • [2025-01-31 12:49:41]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define ov4(a, b, c, d, name, ...) name
#define rep3(i, a, b, c) for(ll i = (a); i < (b); i += (c))
#define rep2(i, a, b) rep3(i, a, b, 1)
#define rep1(i, n) rep2(i, 0, n)
#define rep0(n) rep1(aaaaa, n)
#define rep(...) ov4(__VA_ARGS__, rep3, rep2, rep1, rep0)(__VA_ARGS__)
#define per(i, a, b) for(ll i = (a)-1; i >= (b); i--)
#define fore(e, v) for(auto&& e : v)
#define all(a) begin(a), end(a)
#define sz(a) (int)(size(a))
#define lb(v, x) (lower_bound(all(v), x) - begin(v))
#define eb emplace_back

template<typename T, typename S> bool chmin(T& a, const S& b) { return a > b ? a = b, 1 : 0; }
template<typename T, typename S> bool chmax(T& a, const S& b) { return a < b ? a = b, 1 : 0; }

const int INF = 1e9 + 100;
const ll INFL = 3e18 + 100;

#define i128 __int128_t

struct _ {
   _() { cin.tie(0)->sync_with_stdio(0), cout.tie(0); }
} __;


void solve() {
    int n;cin >> n;
    vl a(n);rep(i, n) cin >> a[i];
    int m = countr_zero(unsigned(n));

    auto calc = [&](int l, int r, int i) -> vi {
        vi cnt = {0, 0};
        vi res = {0, 0};
        vi f0, f1;
        rep(j, l, r) {
            int x = a[j] >> i & 1;
            res[x] += cnt[1^x];
            cnt[x]++;
            if (x == 0) f0.emplace_back(a[j]);
            else f1.emplace_back(a[j]);
        }
        // cerr << l << " " << r << " " << sz(f0) << " " << sz(f1) << endl;
        rep(i, l, (l + r)/2) a[i] = f0[i-l];
        rep(i, (l+r)/2, r) a[i] = f1[i-(l+r)/2];
        return res;
    };
    
    ll ans = 0;
    ll ans0 = 0;
    rep(i, m) {
        int h = 1 << i;
        vl res = {0, 0};
        rep(j, h) {
            // vl cnt = {0, 0};
            // rep(k, (n/h) * j, (n/h) * (j + 1)) {
            //     // cerr << k << endl;
            //     int x = a[k] >> (m-1-i) & 1;
            //     res[x] += cnt[1^x];
            //     cnt[x]++;
            // }
            auto r = calc((n/h) * j, (n/h)*(j+1), m - 1 - i);
            rep(k, 2)res[k] += r[k];
        }
        // cerr << res[0] << " " << res[1] << endl;
        ans0 += res[0];
        ans += min(res[0], res[1]);
    }
    cout << min(ans0, ans + 1) << endl;

}   

int main() {
    // int T;cin >> T;
    int T = 1;
    while (T--) {
        solve();
    }
} 

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3584kb

input:

8
0 1 3 2 5 4 7 6

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3712kb

input:

8
2 0 1 3 4 5 6 7

output:

2

result:

ok 1 number(s): "2"

Test #3:

score: -100
Wrong Answer
time: 62ms
memory: 6580kb

input:

262144
47482 131703 90418 122675 166494 247529 196154 16950 66501 50357 246808 25929 10418 50538 26955 151884 63776 58023 20073 26544 74785 44064 41836 148543 87920 54172 3270 131495 130960 112122 167229 215767 77499 195004 21391 11039 168999 256346 109690 180904 172679 157200 78594 201857 52784 147...

output:

-1842773

result:

wrong answer 1st numbers differ - expected: '17137565829', found: '-1842773'