#include <iostream> #include<vector> #include<utility> #include<map> #include<cmath> using namespace std; #define ll long long int main() { ll t; cin >> t; while(t--){ vector<ll> setBitCount(30,0); vector<ll> arr; ll n; cin >> n; for(ll i=0;i<n;++i){ ll temp; cin >> temp; arr.emplace_back(temp); ll k=0; while(temp!=0){ if(temp&1==1) setBitCount[k]++; temp=temp>>1; k++; } } ll x = 0; ll limit=0; for(ll i=29;i>=0;i--){ if(setBitCount[i]>0){ limit = i; break; } } for(ll i=0;i<=limit;++i){ if(setBitCount[i]>n/2) x = x + pow(2,i); } ll minSum =0; for(ll i=0;i<n;++i){ minSum = minSum + arr[i]^x; } cout << minSum << endl; } return 0; }
Standard input is empty
Standard output is empty
*** Error in `./prog': munmap_chunk(): invalid pointer: 0x0000557c8ad71d30 *** ======= Backtrace: ========= /lib/x86_64-linux-gnu/libc.so.6(+0x70bcb)[0x2affe7affbcb] /lib/x86_64-linux-gnu/libc.so.6(+0x76f96)[0x2affe7b05f96] ./prog(+0x1090)[0x557c89a21090] ./prog(+0xe1a)[0x557c89a20e1a] /lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf1)[0x2affe7aaf2b1] ./prog(+0xeea)[0x557c89a20eea] ======= Memory map: ======== 2affe6daf000-2affe6dd2000 r-xp 00000000 fd:00 2710543 /lib/x86_64-linux-gnu/ld-2.24.so 2affe6dd2000-2affe6dd6000 rw-p 00000000 00:00 0 2affe6ddf000-2affe6de4000 rw-p 00000000 00:00 0 2affe6fd2000-2affe6fd3000 r--p 00023000 fd:00 2710543 /lib/x86_64-linux-gnu/ld-2.24.so 2affe6fd3000-2affe6fd4000 rw-p 00024000 fd:00 2710543 /lib/x86_64-linux-gnu/ld-2.24.so 2affe6fd4000-2affe6fd5000 rw-p 00000000 00:00 0 2affe6fd5000-2affe7147000 r-xp 00000000 fd:00 2712611 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 2affe7147000-2affe7347000 ---p 00172000 fd:00 2712611 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 2affe7347000-2affe7351000 r--p 00172000 fd:00 2712611 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 2affe7351000-2affe7353000 rw-p 0017c000 fd:00 2712611 /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.22 2affe7353000-2affe7357000 rw-p 00000000 00:00 0 2affe7357000-2affe745a000 r-xp 00000000 fd:00 2710572 /lib/x86_64-linux-gnu/libm-2.24.so 2affe745a000-2affe7659000 ---p 00103000 fd:00 2710572 /lib/x86_64-linux-gnu/libm-2.24.so 2affe7659000-2affe765a000 r--p 00102000 fd:00 2710572 /lib/x86_64-linux-gnu/libm-2.24.so 2affe765a000-2affe765b000 rw-p 00103000 fd:00 2710572 /lib/x86_64-linux-gnu/libm-2.24.so 2affe765b000-2affe7671000 r-xp 00000000 fd:00 2710510 /lib/x86_64-linux-gnu/libgcc_s.so.1 2affe7671000-2affe7870000 ---p 00016000 fd:00 2710510 /lib/x86_64-linux-gnu/libgcc_s.so.1 2affe7870000-2affe7871000 r--p 00015000 fd:00 2710510 /lib/x86_64-linux-gnu/libgcc_s.so.1 2affe7871000-2affe7872000 rw-p 00016000 fd:00 2710510 /lib/x86_64-linux-gnu/libgcc_s.so.1 2affe7872000-2affe788a000 r-xp 00000000 fd:00 2710529 /lib/x86_64-linux-gnu/libpthread-2.24.so 2affe788a000-2affe7a89000 ---p 00018000 fd:00 2710529 /lib/x86_64-linux-gnu/libpthread-2.24.so 2affe7a89000-2affe7a8a000 r--p 00017000 fd:00 2710529 /lib/x86_64-linux-gnu/libpthread-2.24.so 2affe7a8a000-2affe7a8b000 rw-p 00018000 fd:00 2710529 /lib/x86_64-linux-gnu/libpthread-2.24.so 2affe7a8b000-2affe7a8f000 rw-p 00000000 00:00 0 2affe7a8f000-2affe7c24000 r-xp 00000000 fd:00 2710666 /lib/x86_64-linux-gnu/libc-2.24.so 2affe7c24000-2affe7e23000 ---p 00195000 fd:00 2710666 /lib/x86_64-linux-gnu/libc-2.24.so 2affe7e23000-2affe7e27000 r--p 00194000 fd:00 2710666 /lib/x86_64-linux-gnu/libc-2.24.so 2affe7e27000-2affe7e29000 rw-p 00198000 fd:00 2710666 /lib/x86_64-linux-gnu/libc-2.24.so 2affe7e29000-2affe7e2d000 rw-p 00000000 00:00 0 557c89a20000-557c89a22000 r-xp 00000000 fd:00 18708487 /home/bzcNgD/prog 557c89c21000-557c89c22000 r--p 00001000 fd:00 18708487 /home/bzcNgD/prog 557c89c22000-557c89c23000 rw-p 00002000 fd:00 18708487 /home/bzcNgD/prog 557c8ad5f000-557c8ad91000 rw-p 00000000 00:00 0 [heap] 7fff2494d000-7fff2496e000 rw-p 00000000 00:00 0 [stack] 7fff249db000-7fff249dd000 r-xp 00000000 00:00 0 [vdso] 7fff249dd000-7fff249df000 r--p 00000000 00:00 0 [vvar] ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0 [vsyscall]