QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#284686#6631. Maximum Bitwise ORMisukiWA 53ms3820kbC++203.9kb2023-12-16 14:28:142023-12-16 14:28:15

Judging History

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

  • [2023-12-16 14:28:15]
  • 评测
  • 测评结果:WA
  • 用时:53ms
  • 内存:3820kb
  • [2023-12-16 14:28:14]
  • 提交

answer

#pragma GCC optimize("O2")
#include <algorithm>
#include <array>
#include <bit>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <compare>
#include <complex>
#include <concepts>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numbers>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <ranges>
#include <set>
#include <span>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <variant>

//#define int ll
#define INT128_MAX (__int128)(((unsigned __int128) 1 << ((sizeof(__int128) * __CHAR_BIT__) - 1)) - 1)
#define INT128_MIN (-INT128_MAX - 1)

namespace R = std::ranges;
namespace V = std::views;

using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
using tiii = tuple<int, int, int>;
using ldb = long double;
//#define double ldb

template<class T>
ostream& operator<<(ostream& os, const pair<T, T> pr) {
  return os << pr.first << ' ' << pr.second;
}
template<class T, size_t N>
ostream& operator<<(ostream& os, const array<T, N> &arr) {
  for(const T &X : arr)
    os << X << ' ';
  return os;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T> &vec) {
  for(const T &X : vec)
    os << X << ' ';
  return os;
}

/**
 * template name: segmentTree
 * author: Misuki
 * last update: 2023/11/30
 * verify: library checker - Point Add Range Sum, Static RMQ
 */

template<class T>
struct segmentTree {
  function<T(const T&, const T&)> combine;
  T UNIT;
  vector<T> arr;
  int sz;

  segmentTree(int _sz, T _UNIT, function<T(const T&, const T&)> _combine) {
    sz = _sz;
    UNIT = _UNIT;
    combine = _combine;
    arr.resize(2 * sz, UNIT);
  }

  void set(int idx, T val) {
    idx += sz;
    arr[idx] = val;
    idx >>= 1;
    while(idx) {
      arr[idx] = combine(arr[idx<<1], arr[idx<<1|1]); 
      idx >>= 1;
    }
  }

  T get(int idx) {
    return arr[idx + sz];
  }

  T query(int l, int r) {
    T L = UNIT, R = UNIT;
    for(l += sz, r += sz; l < r; l >>= 1, r >>= 1) {
      if (l & 1) L = combine(L, arr[l++]);
      if (r & 1) R = combine(arr[--r], R);
    }
    return combine(L, R);
  }
};

using state = array<int, 32>;

signed main() {
  ios::sync_with_stdio(false), cin.tie(NULL);

  int t; cin >> t;
  while(t--) {
    int n, q; cin >> n >> q;
    vector<int> a(n);
    for(int &x : a)
      cin >> x;

    segmentTree<state> seg(n, state{}, [](const state &l, const state &r) {
      state res;
      for(int i = 0; i < 32; i++)
        res[i] = l[i] | r[i];
      return res;
    });

    for(int i = 0; i < n; i++) {
      state tmp = {};
      tmp[31] = a[i];
      for(int bit = 0, p = 0; bit < 30; bit++) {
        if (a[i] >> bit & 1) {
          for(int j = p; j <= bit; j++)
            tmp[j] = (1 << (bit + 1)) - (1 << p);
          p = bit + 1;
        }
      }
      seg.set(i, tmp);
    }

    while(q--) {
      int l, r; cin >> l >> r;
      state res = seg.query(l - 1, r);
      int ans = (1 << bit_width((unsigned)res[31])) - 1, ope;
      if (res[31] == ans)
        ope = 0;
      else if (*max_element(res.begin(), res.begin() + 30) == ans)
        ope = 1;
      else
        ope = 2;
      cout << ans << ' ' << ope << '\n';
    }
  }

  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3812kb

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: 53ms
memory: 3820kb

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: 50ms
memory: 3584kb

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: 49ms
memory: 3616kb

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 5770th numbers differ - expected: '1', found: '2'