Submission #393319

# Submission time Handle Problem Language Result Execution time Memory
393319 2021-04-23T07:51:38 Z Jorge213 Intergalactic ship (IZhO19_xorsum) C++17
0 / 100
1158 ms 252740 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 = 8;
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 mb = 0;
	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]++;
		}

		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 i = 1; i <= n; i++) {
				for (int len = n - i; len >= 0; len--) {
					both[b1][b2][i][i + len] += both[b1][b2][i][i + len + 1];
					both[b1][b2][i][i + len] += both[b1][b2][i - 1][i + len];
					both[b1][b2][i][i + len] -= both[b1][b2][i - 1][i + len + 1];
				}
			}
		}
	}

	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;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:37:6: warning: unused variable 'mb' [-Wunused-variable]
   37 |  int mb = 0;
      |      ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 2 ms 2252 KB Output is correct
3 Incorrect 3 ms 3404 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 2 ms 2252 KB Output is correct
3 Incorrect 3 ms 3404 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 53 ms 27012 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1158 ms 252740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 8524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 8524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 2 ms 2252 KB Output is correct
3 Incorrect 3 ms 3404 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 2 ms 2252 KB Output is correct
3 Incorrect 3 ms 3404 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 2 ms 2252 KB Output is correct
3 Incorrect 3 ms 3404 KB Output isn't correct
4 Halted 0 ms 0 KB -