#include <iostream>//model_code
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
using namespace std;
template<typename T1, typename T2>inline void chkmin(T1 &x, T2 y) { if (x > y) x = y; }
template<typename T1, typename T2>inline void chkmax(T1 &x, T2 y) { if (x < y) x = y; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const pair<T, U> &_p) { _out << _p.first << ' ' << _p.second; return _out; }
template<typename T, typename U> inline istream &operator>> (istream &_in, pair<T, U> &_p) { _in >> _p.first >> _p.second; return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const vector<T> &_v) { if (_v.empty()) { return _out; } _out << _v.front(); for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline istream &operator>> (istream &_in, vector<T> &_v) { for (auto &_i : _v) { _in >> _i; } return _in; }
template<typename T> inline ostream &operator<< (ostream &_out, const set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_set<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T> inline ostream &operator<< (ostream &_out, const unordered_multiset<T> &_s) { if (_s.empty()) { return _out; } _out << *_s.begin(); for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) { _out << ' ' << *_it; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
template<typename T, typename U> inline ostream &operator<< (ostream &_out, const unordered_map<T, U> &_m) { if (_m.empty()) { return _out; } _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')'; for (auto _it = ++_m.begin(); _it != _m.end(); ++_it) { _out << ", (" << _it->first << ": " << _it->second << ')'; } return _out; }
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define left left228
#define right right228
#define rank rank228
#define y1 y1228
#define read(FILENAME) freopen((FILENAME + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((FILENAME + ".out").c_str(), "w", stdout)
#define files(FILENAME) read(FILENAME), write(FILENAME)
#define pb push_back
const string FILENAME = "input";
const int MAXN = 1005;
const int MAXM = 100228;
const int Mod = 1000000007;
void inc(int &a, int b) {
a += b;
if (a >= Mod) {
a -= Mod;
}
}
int add(int a, int b) {
return (a + b >= Mod ? a + b - Mod: a + b);
}
void dec(int &a, int b) {
a -= b;
if (a < 0) {
a += Mod;
}
}
int sub(int a, int b) {
return (a - b >= 0 ? a - b: a - b + Mod);
}
int mul(long long a, long long b) {
return (a * b) % Mod;
}
int powm(int a, int b) {
int res = 1;
while (b) {
if (b & 1) res = mul(res, a);
a = mul(a, a);
b >>= 1;
}
return res;
}
int rev(int a) {
return powm(a, Mod - 2);
}
int n;
int a[MAXN];
int cnt[7][MAXN];
int x[MAXM];
int l[MAXM], r[MAXM];
int cntp[MAXN][MAXN];
int ways[MAXM][2];
bool init[7][MAXN];
int res[MAXN][MAXN];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
// read(FILENAME);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
for (int j = 0; j < 7; j++) {
init[j][i] = a[i] & (1 << j);
}
}
int q;
cin >> q;
for (int i = 0; i < q; i++) {
cin >> l[i] >> r[i] >> x[i];
for (int c = 0; c < 7; c++) {
if (x[i] & (1 << c)) {
cnt[c][l[i]]++;
cnt[c][r[i] + 1]--;
}
}
}
for (int i = 0; i < 7; i++) {
for (int j = 1; j <= n; j++) {
cnt[i][j] += cnt[i][j - 1];
}
}
ways[0][0] = 1;
ways[0][1] = 0;
for (int i = 1; i <= q; i++) {
ways[i][0] = add(ways[i - 1][1], ways[i - 1][0]);
ways[i][1] = add(ways[i - 1][0], ways[i - 1][1]);
}
for (int i = 0; i < 7; i++) {
for (int j = 0; j < 7; j++) {
memset(cntp, 0, sizeof(cntp));
for (int k = 0; k < q; k++) {
if ((x[k] & (1 << i)) && (x[k] & (1 << j))) {
cntp[l[k]][r[k]]++;
}
}
for (int k = 1; k <= n; k++) {
for (int g = n; g >= k; g--) {
cntp[k][g] += cntp[k - 1][g] + cntp[k][g + 1] - cntp[k - 1][g + 1];
}
}
for (int posi = 1; posi <= n; posi++) {
for (int posj = posi; posj <= n; posj++) {
int cnt11 = cntp[posi][posj];
int cnt10 = cnt[i][posi] - cnt11;
int cnt01 = cnt[j][posj] - cnt11;
int cnt00 = q - cnt11 - cnt10 - cnt01;
int kek = 0;
for (int t = 0; t < 2; t++) {
for (int t1 = 0; t1 < 2; t1++) {
for (int t2 = 0; t2 < 2; t2++) {
int c = init[i][posi] ^ t ^ t1;
int c1 = init[j][posj] ^ t ^ t2;
//cout << c << ' ' << c1 << endl;
if (c == 0 || c1 == 0) {
continue;
}
//cout << c << ' ' << c1 << endl;
inc(kek, mul(ways[cnt11][t], mul(ways[cnt10][t1], ways[cnt01][t2])));
}
}
}
//cout << kek << endl;
inc(res[posi][posj], mul(add(ways[cnt00][0], ways[cnt00][1]), mul(kek, 1 << (i + j))));
}
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
ans = add(ans, mul(res[i][i], mul(i, n - i + 1)));
}
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
ans = add(ans, mul(2, mul(res[i][j], mul(i, n - j + 1))));
}
}
cout << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4308 KB |
Output is correct |
2 |
Correct |
6 ms |
4352 KB |
Output is correct |
3 |
Correct |
7 ms |
4384 KB |
Output is correct |
4 |
Correct |
7 ms |
4308 KB |
Output is correct |
5 |
Correct |
8 ms |
4300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4308 KB |
Output is correct |
2 |
Correct |
6 ms |
4352 KB |
Output is correct |
3 |
Correct |
7 ms |
4384 KB |
Output is correct |
4 |
Correct |
7 ms |
4308 KB |
Output is correct |
5 |
Correct |
8 ms |
4300 KB |
Output is correct |
6 |
Correct |
17 ms |
4692 KB |
Output is correct |
7 |
Correct |
15 ms |
4692 KB |
Output is correct |
8 |
Correct |
15 ms |
4744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
7372 KB |
Output is correct |
2 |
Correct |
17 ms |
4948 KB |
Output is correct |
3 |
Correct |
14 ms |
4680 KB |
Output is correct |
4 |
Correct |
14 ms |
4692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
776 ms |
8272 KB |
Output is correct |
2 |
Correct |
795 ms |
8268 KB |
Output is correct |
3 |
Correct |
772 ms |
8276 KB |
Output is correct |
4 |
Correct |
799 ms |
8268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4436 KB |
Output is correct |
2 |
Correct |
7 ms |
4460 KB |
Output is correct |
3 |
Correct |
10 ms |
4460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
4436 KB |
Output is correct |
2 |
Correct |
7 ms |
4460 KB |
Output is correct |
3 |
Correct |
10 ms |
4460 KB |
Output is correct |
4 |
Correct |
10 ms |
4592 KB |
Output is correct |
5 |
Correct |
10 ms |
4600 KB |
Output is correct |
6 |
Correct |
11 ms |
4564 KB |
Output is correct |
7 |
Correct |
9 ms |
4600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4308 KB |
Output is correct |
2 |
Correct |
6 ms |
4352 KB |
Output is correct |
3 |
Correct |
7 ms |
4384 KB |
Output is correct |
4 |
Correct |
7 ms |
4308 KB |
Output is correct |
5 |
Correct |
8 ms |
4300 KB |
Output is correct |
6 |
Correct |
17 ms |
4692 KB |
Output is correct |
7 |
Correct |
15 ms |
4692 KB |
Output is correct |
8 |
Correct |
15 ms |
4744 KB |
Output is correct |
9 |
Correct |
8 ms |
4436 KB |
Output is correct |
10 |
Correct |
7 ms |
4460 KB |
Output is correct |
11 |
Correct |
10 ms |
4460 KB |
Output is correct |
12 |
Correct |
18 ms |
4736 KB |
Output is correct |
13 |
Correct |
15 ms |
4748 KB |
Output is correct |
14 |
Correct |
19 ms |
4692 KB |
Output is correct |
15 |
Correct |
18 ms |
4688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4308 KB |
Output is correct |
2 |
Correct |
6 ms |
4352 KB |
Output is correct |
3 |
Correct |
7 ms |
4384 KB |
Output is correct |
4 |
Correct |
7 ms |
4308 KB |
Output is correct |
5 |
Correct |
8 ms |
4300 KB |
Output is correct |
6 |
Correct |
17 ms |
4692 KB |
Output is correct |
7 |
Correct |
15 ms |
4692 KB |
Output is correct |
8 |
Correct |
15 ms |
4744 KB |
Output is correct |
9 |
Correct |
8 ms |
4436 KB |
Output is correct |
10 |
Correct |
7 ms |
4460 KB |
Output is correct |
11 |
Correct |
10 ms |
4460 KB |
Output is correct |
12 |
Correct |
10 ms |
4592 KB |
Output is correct |
13 |
Correct |
10 ms |
4600 KB |
Output is correct |
14 |
Correct |
11 ms |
4564 KB |
Output is correct |
15 |
Correct |
9 ms |
4600 KB |
Output is correct |
16 |
Correct |
18 ms |
4736 KB |
Output is correct |
17 |
Correct |
15 ms |
4748 KB |
Output is correct |
18 |
Correct |
19 ms |
4692 KB |
Output is correct |
19 |
Correct |
18 ms |
4688 KB |
Output is correct |
20 |
Correct |
292 ms |
9232 KB |
Output is correct |
21 |
Correct |
263 ms |
9308 KB |
Output is correct |
22 |
Correct |
242 ms |
9196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
4308 KB |
Output is correct |
2 |
Correct |
6 ms |
4352 KB |
Output is correct |
3 |
Correct |
7 ms |
4384 KB |
Output is correct |
4 |
Correct |
7 ms |
4308 KB |
Output is correct |
5 |
Correct |
8 ms |
4300 KB |
Output is correct |
6 |
Correct |
17 ms |
4692 KB |
Output is correct |
7 |
Correct |
15 ms |
4692 KB |
Output is correct |
8 |
Correct |
15 ms |
4744 KB |
Output is correct |
9 |
Correct |
46 ms |
7372 KB |
Output is correct |
10 |
Correct |
17 ms |
4948 KB |
Output is correct |
11 |
Correct |
14 ms |
4680 KB |
Output is correct |
12 |
Correct |
14 ms |
4692 KB |
Output is correct |
13 |
Correct |
776 ms |
8272 KB |
Output is correct |
14 |
Correct |
795 ms |
8268 KB |
Output is correct |
15 |
Correct |
772 ms |
8276 KB |
Output is correct |
16 |
Correct |
799 ms |
8268 KB |
Output is correct |
17 |
Correct |
8 ms |
4436 KB |
Output is correct |
18 |
Correct |
7 ms |
4460 KB |
Output is correct |
19 |
Correct |
10 ms |
4460 KB |
Output is correct |
20 |
Correct |
10 ms |
4592 KB |
Output is correct |
21 |
Correct |
10 ms |
4600 KB |
Output is correct |
22 |
Correct |
11 ms |
4564 KB |
Output is correct |
23 |
Correct |
9 ms |
4600 KB |
Output is correct |
24 |
Correct |
18 ms |
4736 KB |
Output is correct |
25 |
Correct |
15 ms |
4748 KB |
Output is correct |
26 |
Correct |
19 ms |
4692 KB |
Output is correct |
27 |
Correct |
18 ms |
4688 KB |
Output is correct |
28 |
Correct |
292 ms |
9232 KB |
Output is correct |
29 |
Correct |
263 ms |
9308 KB |
Output is correct |
30 |
Correct |
242 ms |
9196 KB |
Output is correct |
31 |
Correct |
873 ms |
11268 KB |
Output is correct |
32 |
Correct |
863 ms |
11280 KB |
Output is correct |
33 |
Correct |
942 ms |
11188 KB |
Output is correct |
34 |
Correct |
917 ms |
11088 KB |
Output is correct |
35 |
Correct |
903 ms |
11076 KB |
Output is correct |
36 |
Correct |
918 ms |
11060 KB |
Output is correct |