/*
ЗАПУСКАЕМ
░ГУСЯ░▄▀▀▀▄░РАБОТЯГУ░░
▄███▀░◐░░░▌░░░░░░░
░░░░▌░░░░░▐░░░░░░░
░░░░▐░░░░░▐░░░░░░░
░░░░▌░░░░░▐▄▄░░░░░
░░░░▌░░░░▄▀▒▒▀▀▀▀▄
░░░▐░░░░▐▒▒▒▒▒▒▒▒▀▀▄
░░░▐░░░░▐▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░▀▄░░░░▀▄▒▒▒▒▒▒▒▒▒▒▀▄
░░░░░░▀▄▄▄▄▄█▄▄▄▄▄▄▄▄▄▄▄▀▄
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░░░▌▌░▌▌░░░░░
░░░░░░░░░▄▄▌▌▄▌▌░░░░░
*/
#include <iostream>
#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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
4344 KB |
Output is correct |
2 |
Correct |
15 ms |
4472 KB |
Output is correct |
3 |
Correct |
15 ms |
4344 KB |
Output is correct |
4 |
Correct |
15 ms |
4344 KB |
Output is correct |
5 |
Correct |
15 ms |
4344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
4344 KB |
Output is correct |
2 |
Correct |
15 ms |
4472 KB |
Output is correct |
3 |
Correct |
15 ms |
4344 KB |
Output is correct |
4 |
Correct |
15 ms |
4344 KB |
Output is correct |
5 |
Correct |
15 ms |
4344 KB |
Output is correct |
6 |
Correct |
26 ms |
4728 KB |
Output is correct |
7 |
Correct |
26 ms |
4728 KB |
Output is correct |
8 |
Correct |
26 ms |
4728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
68 ms |
6736 KB |
Output is correct |
2 |
Correct |
29 ms |
4984 KB |
Output is correct |
3 |
Correct |
26 ms |
4728 KB |
Output is correct |
4 |
Correct |
25 ms |
4728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1226 ms |
8340 KB |
Output is correct |
2 |
Correct |
1236 ms |
8184 KB |
Output is correct |
3 |
Correct |
1225 ms |
8336 KB |
Output is correct |
4 |
Correct |
1222 ms |
8380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
4476 KB |
Output is correct |
2 |
Correct |
16 ms |
4472 KB |
Output is correct |
3 |
Correct |
16 ms |
4472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
4476 KB |
Output is correct |
2 |
Correct |
16 ms |
4472 KB |
Output is correct |
3 |
Correct |
16 ms |
4472 KB |
Output is correct |
4 |
Correct |
19 ms |
4600 KB |
Output is correct |
5 |
Correct |
19 ms |
4600 KB |
Output is correct |
6 |
Correct |
19 ms |
4600 KB |
Output is correct |
7 |
Correct |
18 ms |
4600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
4344 KB |
Output is correct |
2 |
Correct |
15 ms |
4472 KB |
Output is correct |
3 |
Correct |
15 ms |
4344 KB |
Output is correct |
4 |
Correct |
15 ms |
4344 KB |
Output is correct |
5 |
Correct |
15 ms |
4344 KB |
Output is correct |
6 |
Correct |
26 ms |
4728 KB |
Output is correct |
7 |
Correct |
26 ms |
4728 KB |
Output is correct |
8 |
Correct |
26 ms |
4728 KB |
Output is correct |
9 |
Correct |
17 ms |
4476 KB |
Output is correct |
10 |
Correct |
16 ms |
4472 KB |
Output is correct |
11 |
Correct |
16 ms |
4472 KB |
Output is correct |
12 |
Correct |
26 ms |
4728 KB |
Output is correct |
13 |
Correct |
26 ms |
4728 KB |
Output is correct |
14 |
Correct |
27 ms |
4808 KB |
Output is correct |
15 |
Correct |
27 ms |
4804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
4344 KB |
Output is correct |
2 |
Correct |
15 ms |
4472 KB |
Output is correct |
3 |
Correct |
15 ms |
4344 KB |
Output is correct |
4 |
Correct |
15 ms |
4344 KB |
Output is correct |
5 |
Correct |
15 ms |
4344 KB |
Output is correct |
6 |
Correct |
26 ms |
4728 KB |
Output is correct |
7 |
Correct |
26 ms |
4728 KB |
Output is correct |
8 |
Correct |
26 ms |
4728 KB |
Output is correct |
9 |
Correct |
17 ms |
4476 KB |
Output is correct |
10 |
Correct |
16 ms |
4472 KB |
Output is correct |
11 |
Correct |
16 ms |
4472 KB |
Output is correct |
12 |
Correct |
19 ms |
4600 KB |
Output is correct |
13 |
Correct |
19 ms |
4600 KB |
Output is correct |
14 |
Correct |
19 ms |
4600 KB |
Output is correct |
15 |
Correct |
18 ms |
4600 KB |
Output is correct |
16 |
Correct |
26 ms |
4728 KB |
Output is correct |
17 |
Correct |
26 ms |
4728 KB |
Output is correct |
18 |
Correct |
27 ms |
4808 KB |
Output is correct |
19 |
Correct |
27 ms |
4804 KB |
Output is correct |
20 |
Correct |
462 ms |
8340 KB |
Output is correct |
21 |
Correct |
376 ms |
8312 KB |
Output is correct |
22 |
Correct |
369 ms |
8308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
4344 KB |
Output is correct |
2 |
Correct |
15 ms |
4472 KB |
Output is correct |
3 |
Correct |
15 ms |
4344 KB |
Output is correct |
4 |
Correct |
15 ms |
4344 KB |
Output is correct |
5 |
Correct |
15 ms |
4344 KB |
Output is correct |
6 |
Correct |
26 ms |
4728 KB |
Output is correct |
7 |
Correct |
26 ms |
4728 KB |
Output is correct |
8 |
Correct |
26 ms |
4728 KB |
Output is correct |
9 |
Correct |
68 ms |
6736 KB |
Output is correct |
10 |
Correct |
29 ms |
4984 KB |
Output is correct |
11 |
Correct |
26 ms |
4728 KB |
Output is correct |
12 |
Correct |
25 ms |
4728 KB |
Output is correct |
13 |
Correct |
1226 ms |
8340 KB |
Output is correct |
14 |
Correct |
1236 ms |
8184 KB |
Output is correct |
15 |
Correct |
1225 ms |
8336 KB |
Output is correct |
16 |
Correct |
1222 ms |
8380 KB |
Output is correct |
17 |
Correct |
17 ms |
4476 KB |
Output is correct |
18 |
Correct |
16 ms |
4472 KB |
Output is correct |
19 |
Correct |
16 ms |
4472 KB |
Output is correct |
20 |
Correct |
19 ms |
4600 KB |
Output is correct |
21 |
Correct |
19 ms |
4600 KB |
Output is correct |
22 |
Correct |
19 ms |
4600 KB |
Output is correct |
23 |
Correct |
18 ms |
4600 KB |
Output is correct |
24 |
Correct |
26 ms |
4728 KB |
Output is correct |
25 |
Correct |
26 ms |
4728 KB |
Output is correct |
26 |
Correct |
27 ms |
4808 KB |
Output is correct |
27 |
Correct |
27 ms |
4804 KB |
Output is correct |
28 |
Correct |
462 ms |
8340 KB |
Output is correct |
29 |
Correct |
376 ms |
8312 KB |
Output is correct |
30 |
Correct |
369 ms |
8308 KB |
Output is correct |
31 |
Correct |
1352 ms |
10356 KB |
Output is correct |
32 |
Correct |
1277 ms |
10272 KB |
Output is correct |
33 |
Correct |
1273 ms |
10280 KB |
Output is correct |
34 |
Correct |
1308 ms |
10272 KB |
Output is correct |
35 |
Correct |
1331 ms |
10284 KB |
Output is correct |
36 |
Correct |
1309 ms |
10232 KB |
Output is correct |