QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#405060#7937. Fast XORtingucup-team992#WA 120ms6340kbC++201.7kb2024-05-05 09:53:202024-05-05 09:53:22

Judging History

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

  • [2024-05-05 09:53:22]
  • 评测
  • 测评结果:WA
  • 用时:120ms
  • 内存:6340kb
  • [2024-05-05 09:53:20]
  • 提交

answer

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

#define F first
#define S second
#define ar array
typedef int uci;
#define int long long
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define ll long long
typedef pair<int, int> pii;
typedef vector<int> vi;

int n;
int count(int v, vector<int> &bit){
    v++;
    int out{};
    while(v >= 1){
        out += bit[v-1];
        v ^= v&(-v);
    }
    return out;
}

void add(int v, vector<int> &bit){
    v++;
    while(v <= n){
        bit[v-1]++;
        v += v&(-v);
    }
}

void solve(){
    cin >> n;
    vector<int> a(n);
    for(int i{}; i < n; ++i)
        cin >> a[i];

    int c{};
    int t = n;
    while(t){
        t >>= 1;
        c++;
    }
    c--;


    int out{};
    int mask{};
    for(int i = c; i >= 1; --i){
        int totinv{};
        int maxinv{};
        for(int j{}; j < n; j += (1<<i)){
            maxinv += (1ll<<i)*((1ll<<i)-1)/2;
            int ones{};
            for(int k = j; k < j+(1<<i); ++k){
                if(a[k]&(1<<(i-1)))
                    ones++;
                else{
                    totinv += ones;
                }
            }
        }
        maxinv -= totinv;
        if(totinv >= maxinv+1){
            for(int j{}; j < n; ++j){
                a[j] ^= (1<<(i-1));
            }
            out++;
        }
        mask |= (1<<(i-1));
        stable_sort(a.begin(), a.end(), [=](auto b, auto c){
            return (b&mask) < (c&mask);
                });
        out += min(maxinv, totinv);
    }

    cout << out << '\n';
}

uci main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    solve();
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3572kb

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: 3564kb

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: 120ms
memory: 6340kb

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'