QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#593837 | #7937. Fast XORting | ATM12345# | WA | 36ms | 14076kb | C++17 | 1002b | 2024-09-27 16:19:25 | 2024-09-27 16:19:26 |
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);
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;
merage(l,mid,len-1),merage(mid+1,r,len-1);
ll cnt=0;
ll i=l,j=mid+1,k=0;
while (i<=mid&&j<=r){
if (a[i]<=a[j]) b[k++]=a[i++];
else cnt+=mid-i+1,b[k++]=a[j++];
}
while (j<=r) b[k++]=a[j++];
while (i<=mid) b[k++]=a[i++];
for (ll k=0;k<r-l+1;k++)
a[l+k]=b[k];
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);
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: 1ms
memory: 10016kb
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: 9972kb
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: 36ms
memory: 14076kb
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'