This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/**
____ ____ ____ __________________ ____ ____ ____
||I || ||c || ||e || || || ||M || ||a || ||n ||
||__|| ||__|| ||__|| ||________________|| ||__|| ||__|| ||__||
|/__\| |/__\| |/__\| |/________________\| |/__\| |/__\| |/__\|
*/
#include <iostream>
#include <chrono>
#include <stack>
#include <vector>
#define endl '\n'
#define maxn 1000005
#define maxlog 20
#define INF 1000000010
#define LINF 1000000000000000005
#define mod 1000000007
#define endl '\n'
#define pb(x) push_back(x)
#define X first
#define Y second
#define control cout<<"passed"<<endl;
#pragma GCC optimize("O3" , "Ofast" , "unroll-loops" , "fast-math")
#pragma GCC target("avx2")
using namespace std;
typedef pair <int, int> pii;
typedef long long ll;
typedef pair <ll, ll> pll;
typedef pair <int, ll> pil;
typedef pair <ll, int> pli;
typedef long double ld;
std::chrono::high_resolution_clock::time_point startT, currT;
constexpr double TIME_MULT = 1;
double timePassed()
{
using namespace std::chrono;
currT = high_resolution_clock::now();
double time = duration_cast<duration<double>>(currT - startT).count();
return time * TIME_MULT;
}
template <typename T>
T power2(T num)
{
return num * num;
}
int n, q;
int a[maxn], pref[maxn];
int l[maxn], r[maxn], x[maxn];
void read()
{
cin >> n;
for(int i = 1; i <= n; i++)
cin >> a[i];
cin >> q;
for(int i = 1; i <= q; i++)
cin >> l[i] >> r[i] >> x[i];
}
void solve()
{
int sum = 0;
for(int mask = 0; mask < (1 << q); mask++)
{
for(int bit = 0; bit < q; bit++)
if(mask & (1 << bit) == 1)
{
pref[l[bit]] ^= x[bit];
pref[r[bit] + 1] ^= x[bit];
}
for(int i = 2; i <= n; i++)
pref[i] ^= pref[i - 1];
for(int i = 1; i <= n; i++)
a[i] ^= pref[i];
int cur = 0 , pom = 0;
for(int i = 1; i <= n; i++)
{
pom = 0;
for(int j = i; j <= n; j++)
{
pom += a[j];
cur += power2(pom);
if(cur >= mod)
cur -= mod;
}
}
sum += cur;
if(sum >= mod)
sum -= mod;
for(int i = 1; i <= n; i++)
{
a[i] ^= pref[i];
pref[i] = 0;
}
}
cout << sum << endl;
}
void combine()
{
int t;
cin >> t;
//while(t--)
//read_solve();
}
int main()
{
/**#ifdef ONLINE_JUDGE
freopen("input.in", "r", stdin);
freopen("output.out", "w", stdout);
#endif*/
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
///startT = std::chrono::high_resolution_clock::now();
read();
solve();
return 0;
}
Compilation message (stderr)
xorsum.cpp: In function 'void solve()':
xorsum.cpp:82:34: warning: suggest parentheses around comparison in operand of '&' [-Wparentheses]
82 | if(mask & (1 << bit) == 1)
| ~~~~~~~~~~~^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |