This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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;
}
# | 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... |