QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#113569#6631. Maximum Bitwise ORchineristCompile Error//C++175.1kb2023-06-18 16:47:562023-06-18 16:47:59

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-18 16:47:59]
  • 评测
  • [2023-06-18 16:47:56]
  • 提交

answer

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <random>
#include <stdio.h>
#include <fstream>
#include <functional>
#include <cassert>
#include <atcoder/all>



using namespace std;
using namespace atcoder;



#define rep(i,n) for (int i=0;i<n;i+=1)
#define append push_back
#define all(x) (x).begin(), (x).end()

template<class T>
using vec = vector<T>;
template<class T>
using vvec = vec<vec<T>>;
template<class T>
using vvvec = vec<vvec<T>>;
using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

using ld = long double;


template<class T>
bool chmin(T &a, T b){
  if (a>b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
bool chmax(T &a, T b){
  if (a<b){
    a = b;
    return true;
  }
  return false;
}

template<class T>
T sum(vec<T> x){
  T res=0;
  for (auto e:x){
    res += e;
  }
  return res;
}

template<class T>
void printv(vec<T> x){
  for (auto e:x){
    cout<<e<<" ";
  }
  cout<<"\n";
}

template<class T>
ostream& operator<<(ostream& os, const vec<T>& A){
  os << "[";
  rep(i,A.size()){
    os << A[i];
    if (i!=A.size()-1){
      os << ", ";
    }
  }
  os << "]" ;
  return os;
}

template<class T>
ostream& operator<<(ostream& os, const deque<T>& A){
  os << "deque{[";
  rep(i,A.size()){
    os << A[i];
    if (i!=A.size()-1){
      os << ", ";
    }
  }
  os << "]}" ;
  return os;
}

template<class T,class U>
ostream& operator<<(ostream& os, const pair<U,T>& A){
  os << "(";
  os << A.first ;
  os << ", ";
  os << A.second;
  os << ")";
  return os;
}

using mint = modint1000000007;



const int M = 30;


using S = array<int,M>;


S op(S x,S y){
  
  array<int,M> bit_cnt;

  rep(i,M){
    if (x[i]==-2) bit_cnt[i] = -2;
    if (x[i]==-1) bit_cnt[i] = y[i];
    if (y[i]==-2) bit_cnt[i] = -2;
    if (y[i]==-1) bit_cnt[i] = x[i];
    if (0 <= x[i] && 0 <= y[i]) bit_cnt[i] = -2;
  }
  return bit_cnt;
}


S e(){
  array<int,M> bit_cnt;
  rep(i,M){
    bit_cnt[i] = -1;
  }
  return bit_cnt;
}

int int_min(int x,int y){
  return min(x,y);
}

int int_e(){
  return 3e6;
}

void solve(){

  int N,Q;
  cin>>N>>Q;
  vec<int> A(N);
  vec<S> AS(N);
  vec<vec<int>> r_to_l(M,vec<int>(N,M));
  rep(i,N){
    cin>>A[i];
    array<int,M> bit_cnt;
    rep(j,M){
      bit_cnt[j] = -1;
      if ((A[i]>>j) & 1) {
        bit_cnt[j] = i;
        int L = j;
        while (0<=L-1 && ((A[i]>>(L-1)) & 1) == 0){
          L--;
        }
        for (int k=L;k<=j;k++){
          r_to_l[k][i] = L;
        }
      }
    }
    AS[i] = bit_cnt;
  }

  segtree<S,op,e> seg(AS);

  vec<int> ans_val(Q);
  vec<int> ans_t(Q,2);
  vec<pii> query_lr(Q);
  vec<S> query_bit_cnt(Q);
  vec<vec<int>> query_only_one(Q);

  vec<vec<pii>> r_to_query(M);

  rep(i,Q){
    int l,r;
    cin>>l>>r;
    l--;
    query_lr[i] = {l,r};
    auto bit_cnt = seg.prod(l,r);
    query_bit_cnt[i] = bit_cnt;

    int k = -1;
    int p = 0;
    int zL = M,zR = -1;
    rep(j,M){
      //cout << bit_cnt[j] << " ";
      if (bit_cnt[j]!=-1){
        k = j;
        p++;
      }
      if (0 <= bit_cnt[j]){
        query_only_one[i].push_back(bit_cnt[j]);
      }
    }
    rep(j,k){
      if (bit_cnt[j]==-1){
        chmin(zL,j);
        chmax(zR,j);
      }
    }
    //cout << endl;
    //cout << zL << " " << zR << endl;
    if (k==-1){
      ans_val[i] = 0;
      ans_t[i] = 0;
      continue;
    }
    ans_val[i] = (1<<(k+1)) - 1;
    if (p==k+1){
      ans_t[i] = 0;
      continue;
    }

    r_to_query[zR].push_back({i,zL});
  } 

  vec<int> tmp_onlyone_cnt(N,0);

  

  rep(r,M){
    segtree<int,int_min,int_e> seg_b(r_to_l[r]);
    for (auto [i,l]:r_to_query[r]){
      //cout << i << " " << l << " " << r << endl;
      int L = M;
      for (auto a:query_only_one[i]){
        tmp_onlyone_cnt[a]++;
      }
      for (int k=r;k<M;k++){
        int a = query_bit_cnt[i][k];
        if (a < 0 || 2 <= tmp_onlyone_cnt[a]) continue;
        chmin(L,r_to_l[k][a]);
      }

      query_only_one[i].push_back(query_lr[i].first-1);
      query_only_one[i].push_back(query_lr[i].second);
      sort(all(query_only_one[i]));

      auto &tmp = query_only_one[i];
      for (int j=0;j<int(tmp.size())-1;j++){
        int a = tmp[j],b = tmp[j+1];
        if (a+1 <= b-1){
          chmin(L,seg_b.prod(a+1,b));
        }
      }

      if (L <= l){
        ans_t[i] = 1;
      }

      for (auto a:query_only_one[i]){
        if (a==query_lr[i].first-1 || a==query_lr[i].second) continue;
        tmp_onlyone_cnt[a]--;
      }

    }
  }

  rep(i,Q){
    cout << ans_val[i] << " " << ans_t[i] << endl;
  }
}


int main() {

  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  

  int T;
  cin>>T;
  while (T--){
    solve();
  }

  



  
}

詳細信息

answer.code:19:10: fatal error: atcoder/all: No such file or directory
   19 | #include <atcoder/all>
      |          ^~~~~~~~~~~~~
compilation terminated.