#include<bits/stdc++.h>
#define taskname "C"
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;
const int lim = 1e3 + 5;
void add(int& a, int b){
if((a += b) >= mod){
a -= mod;
}
}
int n, q, a[lim];
vector<tuple<int, int, int>>query;
namespace sub125{
void solve(){
for(auto& [l, r, x] : query){
cin >> l >> r >> x;
}
int ans = 0;
vector<int>A(n + 1);
for(int mask = (1 << q) - 1; mask > -1; mask--){
for(int i = 1; i <= n; i++){
A[i] = a[i];
}
for(int i = 0; i < q; i++){
if(1 << i & mask){
auto& [l, r, x] = query[i];
for(int j = l; j <= r; j++){
A[j] ^= x;
}
}
}
for(int i = 1; i <= n; i++){
for(int j = i, sum = 0; j <= n; j++){
sum += A[j];
add(ans, 1LL * sum * sum % mod);
}
}
}
cout << ans;
}
}
namespace sub6{
int state(int x, int y, int i, int j){
return (i >> x & 1) | ((j >> y & 1) << 1);
}
void solve(){
int ans = 0;
vector<int>dp(4), ndp;
for(int x = 0; x < 7; x++){
for(int y = 0; y < 7; y++){
for(int i = 1; i <= n; i++){
for(int j = i; j <= n; j++){
dp[0] = dp[1] = dp[2] = dp[3] = 0;
dp[state(x, y, a[i], a[j])] = 1;
for(auto& [l, r, X] : query){
ndp = dp;
for(int mask = 0; mask < 4; mask++){
int n_mask = mask;
if(l <= i && r >= i && (1 << x & X)){
n_mask ^= 1;
}
if(l <= j && r >= j && (1 << y & X)){
n_mask ^= 2;
}
add(ndp[n_mask], dp[mask]);
}
swap(dp, ndp);
}
add(ans, ll(1 + int(i != j)) * i * (n - j + 1) * dp[3] * (1 << (x + y)) % mod);
}
}
}
}
cout << ans;
}
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
if(fopen(taskname".inp", "r")){
freopen(taskname".inp", "r", stdin);
}
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
}
cin >> q;
query.resize(q);
bool x_32 = true;
for(auto& [l, r, x] : query){
cin >> l >> r >> x;
if(x > 31){
x_32 = false;
}
}
if((n <= 100 && q <= 10) || (n <= 30 && q <= 20)){
sub125::solve();
}
else if(true){
sub6::solve();
}
else if(n <= 30 && q <= 5000 && x_32 && *max_element(a + 1, a + n + 1) < 32){
sub6::solve();
}
}
컴파일 시 표준 에러 (stderr) 메시지
xorsum.cpp: In function 'int main()':
xorsum.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
81 | freopen(taskname".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |