Submission #393333

# Submission time Handle Problem Language Result Execution time Memory
393333 2021-04-23T08:07:54 Z Jorge213 Intergalactic ship (IZhO19_xorsum) C++17
100 / 100
941 ms 194772 KB
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int Q = 1e5 + 10;
const int N = 1005;
const int B = 7;
int n, q, a[N], pw2[Q];
int one[B][N], both[B][B][N][N];

int add(int x, int y) {
	if (x + y >= mod) {
		return x + y - mod;
	}
	return x + y;
}

int mul(int x, int y) {
	return (long long) x * y % mod;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);

	pw2[0] = 1;
	for (int i = 1; i < Q; i++) {
		pw2[i] = add(pw2[i - 1], pw2[i - 1]);
	}

	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	cin >> q;

	int l, r, x;
	for (int i = 0; i < q; i++) {
		cin >> l >> r >> x;

		for (int b = 0; b < B; b++) {
			if (!(x & (1 << b))) continue;
			one[b][l]++;
			one[b][r + 1]--;
		}

		for (int b1 = 0; b1 < B; b1++) {
			if (!(x & (1 << b1))) continue;

			for (int b2 = 0; b2 < B; b2++) {
				if (!(x & (1 << b2))) continue;
				both[b1][b2][l][r]++;
			}
		}

	}

	for (int b = 0; b < B; b++) {
		for (int i = 1; i <= n; i++) {
			one[b][i] += one[b][i - 1];
		}
	}

	for (int b1 = 0; b1 < B; b1++) {
		for (int b2 = 0; b2 < B; b2++) {
			for (int len = n; len >= 2; len--) {
				for (int i = 1; i + len - 1 <= n; i++) {
					int j = i + len - 1;
					both[b1][b2][i][j - 1] += both[b1][b2][i][j];
					both[b1][b2][i + 1][j] += both[b1][b2][i][j];
					both[b1][b2][i + 1][j - 1] -= both[b1][b2][i][j];
				}
			}
		}
	}

	int ans = 0;
	for (int i = 1; i <= n; i++) {
		for (int j = i; j <= n; j++) {

			int times = mul(i, n - j + 1);
			if (i != j) times = mul(times, 2);

			for (int b1 = 0; b1 < B; b1++) {
				for (int b2 = 0; b2 < B; b2++) {
					int cij = both[b1][b2][i][j];
					int coi = one[b1][i] - cij;
					int coj = one[b2][j] - cij;
					int cn = q - (cij + coi + coj);

					int be = cij ? pw2[cij - 1] : 1;
					int bo = cij ? pw2[cij - 1] : 0;

					int le = coi ? pw2[coi - 1] : 1;
					int lo = coi ? pw2[coi - 1] : 0;

					int re = coj ? pw2[coj - 1] : 1;
					int ro = coj ? pw2[coj - 1] : 0;

					int cont;
					if (!(a[i] & (1 << b1)) && !(a[j] & (1 << b2))) {
						cont = add(mul(bo, mul(le, re)), mul(be, mul(lo, ro)));
					}
					if ((a[i] & (1 << b1)) && !(a[j] & (1 << b2))) {
						cont = add(mul(be, mul(le, ro)), mul(bo, mul(lo, re)));
					}
					if (!(a[i] & (1 << b1)) && (a[j] & (1 << b2))) {
						cont = add(mul(be, mul(lo, re)), mul(bo, mul(le, ro)));
					}
					if ((a[i] & (1 << b1)) && (a[j] & (1 << b2))) {
						cont = add(mul(be, mul(le, re)), mul(bo, mul(lo, ro)));
					}

					cont = mul(cont, pw2[cn]);
					cont = mul(cont, mul(times, pw2[b1 + b2]));
					ans = add(ans, cont);
				}
			}
		}
	}

	cout << ans << '\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 2 ms 2764 KB Output is correct
