답안 #227533

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
227533 2020-04-27T17:20:00 Z srvlt Intergalactic ship (IZhO19_xorsum) C++14
100 / 100
1473 ms 49016 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ull unsigned long long
#define db long double
#define pb push_back
#define ppb pop_back
#define F first
#define S second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
const int N = 1003, M = 100003, K = 128, MOD = 1e9 + 7;
int n, q, a[N], pw[M];
vector <pii> L[N], R[N];

int bit[K], mask[K];
 
struct basis {
	short int b[7];
	int sz = 0, bsz = 0;
	bitset <K> can;
	basis() {
		memset(& b, 0, sizeof(b));
		can[0] = 1;
	}
	void clear() {
		memset(& b, 0, sizeof(b));
		sz = 0;
		bsz = 0;
		can.reset();
		can[0] = 1;
	};
	void upd() {
		can.reset();
		for (int i = 0; i < (1 << bsz); i++) {
			if (i > 0) {
				mask[i] = mask[i ^ (1 << bit[i])] ^ b[bit[i]];
			}
			can[mask[i]] = 1;
		}
	};
	bool add(int x) {
		sz++;
		if (can[x]) {
			return false;
		}
		for (int i = 0; i < bsz; i++) {
			x = min(x, x ^ b[i]);
		}
		b[bsz++] = x;
		upd();
		return true;
	}
	int ways() {
		return pw[sz - bsz];
	}
};
 
basis cur, C[N][N], A[8][N];
short int f[8][K][N], g[K];
int last[N][N];
 
