#include<bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0);cin.tie(0)
#define F first
#define S second
using namespace std;
template<typename T>
using vvector = vector<vector<T>>;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INF=0x3f3f3f3f;
const ll P=1e9+7;
int main() {
speed;
int n;
cin>>n;
vector<ll> a(n+1);
for (int i=1;i<=n;i++) {
cin>>a[i];
}
int q;
cin>>q;
vector<pair<pll,ll>> Q(q+1);
for (int i=0;i<q;i++) {
cin>>Q[i].F.F>>Q[i].F.S>>Q[i].S;
}
ll ans=0;
for (int s=0;s<(1<<q);s++) {
for (int i=0;i<q;i++) {
if (s&(1<<i)) {
for (int j=Q[i].F.F;j<=Q[i].F.S;j++) a[i]^=Q[i].S;
}
}
vector<ll> pre(n+1);
for (int i=1;i<=n;i++) pre[i]=(pre[i-1]+a[i])%P;
ll now=0;
for (int i=1;i<=n;i++) {
for (int j=i;j<=n;j++) {
now+=(pre[j]-pre[i-1]+P)%P*(pre[j]-pre[i-1]+P)%P;
now%=P;
}
}
ans+=now;
ans%=P;
for (int i=0;i<q;i++) {
if (s&(1<<i)) {
for (int j=Q[i].F.F;j<=Q[i].F.S;j++) a[i]^=Q[i].S;
}
}
}
cout<<ans<<"\n";
return 0;
}
# | 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... |