QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#593856 | #7937. Fast XORting | ATM12345# | WA | 56ms | 13536kb | C++17 | 1003b | 2024-09-27 16:27:47 | 2024-09-27 16:27:48 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define Ma 1000005
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
using namespace std;
ll n;
ll a[Ma];
ll b[Ma];
ll ans[Ma],all[Ma],res=0;
void merage(ll l,ll r,ll len)
{
if (l==r)
return;
ll mid=(l+r)>>1;
ll cnt=0;
vector <ll> mi,ma;
for (ll i=l;i<=r;i++)
{
if (a[i]>>len&1)
ma.pb(a[i]);
else
cnt+=ma.size(),mi.pb(a[i]);
}
ll be=l;
for (auto z:mi)
a[be++]=z;
for (auto z:ma)
a[be++]=z;
merage(l,mid,len-1),merage(mid+1,r,len-1);
ans[len]+=cnt;
all[len]+=(r-l+1)*(r-l)/2;
return;
}
void sol()
{
cin>>n;
ll len=0,lim=1;
while (lim<n)
lim<<=1,len++;
for (ll i=1;i<=n;i++)
cin>>a[i];
merage(1,n,len-1);
ll res=0,pri=1;
for (ll i=0;i<len;i++)
res+=ans[i],pri+=min(ans[i],all[i]-ans[i]);
res=min(res,pri);
printf("%lld\n",res);
}
int main()
{
IOS
ll tt=1;
//cin>>tt;
while (tt--)
sol();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 8116kb
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: 7828kb
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: 56ms
memory: 13536kb
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'