結果

問題 No.1167 Graduation Trip
ユーザー 沙耶花沙耶花
提出日時 2020-08-12 00:30:52
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 812 ms / 4,000 ms
コード長 2,007 bytes
コンパイル時間 2,768 ms
コンパイル使用メモリ 207,732 KB
実行使用メモリ 47,944 KB
最終ジャッジ日時 2024-04-17 17:59:31
合計ジャッジ時間 17,343 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 602 ms
47,632 KB
testcase_01 AC 425 ms
40,704 KB
testcase_02 AC 324 ms
34,688 KB
testcase_03 AC 610 ms
47,872 KB
testcase_04 AC 608 ms
47,944 KB
testcase_05 AC 449 ms
41,984 KB
testcase_06 AC 600 ms
47,872 KB
testcase_07 AC 418 ms
39,808 KB
testcase_08 AC 323 ms
35,788 KB
testcase_09 AC 529 ms
44,544 KB
testcase_10 AC 779 ms
47,744 KB
testcase_11 AC 812 ms
47,744 KB
testcase_12 AC 773 ms
47,928 KB
testcase_13 AC 795 ms
47,872 KB
testcase_14 AC 794 ms
47,744 KB
testcase_15 AC 569 ms
41,864 KB
testcase_16 AC 431 ms
35,744 KB
testcase_17 AC 801 ms
47,872 KB
testcase_18 AC 693 ms
45,696 KB
testcase_19 AC 789 ms
47,744 KB
testcase_20 AC 25 ms
5,376 KB
testcase_21 AC 28 ms
5,376 KB
testcase_22 AC 24 ms
5,376 KB
testcase_23 AC 27 ms
5,376 KB
testcase_24 AC 26 ms
5,376 KB
testcase_25 AC 23 ms
5,376 KB
testcase_26 AC 23 ms
5,376 KB
testcase_27 AC 27 ms
5,376 KB
testcase_28 AC 26 ms
5,376 KB
testcase_29 AC 24 ms
5,376 KB
testcase_30 AC 64 ms
7,796 KB
testcase_31 AC 98 ms
10,880 KB
testcase_32 AC 124 ms
12,672 KB
testcase_33 AC 235 ms
40,832 KB
testcase_34 AC 298 ms
45,796 KB
testcase_35 AC 1 ms
5,376 KB
testcase_36 AC 1 ms
5,376 KB
testcase_37 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 100000000000000000

void Func(vector<long long> &A){
	int last = 0;
	for(long long i=31;i>=0;i--){
		int ind = -1;
		for(int j=last;j<A.size();j++){
			if((A[j]>>i) & 1LL){
				ind = j;
				break;
				swap(A[j],A[last]);
				ind = last;
				last++;
				break;
			}
		}
		if(ind==-1)continue;
		for(int j=0;j<A.size();j++){
			if(j!=ind){
				if((A[j]>>i)&1LL){
					A[j] ^= A[ind];
				}
			}
		}
		swap(A[last],A[ind]);
		last++;
	}
	while(A.size()!=0&&A.back()==0)A.pop_back();
	return;
}

template <typename T>
struct sparse_table{
	const T init_value = vector<long long>();
	
	vector<T> v;
	int n;
	int sz;
	sparse_table(vector<T> &x){
		sz = x.size();
		for(int i=0;true;i++){
			if((1<<i)>sz){
				n = i;
				break;
			}
		}
		v.resize(sz*n,init_value);
		
		for(int i=0;i<sz;i++){
			v[i] = x[i];
		}
		
		for(int i=1;i<n;i++){
			for(int j=0;j<sz+1-(1<<i);j++){
				int temp = j+(1<<(i-1));
				v[i*sz+j] = func(v[(i-1)*sz+j],v[(i-1)*sz+temp]);
			}
		}
	}
	
	T query(int l,int r){
		int x = 31-__builtin_clz(r-l);
		return func(v[sz*x+l],v[sz*x+r-(1<<x)]);
	}
	
	T func(T a,T b){
		while(b.size()!=0){
			a.push_back(b.back());
			b.pop_back();
		}
		Func(a);
		return a;
	}
};

int beki(long long a,long long b,int M = modulo){
	int x = 1;
	while(b!=0){
		if(b&1){
			x=((long long)x*a)%M;
		}
		a=((long long)a*a)%M;
		b>>=1;
	}
	return x;
}

int main(){
	
	int N,Q;
	cin>>N>>Q;
	
	vector<vector<long long>> A(N);
	for(int i=0;i<N;i++){
		long long t;
		cin>>t;
		A[i] = {t};
	}
	
	sparse_table<vector<long long>> S(A);
	
	for(int i=0;i<Q;i++){
		int M;
		cin>>M;
		
		vector<int> B(M);
		for(int j=0;j<M;j++)cin>>B[j];
		int ans = 1;
		for(int j=0;j<=M;j++){
			int l,r;
			if(j!=0)l = B[j-1];
			else l=0;
			if(j!=M)r = B[j];
			else r=N;
			
			int t = S.query(l,r).size();
			ans = mod(ans * beki(2,r-l-t));
		}
		cout<<ans<<endl;
	}
	
	
	return 0;
}
0