#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define fp(i,a,b) for(ll i=a ; i<b ; i++)
#define fn(i,a,b) for(int i=a ; i>=b ; i--)
#define ones(x) __builtin_popcount(x)
#define pb push_back
#define mk make_pair
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define dbg(x) cout << (#x) << " = " << x << " "
#define fini cout << "\n";
#define line cout << "-----------------------------------\n";
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef tree<
ll,
null_type,
less_equal<ll>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
int read (){
int x = 0, f = 1; char s = getchar();while (s < '0' || s > '9') {if (s == '-') f = -1; s = getchar();}
while (s >= '0' && s <= '9') x = x * 10 + s - '0', s = getchar();
return x * f;
}
const ll M=1e5+7;
const ll N=1e3+7;
const ll inf=1e9;
const ll mod=1e9+7;
const ll mod2=998244353;
struct rng{
int l,r,x;
};
int n,q;
int a[N];
rng qs[M];
int c[N][N],c1[N],c2[N];
ll b[4],z[4];
ll e[M];
ll ans;
ll pro(ll a,ll b){
return (a*b)%mod;
}
void go(int ide){
cin >> n;
fp(i,1,n+1) cin >> a[i];
cin >> q;
fp(i,1,q+1) cin >> qs[i].l >> qs[i].r >> qs[i].x;
e[0] = 1;
fp(i,1,M) e[i] = (e[i-1]*2)%mod;
fp(k1,0,7) fp(k2,0,7){
fp(i,1,n+1){
fp(j,1,n+1) c[i][j] = 0;
c1[i] = c2[i] = 0;
}
fp(i,1,q+1){
int l = qs[i].l;
int r = qs[i].r;
if (1<<k1&qs[i].x) c1[l]++, c1[r+1]--;
if (1<<k2&qs[i].x) c2[l]++, c2[r+1]--;
if ((1<<k1&qs[i].x) && (1<<k2&qs[i].x)){
c[l][l]++;
c[l][r+1]--;
c[r+1][l]--;
c[r+1][r+1]++;
}
}
fp(i,1,n+1){
c1[i] += c1[i-1];
c2[i] += c2[i-1];
fp(j,1,n+1) c[i][j] += c[i][j-1] + c[i-1][j] - c[i-1][j-1];
}
fp(i,1,n+1) fp(j,1,n+1){
z[3] = c[i][j];
z[2] = c1[i] - c[i][j];
z[1] = c2[j] - c[i][j];
z[0] = q - c1[i] - c2[j] + c[i][j];
fp(k,0,4) b[k] = 0;
b[2*(a[i]>>k1&1) + (a[j]>>k2&1)] = e[z[0]];
int cont = (z[1]>0) + (z[2]>0) + (z[3]>0);
if (cont>1) b[3] = e[q-2];
else{
if (z[1]) b[3] = e[z[1]-1]*(b[3]+b[2]);
if (z[2]) b[3] = e[z[2]-1]*(b[3]+b[1]);
if (z[3]) b[3] = e[z[3]-1]*(b[3]+b[0]);
}
ans = (ans + pro(e[k1+k2], pro(pro(min(i,j), n-max(i,j)+1), b[3]%mod)))%mod;
// dbg(ans); fini;
}
// line;
}
cout << ans << "\n";
}
int main(){
fastio;
int tst=1;
// cin >> tst;
// cout << fixed << setprecision(12);
fp(i,0,tst) go(i+1);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
2 ms |
1100 KB |
Output is correct |
4 |
Correct |
2 ms |
1100 KB |
Output is correct |
5 |
Correct |
2 ms |
1100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
2 ms |
1100 KB |
Output is correct |
4 |
Correct |
2 ms |
1100 KB |
Output is correct |
5 |
Correct |
2 ms |
1100 KB |
Output is correct |
6 |
Correct |
14 ms |
1516 KB |
Output is correct |
7 |
Correct |
13 ms |
1484 KB |
Output is correct |
8 |
Correct |
15 ms |
1516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
73 ms |
2664 KB |
Output is correct |
2 |
Correct |
19 ms |
1720 KB |
Output is correct |
3 |
Correct |
13 ms |
1480 KB |
Output is correct |
4 |
Correct |
13 ms |
1484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1164 ms |
5068 KB |
Output is correct |
2 |
Correct |
1148 ms |
5068 KB |
Output is correct |
3 |
Correct |
1147 ms |
5060 KB |
Output is correct |
4 |
Correct |
1126 ms |
5044 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1228 KB |
Output is correct |
2 |
Correct |
2 ms |
1228 KB |
Output is correct |
3 |
Correct |
2 ms |
1228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1228 KB |
Output is correct |
2 |
Correct |
2 ms |
1228 KB |
Output is correct |
3 |
Correct |
2 ms |
1228 KB |
Output is correct |
4 |
Correct |
6 ms |
1296 KB |
Output is correct |
5 |
Correct |
6 ms |
1228 KB |
Output is correct |
6 |
Correct |
7 ms |
1228 KB |
Output is correct |
7 |
Correct |
7 ms |
1228 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
2 ms |
1100 KB |
Output is correct |
4 |
Correct |
2 ms |
1100 KB |
Output is correct |
5 |
Correct |
2 ms |
1100 KB |
Output is correct |
6 |
Correct |
14 ms |
1516 KB |
Output is correct |
7 |
Correct |
13 ms |
1484 KB |
Output is correct |
8 |
Correct |
15 ms |
1516 KB |
Output is correct |
9 |
Correct |
2 ms |
1228 KB |
Output is correct |
10 |
Correct |
2 ms |
1228 KB |
Output is correct |
11 |
Correct |
2 ms |
1228 KB |
Output is correct |
12 |
Correct |
15 ms |
1516 KB |
Output is correct |
13 |
Correct |
13 ms |
1484 KB |
Output is correct |
14 |
Correct |
13 ms |
1520 KB |
Output is correct |
15 |
Correct |
13 ms |
1524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
2 ms |
1100 KB |
Output is correct |
4 |
Correct |
2 ms |
1100 KB |
Output is correct |
5 |
Correct |
2 ms |
1100 KB |
Output is correct |
6 |
Correct |
14 ms |
1516 KB |
Output is correct |
7 |
Correct |
13 ms |
1484 KB |
Output is correct |
8 |
Correct |
15 ms |
1516 KB |
Output is correct |
9 |
Correct |
2 ms |
1228 KB |
Output is correct |
10 |
Correct |
2 ms |
1228 KB |
Output is correct |
11 |
Correct |
2 ms |
1228 KB |
Output is correct |
12 |
Correct |
6 ms |
1296 KB |
Output is correct |
13 |
Correct |
6 ms |
1228 KB |
Output is correct |
14 |
Correct |
7 ms |
1228 KB |
Output is correct |
15 |
Correct |
7 ms |
1228 KB |
Output is correct |
16 |
Correct |
15 ms |
1516 KB |
Output is correct |
17 |
Correct |
13 ms |
1484 KB |
Output is correct |
18 |
Correct |
13 ms |
1520 KB |
Output is correct |
19 |
Correct |
13 ms |
1524 KB |
Output is correct |
20 |
Correct |
379 ms |
4504 KB |
Output is correct |
21 |
Correct |
354 ms |
4504 KB |
Output is correct |
22 |
Correct |
320 ms |
4600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1100 KB |
Output is correct |
2 |
Correct |
1 ms |
1100 KB |
Output is correct |
3 |
Correct |
2 ms |
1100 KB |
Output is correct |
4 |
Correct |
2 ms |
1100 KB |
Output is correct |
5 |
Correct |
2 ms |
1100 KB |
Output is correct |
6 |
Correct |
14 ms |
1516 KB |
Output is correct |
7 |
Correct |
13 ms |
1484 KB |
Output is correct |
8 |
Correct |
15 ms |
1516 KB |
Output is correct |
9 |
Correct |
73 ms |
2664 KB |
Output is correct |
10 |
Correct |
19 ms |
1720 KB |
Output is correct |
11 |
Correct |
13 ms |
1480 KB |
Output is correct |
12 |
Correct |
13 ms |
1484 KB |
Output is correct |
13 |
Correct |
1164 ms |
5068 KB |
Output is correct |
14 |
Correct |
1148 ms |
5068 KB |
Output is correct |
15 |
Correct |
1147 ms |
5060 KB |
Output is correct |
16 |
Correct |
1126 ms |
5044 KB |
Output is correct |
17 |
Correct |
2 ms |
1228 KB |
Output is correct |
18 |
Correct |
2 ms |
1228 KB |
Output is correct |
19 |
Correct |
2 ms |
1228 KB |
Output is correct |
20 |
Correct |
6 ms |
1296 KB |
Output is correct |
21 |
Correct |
6 ms |
1228 KB |
Output is correct |
22 |
Correct |
7 ms |
1228 KB |
Output is correct |
23 |
Correct |
7 ms |
1228 KB |
Output is correct |
24 |
Correct |
15 ms |
1516 KB |
Output is correct |
25 |
Correct |
13 ms |
1484 KB |
Output is correct |
26 |
Correct |
13 ms |
1520 KB |
Output is correct |
27 |
Correct |
13 ms |
1524 KB |
Output is correct |
28 |
Correct |
379 ms |
4504 KB |
Output is correct |
29 |
Correct |
354 ms |
4504 KB |
Output is correct |
30 |
Correct |
320 ms |
4600 KB |
Output is correct |
31 |
Correct |
1244 ms |
6480 KB |
Output is correct |
32 |
Correct |
1236 ms |
7304 KB |
Output is correct |
33 |
Correct |
1180 ms |
7208 KB |
Output is correct |
34 |
Correct |
1181 ms |
7112 KB |
Output is correct |
35 |
Correct |
1209 ms |
7100 KB |
Output is correct |
36 |
Correct |
1219 ms |
7084 KB |
Output is correct |