QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#113484 | #6631. Maximum Bitwise OR | dnialh | WA | 308ms | 3508kb | C++14 | 3.0kb | 2023-06-18 07:13:46 | 2023-06-18 07:13:47 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<int, int> pii;
#define F0R(i,a) for(int i=0; i<a; i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define pb push_back
#define f first
#define s second
signed main(){
int t;
cin >> t;
vi offset(30);
int c = 0;
F0R(k, 30){
offset[k] = c;
c += k + 1;
}
while(t --){
int n, q;
cin >> n >> q;
vvi seen;
vi curr(500);
seen.pb(curr);
F0R(i, n){
int a;
cin >> a;
int last = -1;
F0R(k, 30){
if (a & (1 << k)){
curr[offset[k] + last + 1] ++;
last = k;
}
}
seen.pb(curr);
}
while(q --){
int l, r;
cin >> l >> r;
vi qc(500);
F0R(i, 500){
qc[i] = seen[r][i] - seen[l-1][i];
}
int out = 0;
int mv = 0;
int right = 31;
int nr = 31;
vi cost(31, 100);
for(int k = 29; k >= 0; k--){
int p1 = k + 1;
int p2 = k + 1;
for(int j = k; j >= 0; j--){
if (qc[offset[k] + j] >= 2){
//cout << k << " " << j << endl;
p1 = j;
p2 = j;
} else if (qc[offset[k] + j]){
//cout << k << " " << j << endl;
p2 = p1;
p1 = j;
}
}
if (cost[k + 1] == 100){
if (p2 > k){
if (p1 <= k){
out |= (1 << k);
}
} else {
out |= (1 << k);
cost[k] = 0;
FOR(u, p1, k){
cost[u] = min(cost[u], 1);
}
}
} else {
//cout << k << " " << cost[k + 1] << " " << p1 << " " << p2 << endl;
if (p2 <= k){
out |= (1 << k);
FOR(u, p1, k - 1){
cost[u] = min(cost[u], 1 + cost[k + 1]);
}
cost[k] = min(cost[k], cost[k + 1]);
} else if (p1 <= k){
out |= (1 << k);
FOR(u, p1, k - 1){
cost[u] = min(cost[u], 1 + cost[k]);
}
cost[k] = min(cost[k], cost[k + 1]);
} else {
out |= (1 << k);
}
}
/*
if ((p2 <= k) || (right <= k)){
nr = min(nr, p1);
} else if (p1 > k){
if (nr <= k){
out |= (1 << k);
mv ++;
right = nr;
}
} else {
}*/
/**
if (p2 <= k || (right <= k)){
nr = min(nr, p1);
out |= (1 << k);
} else if ((p1 <= k) && (right <= k)){
} else if ((p1 <= k) && (nr <= k)){
} else if ((p1 <= k) || (right <= k)){
out |= (1 << k);
}*/
}
if (cost[0] == 100) cost[0] = 0;
cout << out << " " << cost[0] << '\n';
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3452kb
input:
1 3 2 10 10 5 1 2 1 3
output:
15 2 15 0
result:
ok 4 number(s): "15 2 15 0"
Test #2:
score: -100
Wrong Answer
time: 308ms
memory: 3508kb
input:
100000 1 1 924704060 1 1 1 1 149840457 1 1 1 1 515267304 1 1 1 1 635378394 1 1 1 1 416239424 1 1 1 1 960156404 1 1 1 1 431278082 1 1 1 1 629009153 1 1 1 1 140374311 1 1 1 1 245014761 1 1 1 1 445512399 1 1 1 1 43894730 1 1 1 1 129731646 1 1 1 1 711065534 1 1 1 1 322643984 1 1 1 1 482420443 1 1 1 1 20...
output:
924704060 0 149840457 0 515267304 0 635378394 0 416239424 0 960156404 0 431278082 0 629009153 0 140374311 0 245014761 0 445512399 0 43894730 0 129731646 0 711065534 0 322643984 0 482420443 0 202661591 0 529979773 0 520572847 0 500838890 0 224446016 0 228171383 0 973333717 0 8493236 0 622547486 0 677...
result:
wrong answer 1st numbers differ - expected: '1073741823', found: '924704060'