int main() {
	ios_base::sync_with_stdio(false), cin.tie(NULL);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	
	pw[0] = 1;
	for (int i = 1; i < M; i++) {
		pw[i] = pw[i - 1] * 2 % MOD;
	}
	
	for (int i = 1; i < K; i++) {
		for (int j = 6; j >= 0; j--) {
			if (i >> j & 1) {
				bit[i] = j;
				break;
			}
		}
	}
	
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	cin >> q;
	for (int i = 1; i <= q; i++) {
		int l, r, x;
		cin >> l >> r >> x;
		R[r].pb({l, x});
		L[l].pb({r, x});
	}
	for (int l = 1; l <= n; l++) {
		cur.clear();
		for (int r = n; r >= l; r--) {
			for (auto i : R[r]) {
				if (i.F <= l) {
					cur.add(i.S);
				}
			}
			C[l][r] = cur;
		}
	}
	memset(& last, -1, sizeof(last));
	for (int l = 1; l <= n; l++) {
		cur.clear();
		int cnt = 0;
		last[l][l] = cnt;
		for (int r = l; r <= n; r++) {
			int pos = last[l][r];
			if (pos == cnt) {
				A[pos][l] = cur;
				for (int i = 0; i < K; i++) {
					for (int j = 0; j < K; j++) {
						f[pos][i][l] += j * cur.can[j ^ i];
					}
				}
				cnt++;
			}	else {
				last[l][r] = last[l][r - 1];
			}
			for (auto i : R[r]) {
				if (i.F <= l && cur.add(i.S)) {
					last[l][r + 1] = cnt;
				}
			}
		}
	}
	int ans = 0;
	for (int r = n; r >= 1; r--) {
		cur.clear();
		for (int i = 0; i < K; i++) {
			g[i] = 0;
			for (int j = 0; j < K; j++) {
				g[i] += j * cur.can[j ^ i];
			}
		}
		for (int l = r; l >= 1; l--) {
			int res = 0, pos = last[l][r];
			for (int i = 0; i < K; i++) {
				res += (int)C[l][r].can[i] * f[pos][i ^ a[l]][l] * g[i ^ a[r]];
				if (res >= MOD) {
					res -= MOD;
				}
			}
			res = (ll)res * C[l][r].ways() % MOD;
			res = (ll)res * A[pos][l].ways() % MOD;
			res = (ll)res * cur.ways() % MOD;
			res = (ll)res * pw[q - C[l][r].sz - A[pos][l].sz - cur.sz] % MOD;
			if (l == r) {
				res = (ll)res * ((MOD + 1) / 2) % MOD;
			}
			int occ = l * (n - r + 1);
			ans += (ll)res * occ % MOD;
			if (ans >= MOD) {
				ans -= MOD;
			}
    		for (auto i : L[l]) {
    			if (i.F >= r && cur.add(i.S)) {
    				for (int k = 0; k < K; k++) {
    					g[k] = 0;
    					for (int j = 0; j < K; j++) {
    						g[k] += j * cur.can[j ^ k];
    					}
    				}
    			}
    		}
    	}
    }
    cout << 2 * ans % MOD;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 44672 KB Output is correct
2 Correct 29 ms 44664 KB Output is correct
3 Correct 30 ms 46208 KB Output is correct
4 Correct 31 ms 45696 KB Output is correct
5 Correct 28 ms 44920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 44672 KB Output is correct
2 Correct 29 ms 44664 KB Output is correct
3 Correct 30 ms 46208 KB Output is correct
4 Correct 31 ms 45696 KB Output is correct
5 Correct 28 ms 44920 KB Output is correct
6 Correct 51 ms 45944 KB Output is correct
7 Correct 36 ms 45184 KB Output is correct
8 Correct 40 ms 44928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 47096 KB Output is correct
2 Correct 56 ms 45184 KB Output is correct
3 Correct 48 ms 44988 KB Output is correct
4 Correct 39 ms 44968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 396 ms 44920 KB Output is correct
2 Correct 410 ms 44928 KB Output is correct
3 Correct 387 ms 44928 KB Output is correct
4 Correct 393 ms 44924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 45944 KB Output is correct
2 Correct 37 ms 45696 KB Output is correct
3 Correct 35 ms 45952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 45944 KB Output is correct
2 Correct 37 ms 45696 KB Output is correct
3 Correct 35 ms 45952 KB Output is correct
4 Correct 36 ms 45284 KB Output is correct
5 Correct 37 ms 45304 KB Output is correct
6 Correct 38 ms 45056 KB Output is correct
7 Correct 37 ms 45048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 44672 KB Output is correct
2 Correct 29 ms 44664 KB Output is correct
3 Correct 30 ms 46208 KB Output is correct
4 Correct 31 ms 45696 KB Output is correct
5 Correct 28 ms 44920 KB Output is correct
6 Correct 51 ms 45944 KB Output is correct
7 Correct 36 ms 45184 KB Output is correct
8 Correct 40 ms 44928 KB Output is correct
9 Correct 37 ms 45944 KB Output is correct
10 Correct 37 ms 45696 KB Output is correct
11 Correct 35 ms 45952 KB Output is correct
12 Correct 65 ms 46464 KB Output is correct
13 Correct 67 ms 46464 KB Output is correct
14 Correct 63 ms 46208 KB Output is correct
15 Correct 69 ms 46200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 44672 KB Output is correct
2 Correct 29 ms 44664 KB Output is correct
3 Correct 30 ms 46208 KB Output is correct
4 Correct 31 ms 45696 KB Output is correct
5 Correct 28 ms 44920 KB Output is correct
6 Correct 51 ms 45944 KB Output is correct
7 Correct 36 ms 45184 KB Output is correct
8 Correct 40 ms 44928 KB Output is correct
9 Correct 37 ms 45944 KB Output is correct
10 Correct 37 ms 45696 KB Output is correct
11 Correct 35 ms 45952 KB Output is correct
12 Correct 36 ms 45284 KB Output is correct
13 Correct 37 ms 45304 KB Output is correct
14 Correct 38 ms 45056 KB Output is correct
15 Correct 37 ms 45048 KB Output is correct
16 Correct 65 ms 46464 KB Output is correct
17 Correct 67 ms 46464 KB Output is correct
18 Correct 63 ms 46208 KB Output is correct
19 Correct 69 ms 46200 KB Output is correct
20 Correct 629 ms 48888 KB Output is correct
21 Correct 321 ms 48248 KB Output is correct
22 Correct 691 ms 49016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 44672 KB Output is correct
2 Correct 29 ms 44664 KB Output is correct
3 Correct 30 ms 46208 KB Output is correct
4 Correct 31 ms 45696 KB Output is correct
5 Correct 28 ms 44920 KB Output is correct
6 Correct 51 ms 45944 KB Output is correct
7 Correct 36 ms 45184 KB Output is correct
8 Correct 40 ms 44928 KB Output is correct
9 Correct 85 ms 47096 KB Output is correct
10 Correct 56 ms 45184 KB Output is correct
11 Correct 48 ms 44988 KB Output is correct
12 Correct 39 ms 44968 KB Output is correct
13 Correct 396 ms 44920 KB Output is correct
14 Correct 410 ms 44928 KB Output is correct
15 Correct 387 ms 44928 KB Output is correct
16 Correct 393 ms 44924 KB Output is correct
17 Correct 37 ms 45944 KB Output is correct
18 Correct 37 ms 45696 KB Output is correct
19 Correct 35 ms 45952 KB Output is correct
20 Correct 36 ms 45284 KB Output is correct
21 Correct 37 ms 45304 KB Output is correct
22 Correct 38 ms 45056 KB Output is correct
23 Correct 37 ms 45048 KB Output is correct
24 Correct 65 ms 46464 KB Output is correct
25 Correct 67 ms 46464 KB Output is correct
26 Correct 63 ms 46208 KB Output is correct
27 Correct 69 ms 46200 KB Output is correct
28 Correct 629 ms 48888 KB Output is correct
29 Correct 321 ms 48248 KB Output is correct
30 Correct 691 ms 49016 KB Output is correct
31 Correct 1376 ms 49016 KB Output is correct
32 Correct 753 ms 48376 KB Output is correct
33 Correct 1473 ms 49016 KB Output is correct
34 Correct 1186 ms 46956 KB Output is correct
35 Correct 1178 ms 46956 KB Output is correct
36 Correct 1177 ms 46952 KB Output is correct