QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#419682#7937. Fast XORtinggabrielwu#WA 712ms50680kbC++201.7kb2024-05-24 09:16:182024-05-24 09:16:20

Judging History

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

  • [2024-05-24 09:16:20]
  • 评测
  • 测评结果:WA
  • 用时:712ms
  • 内存:50680kb
  • [2024-05-24 09:16:18]
  • 提交

answer

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

#define forn(i,n) for (int i=0; i<(n); i++)
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define f first
#define s second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

template<typename A, typename B> ostream& operator<<(ostream & cout, pair<A,B> const &p) {
    return cout << "("<< p.f << ", "<< p.s << ")";
}
template<typename A> ostream& operator<<(ostream &cout, vector<A> const & v) {
    cout << "[";
    forn(i, v.size()) {
        if(i) cout << ", ";
        cout << v[i];
    }
    return cout << "]";
}

ll inv(vector<int>& v) {
    int n = v.size();
    ll ans = 0, oc = 0;
    forn(i, n) {
        if(v[i] == 1) oc++;
        else ans += oc;
    }
    return ans;
}


int main() {
    cin.tie(0)->sync_with_stdio(0);
    
    int n; cin >> n;
    vector<int> v(n);
    forn(i, n) {
        cin >> v[i];
    }
    int LG = 0; // # of bits
    int nc = n;
    while(nc > 0) {
        LG++;
        nc /= 2;
    }

    vector<map<int, vector<int>>> r(LG+1);
    forn(i, n) {
        for(int j=1; j<=LG; j++) {
            r[j][v[i] >> j].pb((v[i]>>(j-1))&1);
        }
    }
    ll inv_with_move=0, inv_without_move=0;
    for(int i=1; i<=LG; i++) {
        ll wm = 0;
        ll R = -1;
        for(auto p: r[i]) {
            R = p.s.size();
            ll x = inv(p.s);
            // cout << p.s << " " << x << "\n";
            wm += x;
        }
        inv_without_move += wm;
        inv_with_move += min(wm, n*(R-1)/2 - wm);
    }

    cout << min(inv_with_move+1, inv_without_move) << "\n";


   
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

8
0 1 3 2 5 4 7 6

output:

2

result:

ok 1 number(s): "2"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3616kb

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: 712ms
memory: 50680kb

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:

17145325034

result:

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