QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#708119 | #7937. Fast XORting | bilbo_b# | TL | 0ms | 3608kb | C++17 | 1.3kb | 2024-11-03 19:38:47 | 2024-11-03 19:38:49 |
Judging History
answer
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define x first
#define y second
using namespace std;
using namespace __gnu_cxx;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> set_t;
int f(vector<int>& a) {
int res = 0, n = a.size();
set_t s;
for (int i = 0; i < n; ++i) {
res += s.size() - s.order_of_key(a[i]);
s.insert(a[i]);
}
return res;
}
signed main() {
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
int n;
cin >> n;
vector<int> a(n);
for (auto &i : a) {
cin >> i;
}
int curr_res = f(a), was = 0;
for (int q = 1; q < n; q += q) {
vector<int> b = a;
vector<int> pos(n);
for (int i = 0; i < n; ++i) {
pos[a[i]] = i;
}
for (int i = 0; i < n; ++i) {
if (i < (i ^ q)) {
swap(b[pos[i]], b[pos[i ^ q]]);
}
}
int res = f(b);
if (res < curr_res) {
curr_res = res;
a = b;
was = 1;
}
}
cout << curr_res + was;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3544kb
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: 3608kb
input:
8 2 0 1 3 4 5 6 7
output:
2
result:
ok 1 number(s): "2"
Test #3:
score: -100
Time Limit Exceeded
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...