結果

問題 No.1167 Graduation Trip
ユーザー 蜜蜂蜜蜂
提出日時 2020-08-11 22:09:26
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 776 ms / 4,000 ms
コード長 2,152 bytes
コンパイル時間 2,348 ms
コンパイル使用メモリ 180,232 KB
実行使用メモリ 29,924 KB
最終ジャッジ日時 2024-04-17 17:40:43
合計ジャッジ時間 17,436 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 546 ms
29,796 KB
testcase_01 AC 454 ms
26,292 KB
testcase_02 AC 350 ms
23,044 KB
testcase_03 AC 549 ms
29,800 KB
testcase_04 AC 546 ms
29,644 KB
testcase_05 AC 467 ms
26,436 KB
testcase_06 AC 564 ms
29,652 KB
testcase_07 AC 444 ms
25,260 KB
testcase_08 AC 382 ms
23,056 KB
testcase_09 AC 502 ms
27,468 KB
testcase_10 AC 714 ms
29,924 KB
testcase_11 AC 712 ms
29,640 KB
testcase_12 AC 712 ms
29,656 KB
testcase_13 AC 711 ms
29,772 KB
testcase_14 AC 776 ms
29,808 KB
testcase_15 AC 606 ms
26,316 KB
testcase_16 AC 492 ms
22,940 KB
testcase_17 AC 715 ms
29,784 KB
testcase_18 AC 671 ms
28,692 KB
testcase_19 AC 716 ms
29,776 KB
testcase_20 AC 27 ms
5,376 KB
testcase_21 AC 30 ms
5,376 KB
testcase_22 AC 25 ms
5,376 KB
testcase_23 AC 29 ms
5,376 KB
testcase_24 AC 29 ms
5,376 KB
testcase_25 AC 26 ms
5,376 KB
testcase_26 AC 26 ms
5,376 KB
testcase_27 AC 32 ms
5,376 KB
testcase_28 AC 31 ms
5,376 KB
testcase_29 AC 26 ms
5,376 KB
testcase_30 AC 78 ms
8,448 KB
testcase_31 AC 128 ms
11,156 KB
testcase_32 AC 157 ms
11,288 KB
testcase_33 AC 240 ms
26,544 KB
testcase_34 AC 276 ms
28,672 KB
testcase_35 AC 2 ms
5,376 KB
testcase_36 AC 2 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0;i<(n);++i)
#define int long long

const long long MOD = 1e9+7;
typedef vector<int> INTV;
using BitMatrix = vector<int>;

BitMatrix merge(BitMatrix a, BitMatrix b){
  BitMatrix c(a.size() + b.size());
  REP(i, a.size()) c[i] = a[i];
  REP(i, b.size()) c[a.size()+i] = b[i];

  int rank = 0;
  for(int col = 31; col >= 0; col--){
    int pivot = -1;
    for(int row = rank; row < c.size(); row++){
      if((c[row] >> col) & 1){
        pivot = row; break;
      }
    }
    if(pivot == -1) continue;
    swap(c[pivot], c[rank]);
    REP(row, c.size()){
      if(row != rank and ((c[row] >> col) & 1)) c[row] ^= c[rank];
    }
    rank++;
  }

  BitMatrix res(rank);
  REP(i, rank) res[i] = c[i];
  return res;
}

int siz;
vector<vector<BitMatrix>> table;
vector<int> logtable;

void SparseTable_init(vector<BitMatrix> vec){
  siz = vec.size();
  logtable.resize(siz+1, 0);
  for(int i = 2; i <= siz; i++){
    logtable[i] = logtable[i >> 1] + 1;
  }
  table.resize(siz, vector<BitMatrix>(14));
  REP(i, siz){
    table[i][0] = vec[i];
  }
}

void build(void){
  for(int k = 1; (1<<k) <= siz; k++){
    for(int i = 0; i + (1<<k) <= siz; i++){
      BitMatrix first = table[i][k-1];
      BitMatrix second = table[i+(1<<(k-1))][k-1];
      table[i][k] = merge(first, second);
    }
  }
}

BitMatrix query(int l, int r){ // [l, r)
  assert(l < r);
  int length = r-l;
  int k = logtable[length];
  return merge(table[l][k], table[r-(1<<k)][k]);
}

int powmod(int a, int p, int m){
  int res = 1, tmp = a;
  while(p != 0){
    if(p % 2)
      res = (res*tmp) % m;
    tmp = (tmp*tmp) % m;
    p /= 2;
  }
  return res;
}

signed main(){  
  int N, Q;
  cin >> N >> Q;
  vector<BitMatrix> vec(N, BitMatrix(1));
  REP(i, N) {
    int a; cin >> a;
    vec[i][0] = a;
  }

  SparseTable_init(vec);
  vector<BitMatrix>().swap(vec);
  build();

  int M;
  REP(_, Q){
    cin >> M;
    INTV B(M+2); B[0] = 0; B[M+1] = N;
    int pw = N;
    REP(i, M){
      cin >> B[i+1];
    }
    REP(i, M+1){
      pw -= query(B[i], B[i+1]).size();
    }
    cout << powmod(2ll, pw, MOD) << endl;
  }
}
0