Submission #530896

# Submission time Handle Problem Language Result Execution time Memory
530896 2022-02-27T05:03:38 Z abc864197532 Intergalactic ship (IZhO19_xorsum) C++17
0 / 100
126 ms 1444 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;

lli modpow(lli a, int b) {
	lli ans = 1;
	for (; b >>= 1; a = a * a % mod) {
		if (b & 1)
			ans = ans * a % mod;
	}
	return ans;
}

int main () {
	owo;
	int n, q;
	cin >> n;
	vector <int> a(n), b(n, -1);
	for (int i = 0; i < n; ++i)
		cin >> a[i];
	cin >> q;
	vector <int> x(q);
	for (int i = 0, l, r; i < q; ++i) {
		cin >> l >> r >> x[i], --l;
		for (int j = l; j < r; ++j)
			b[j] = i;
	}
	lli ans = 0;
	for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
		lli pre = 0;
		if (b[i] == b[j] && b[i] != -1) {
			pre = modpow(2, q - 1) * (a[i] * a[j] + (a[i] ^ x[b[i]]) * (a[j] ^ x[b[j]])) % mod;
		} else {
			vector <int> A = {a[i]}, B = {a[j]};
			int cnt = q;
			if (b[i] != -1)
				A.pb(a[i] ^ x[b[i]]), cnt--;
			if (b[j] != -1)
				B.pb(a[j] ^ x[b[j]]), cnt--;
			lli tmp = 0;
			for (int ii : A) for (int jj : B) {
				tmp += ii * jj;
			}
			pre = modpow(2, cnt) * tmp % mod;
		}
		int ni = i, nj = j;
		if (ni > nj)
			swap(ni, nj);
		(ans += pre * (ni + 1) * (n - nj)) %= mod;
	}
	cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 1444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 126 ms 312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 1 ms 204 KB Output isn't correct
4 Halted 0 ms 0 KB -