Submission #530872

# Submission time Handle Problem Language Result Execution time Memory
530872 2022-02-27T03:47:00 Z abc864197532 Intergalactic ship (IZhO19_xorsum) C++17
6 / 100
914 ms 2960 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pii pair<int,int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T i, U ...j) {
	cout << i << ' ', abc(j...);
}
template <typename T> void printv(T l, T r) {
	for (; l != r; ++l)
		cout << *l << " \n"[l + 1 == r];
}
#ifdef Doludu
#define test(x...) abc("[" + string(#x) + "]", x);
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#else
#define test(x...) void(0)
#define owo ios::sync_with_stdio(false)
#endif
const int mod = 1e9 + 7, N = 200000;

int main () {
	owo;
	int n, q;
	cin >> n;
	vector <vector <int>> cnt(n, vector <int> (32, 0));
	vector <int> cnt2(n + 1, 0);
	for (int i = 0, x; i < n; ++i)
		cin >> x, cnt[i][x]++;
	cin >> q;
	for (int i = 0, l, r, x; i < q; ++i) {
		cin >> l >> r >> x, --l;
		assert(l + 1 == r);
		cnt2[l]++;
		vector <int> ncnt = cnt[l];
		for (int i = 0; i < 32; ++i) {
			cnt[l][i ^ x] += ncnt[i];
			if (cnt[l][i ^ x] >= mod)
				cnt[l][i ^ x] -= mod;
		}
	}
	for (int i = n; i > 0; --i)
		cnt2[i - 1] += cnt2[i];
	for (int i = 0; i <= n; ++i) {
		int x = cnt2[i];
		int now = 1;
		while (x--)
			now = now * 2 % mod;
		cnt2[i] = now;
	}
	vector <lli> pre(3101, 0), dp;
	pre[0] = 1;
	lli ans = 0;
	for (int i = 0; i < n; ++i) {
		dp.assign(3101, 0);
		for (int k = 0; k < 32; ++k) for (int j = 0; j + k < 3101; ++j) {
			(dp[j + k] += pre[j] * cnt[i][k]) %= mod;
		}
		for (int j = 0; j < 3101; ++j) {
			pre[j] = dp[j];
			(ans += dp[j] * j * j * (n + 1) % mod * cnt2[i + 1]) %= mod;
		}
	}
	pre.assign(160000, 0);
	pre[0] = 1;
	for (int i = 0; i < n; ++i) {
		dp.assign(160000, 0);
		for (int k = 0; k < 32; ++k) for (int j = 0; j + k * (n - i) < 160000; ++j) {
			(dp[j + k * (n - i)] += pre[j] * cnt[i][k]) %= mod;
		}
		pre = dp;
	}
	for (int j = 0; j < 160000; ++j) {
		(ans += mod - dp[j] * j % mod * j % mod) %= mod;
	}
	assert(0 <= ans && ans < mod);
	cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 914 ms 2880 KB Output is correct
2 Correct 856 ms 2960 KB Output is correct
3 Correct 886 ms 2896 KB Output is correct
4 Correct 895 ms 2880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 716 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 460 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -