QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#376492#6631. Maximum Bitwise ORFido_PuppyWA 37ms70060kbC++233.0kb2024-04-04 10:45:582024-04-04 10:45:59

Judging History

你现在查看的是最新测评结果

  • [2024-04-04 10:45:59]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:70060kb
  • [2024-04-04 10:45:58]
  • 提交

answer

#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define MT make_tuple
#define IT iterator
#define fi first
#define se second
#define For(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define Rep(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define CLR(a, v) memset(a, v, sizeof(a))
#define CPY(a, b) memcpy(a, b, sizeof(a))
#define debug cerr << "ztxakking\n"
#define y0 ztxaknoi
#define y1 ztxakioi
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using vi = vector<int>;
template<typename T>
using V = vector<T>;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
bool mem1;
const int N = 1e5 + 7;
int n, q, a[N];
struct info {
  int w[30], OR;
  V<pii> ban;
};
info mrg(info a, info b) {
  info c;
  c.OR = a.OR | b.OR;
  For(i, 0, 29) c.w[i] = max(a.w[i], b.w[i]);
  for (auto [x, y] : a.ban) {
    if ((y | b.OR) != c.OR) c.ban.eb(x, y | b.OR);
    else {
      For(i, 0, __lg(x)) c.w[i] = max(c.w[i], x ^ (x - (1 << i)));
    }
  }
  for (auto [x, y] : b.ban) {
    if ((y | a.OR) != c.OR) c.ban.eb(x, y | a.OR);
    else {
      For(i, 0, __lg(x)) c.w[i] = max(c.w[i], x ^ (x - (1 << i)));
    }
  }
  assert(c.ban.size() <= 30);
  return c;
}
struct node {
  int l, r, mx;
  info f;
} tr[N * 4];
#define ls (p * 2)
#define rs (p * 2 + 1)
void pushup(int p) {
  tr[p].mx = max(tr[ls].mx, tr[rs].mx);
  tr[p].f = mrg(tr[ls].f, tr[rs].f);
}
void build(int p, int l, int r) {
  tr[p].l = l, tr[p].r = r;
  if (l == r) {
    tr[p].mx = a[l];
    tr[p].f.OR = a[l];
    tr[p].f.ban.clear();
    if (a[l]) {
      tr[p].f.ban.eb(a[l], 0);
    }
    return ;
  }
  int mid = (l + r) / 2;
  build(ls, l, mid), build(rs, mid + 1, r);
  pushup(p);
}
int qrymx(int p, int x, int y) {
  if (tr[p].l >= x && tr[p].r <= y) return tr[p].mx;
  int mid = (tr[p].l + tr[p].r) / 2, ans = 0;
  if (x <= mid) ans = max(ans, qrymx(ls, x, y));
  if (mid < y) ans = max(ans, qrymx(rs, x, y));
  return ans;
}
info qry(int p, int x, int y) {
  if (tr[p].l >= x && tr[p].r <= y) return tr[p].f;
  int mid = (tr[p].l + tr[p].r) / 2;
  if (y <= mid) return qry(ls, x, y);
  if (mid < x) return qry(rs, x, y);
  return mrg(qry(ls, x, y), qry(rs, x, y));
}
void sol() {
  cin >> n >> q;
  For(i, 1, n) cin >> a[i];
  build(1, 1, n);
  while (q--) {
    int l, r; cin >> l >> r;
    int ans = (1 << __lg(qrymx(1, l, r)) + 1) - 1;
    cout << ans << ' ';
    info t = qry(1, l, r);
    if (t.OR == ans) cout << "0\n";
    else {
      bool ok = 0;
      For(i, 0, 29) if ((t.w[i] | t.OR) == ans) { ok = 1; break; }
      cout << (ok? 1 : 2) << '\n';
    }
  }
}
bool mem2;
int main() {
  cerr << abs(&mem1 - &mem2) / 1048576. << '\n';
  ios::sync_with_stdio(0), cin.tie(0);
  int t; cin >> t;
  while (t--) sol();
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 70060kb

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: 0
Accepted
time: 37ms
memory: 69560kb

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:

1073741823 2
268435455 2
536870911 2
1073741823 2
536870911 2
1073741823 2
536870911 2
1073741823 2
268435455 2
268435455 2
536870911 2
67108863 2
134217727 2
1073741823 2
536870911 2
536870911 2
268435455 2
536870911 2
536870911 2
536870911 2
268435455 2
268435455 2
1073741823 2
16777215 2
10737418...

result:

ok 200000 numbers

Test #3:

score: 0
Accepted
time: 36ms
memory: 69428kb

input:

50000
2 2
924896435 917026400
1 2
1 2
2 2
322948517 499114106
1 2
2 2
2 2
152908571 242548777
1 1
1 2
2 2
636974385 763173214
1 2
1 1
2 2
164965132 862298613
1 1
1 2
2 2
315078033 401694789
1 2
1 2
2 2
961358343 969300127
2 2
1 2
2 2
500628228 28065329
1 2
1 2
2 2
862229381 863649944
1 2
2 2
2 2
541...

output:

1073741823 2
1073741823 2
536870911 2
536870911 2
268435455 2
268435455 2
1073741823 2
1073741823 2
268435455 2
1073741823 2
536870911 2
536870911 2
1073741823 2
1073741823 2
536870911 2
536870911 2
1073741823 2
1073741823 2
1073741823 2
268435455 2
536870911 2
536870911 2
1073741823 2
1073741823 2
...

result:

ok 200000 numbers

Test #4:

score: -100
Wrong Answer
time: 35ms
memory: 69820kb

input:

33333
3 3
925088809 339284112 289540728
3 3
1 3
1 1
3 3
422399522 892365243 216341776
3 3
3 3
1 2
3 3
668932010 837523227 840095874
1 3
1 3
3 3
3 3
731584574 357877180 359063739
1 1
1 1
3 3
3 3
463358343 833924976 847087403
2 3
3 3
1 2
3 3
377154649 772000701 656357011
2 3
1 2
2 3
3 3
977492169 5540...

output:

536870911 2
1073741823 2
1073741823 2
268435455 2
268435455 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
536870911 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
1073741823 2
67108863 2
1073741823 2
1073741...

result:

wrong answer 9322nd numbers differ - expected: '1', found: '2'