QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#154999 | #6521. Swapping Operation | Insert_Username_Here | WA | 118ms | 11716kb | C++20 | 2.2kb | 2023-09-01 05:33:15 | 2023-09-01 05:33:15 |
Judging History
answer
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
// Cope Counter = at least 125
ll n;
ll arr[100001], kms[18][100001];
map<ll, vector<ll>> bk;
ll wxzs(ll l, ll r) {
for(ll i = 17; i >= 0; i--) {
if(r - l + 1 >= (1 << i)) return kms[i][l] & kms[i][r - (1 << i) + 1];
}
return (1 << 30) - 1;
}
ll qry(ll type, ll val, ll i) {
if(bk[val].empty()) {
vector<ll> cancer(n);
if(!type) {
cancer[0] = arr[0] & val;
for(ll j = 1; j < n; j++) cancer[j] = max(cancer[j - 1], arr[j] & val);
} else {
cancer[n - 1] = arr[n - 1] & val;
for(ll j = n - 2; j >= 0; j--) cancer[j] = max(cancer[j + 1], arr[j] & val);
}
bk[val] = cancer;
}
return bk[val][i];
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
ll t;
cin >> t;
while(t--) {
cin >> n;
for(ll i = 0; i < n; i++) {
cin >> arr[i];
kms[0][i] = arr[i];
}
for(ll i = 0; i < 17; i++) {
for(ll j = 0; j + (1 << i) < n; j++) {
kms[i + 1][j] = kms[i][j] & kms[i][j + (1 << i)];
}
}
vector<ll> sped[2];
sped[0].push_back(0), sped[1].push_back(n - 1);
ll pre = arr[0], suf = arr[n - 1], ans = 0;
for(ll i = 1; i < n; i++) {
ans = max(ans, wxzs(0, i - 1) + wxzs(i, n - 1));
if((pre & arr[i]) != pre) {
pre &= arr[i];
sped[0].push_back(i);
}
if((suf & arr[n - i - 1]) != suf) {
suf &= arr[n - i - 1];
sped[1].push_back(n - i - 1);
}
}
for(ll k = 1; k < n; k++) {
for(ll i : sped[0]) {
if(i >= k) break;
for(ll j : sped[1]) {
if(j < k) break;
ans = max(ans, (wxzs(0, i - 1) & arr[j] & wxzs(i + 1, k - 1)) + (wxzs(k, j - 1) & arr[i] & wxzs(j + 1, n - 1)));
}
}
}
for(ll thing = 0; thing < 2; thing++) {
bk.clear();
for(ll k = 1; k < n; k++) {
for(ll i : sped[thing]) {
if((!thing && i >= k) || (thing && i < k)) break;
ans = max(ans, qry(thing, wxzs(0, i - 1) & wxzs(i + 1, k - 1), k) + wxzs(k, n - 1) & arr[i]);
}
}
}
cout << ans << "\n";
}
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 7548kb
input:
3 6 6 5 4 3 5 6 6 1 2 1 1 2 2 5 1 1 2 2 2
output:
7 3 3
result:
ok 3 number(s): "7 3 3"
Test #2:
score: -100
Wrong Answer
time: 118ms
memory: 11716kb
input:
1000 100 803046221 177233942 164782937 53823867 383853667 250036100 888743479 576687945 737272231 801579441 647643785 393059353 401516062 663466861 308544510 825328494 162739603 501761995 570908380 655227403 444493122 844535039 208303132 493226172 421479971 634680694 396627047 787471115 335787136 16...
output:
890299519 923642535 960163633 963497255 906186590 923065154 979836345 771417883 973791353 897446548 920223968 969979000 494498965 917264022 981686922 827513928 988685740 989181315 729655322 863912714 968789214 934333526 924124296 964130484 971937793 918136308 977368039 980800625 551789116 973760189 ...
result:
wrong answer 1st numbers differ - expected: '999397418', found: '890299519'