QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#691024 | #7937. Fast XORting | ucup-team3699# | WA | 26ms | 9560kb | C++14 | 1.6kb | 2024-10-31 09:28:09 | 2024-10-31 09:28:17 |
Judging History
answer
#include<iostream>
using namespace std;
#define int long long
#define pb push_back
#define F first
#define S second
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx,popcnt,sse4,abm")
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#define N 400005
int a[N], bit[N];
void add(int x, int val){
while(x < N)
bit[x] += val, x += x & -x;
}
int query(int l, int r){
int ret = 0;
l--;
while(l)
ret -= bit[l], l -= l & -l;
while(r)
ret += bit[r], r -= r & -r;
return ret;
}
void solve(){
int n;
cin >> n;
for (int i = 1; i <= n; i++)
cin >> a[i];
if(n == 1){
cout << "0\n";
return;
}
if(n == 2){
if(a[1] == 0)
cout << "0\n";
else
cout << "1\n";
return;
}
int x = 0;
int ans = 0;
for (int b = 0; b < 20; b++){
int cnt = 0;
for (int i = 0; i < n; i++){
if((i >> b) & 1)
continue;
cnt += (a[i + 1] >> b) & 1;
}
if(cnt > n / 4)
x |= (1 << b), ans++;
// cout << b << " " << cnt << "\n";
}
// cout << x << "\n";
for (int i = 1; i <= n; i++)
a[i] ^= x, a[i]++;
// cout << "\n";
for (int i = 1; i <= n; i++){
ans += query(a[i] + 1, N - 1);
add(a[i], 1);
}
cout << ans << "\n";
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
// int t;
// cin>>t;
// while(t--)
solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5728kb
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: 5736kb
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: 26ms
memory: 9560kb
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:
17145504953
result:
wrong answer 1st numbers differ - expected: '17137565829', found: '17145504953'