QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#786723#7937. Fast XORtingucup-team3646WA 35ms6288kbC++201.8kb2024-11-26 23:05:062024-11-26 23:05:08

Judging History

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

  • [2024-11-26 23:05:08]
  • 评测
  • 测评结果:WA
  • 用时:35ms
  • 内存:6288kb
  • [2024-11-26 23:05:06]
  • 提交

answer

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

using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define rep2(i, l, r) for (ll i = l; i < r; i++)

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

#define all(A) A.begin(), A.end()
#define elif else if
using pii = pair<ll, ll>;

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

struct IOSetup {
  IOSetup() {
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
} iosetup;

template <class T>
void print(vector<T> a) {
  for (auto x : a) cerr << x << ' ';
  cout << endl;
}

void print(auto x) { cout << x << endl; }

template <class Head, class... Tail>
void print(Head &&head, Tail &&...tail) {
  cout << head << ' ';
  print(forward<Tail>(tail)...);
}

struct BIT {
  ll n;
  vector<ll> data;
  
  BIT() = default;
  BIT(ll n) : n(n), data(n + 1, 0) { }
  
  // a_x += val;
  void add(ll x, ll val) {
    x++;
    for ( ; x <= n; x += x & -x) data[x] += val;
    return;
  }
  
  // sum of a[0, x)
  ll sum(ll x) {
    ll ret = 0;
    for ( ; x > 0; x -= x & -x) ret += data[x];
    return ret;
  }
  
  // sum of a[lx, rx)
  ll sum(ll lx, ll rx) {
    return sum(rx) - sum(lx);
  }  
};

int main() {
  int n;
  cin>>n;
  vi a(n);
  rep(i,n)cin>>a[i];
  ll inv=0;
  BIT bit(n);
  rep(i,n){
    inv+=bit.sum(a[i],n);
    bit.add(a[i],1);
  }
  ll ans2=inv+1;
  for(int i=1;i<n;i*=2){
    ll now=0,nxt=0,c0=0,c1=0;
    rep(j,n){
      if((a[j]&i)==0){
        now+=c1;
        c0++;
      }
      else{
        nxt+=c0;
        c1++;
      }
    }
    if(now>nxt){
      ans2+=-now+nxt;
    }
  }
  cout<<min(inv,ans2)<<endl;
}

详细

Test #1:

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

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

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: 35ms
memory: 6288kb

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:

16883827399

result:

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