4 Correct 2 ms 2764 KB Output is correct
5 Correct 2 ms 2764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 2 ms 2764 KB Output is correct
4 Correct 2 ms 2764 KB Output is correct
5 Correct 2 ms 2764 KB Output is correct
6 Correct 16 ms 20236 KB Output is correct
7 Correct 15 ms 20228 KB Output is correct
8 Correct 15 ms 20180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 44 ms 20204 KB Output is correct
2 Correct 20 ms 20220 KB Output is correct
3 Correct 17 ms 20184 KB Output is correct
4 Correct 16 ms 20172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 900 ms 193772 KB Output is correct
2 Correct 839 ms 193664 KB Output is correct
3 Correct 807 ms 193668 KB Output is correct
4 Correct 828 ms 193676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6604 KB Output is correct
2 Correct 4 ms 6604 KB Output is correct
3 Correct 4 ms 6604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 6604 KB Output is correct
2 Correct 4 ms 6604 KB Output is correct
3 Correct 4 ms 6604 KB Output is correct
4 Correct 6 ms 6748 KB Output is correct
5 Correct 7 ms 6732 KB Output is correct
6 Correct 6 ms 6732 KB Output is correct
7 Correct 5 ms 6732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 2 ms 2764 KB Output is correct
4 Correct 2 ms 2764 KB Output is correct
5 Correct 2 ms 2764 KB Output is correct
6 Correct 16 ms 20236 KB Output is correct
7 Correct 15 ms 20228 KB Output is correct
8 Correct 15 ms 20180 KB Output is correct
9 Correct 4 ms 6604 KB Output is correct
10 Correct 4 ms 6604 KB Output is correct
11 Correct 4 ms 6604 KB Output is correct
12 Correct 16 ms 20236 KB Output is correct
13 Correct 16 ms 20196 KB Output is correct
14 Correct 17 ms 20172 KB Output is correct
15 Correct 17 ms 20152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 2 ms 2764 KB Output is correct
4 Correct 2 ms 2764 KB Output is correct
5 Correct 2 ms 2764 KB Output is correct
6 Correct 16 ms 20236 KB Output is correct
7 Correct 15 ms 20228 KB Output is correct
8 Correct 15 ms 20180 KB Output is correct
9 Correct 4 ms 6604 KB Output is correct
10 Correct 4 ms 6604 KB Output is correct
11 Correct 4 ms 6604 KB Output is correct
12 Correct 6 ms 6748 KB Output is correct
13 Correct 7 ms 6732 KB Output is correct
14 Correct 6 ms 6732 KB Output is correct
15 Correct 5 ms 6732 KB Output is correct
16 Correct 16 ms 20236 KB Output is correct
17 Correct 16 ms 20196 KB Output is correct
18 Correct 17 ms 20172 KB Output is correct
19 Correct 17 ms 20152 KB Output is correct
20 Correct 290 ms 98440 KB Output is correct
21 Correct 257 ms 98464 KB Output is correct
22 Correct 264 ms 98356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1228 KB Output is correct
2 Correct 1 ms 1868 KB Output is correct
3 Correct 2 ms 2764 KB Output is correct
4 Correct 2 ms 2764 KB Output is correct
5 Correct 2 ms 2764 KB Output is correct
6 Correct 16 ms 20236 KB Output is correct
7 Correct 15 ms 20228 KB Output is correct
8 Correct 15 ms 20180 KB Output is correct
9 Correct 44 ms 20204 KB Output is correct
10 Correct 20 ms 20220 KB Output is correct
11 Correct 17 ms 20184 KB Output is correct
12 Correct 16 ms 20172 KB Output is correct
13 Correct 900 ms 193772 KB Output is correct
14 Correct 839 ms 193664 KB Output is correct
15 Correct 807 ms 193668 KB Output is correct
16 Correct 828 ms 193676 KB Output is correct
17 Correct 4 ms 6604 KB Output is correct
18 Correct 4 ms 6604 KB Output is correct
19 Correct 4 ms 6604 KB Output is correct
20 Correct 6 ms 6748 KB Output is correct
21 Correct 7 ms 6732 KB Output is correct
22 Correct 6 ms 6732 KB Output is correct
23 Correct 5 ms 6732 KB Output is correct
24 Correct 16 ms 20236 KB Output is correct
25 Correct 16 ms 20196 KB Output is correct
26 Correct 17 ms 20172 KB Output is correct
27 Correct 17 ms 20152 KB Output is correct
28 Correct 290 ms 98440 KB Output is correct
29 Correct 257 ms 98464 KB Output is correct
30 Correct 264 ms 98356 KB Output is correct
31 Correct 941 ms 194772 KB Output is correct
32 Correct 868 ms 194760 KB Output is correct
33 Correct 906 ms 194656 KB Output is correct
34 Correct 864 ms 194552 KB Output is correct
35 Correct 862 ms 194544 KB Output is correct
36 Correct 900 ms 194600 KB Output is correct