Submission #531786

# Submission time Handle Problem Language Result Execution time Memory
531786 2022-03-01T13:44:58 Z abc864197532 Intergalactic ship (IZhO19_xorsum) C++17
100 / 100
1397 ms 194040 KB
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define X first
#define Y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
void abc() {cout << endl;}
template <typename T, typename ...U> void abc(T a, U ...b) {
    cout << a << ' ', abc(b...);
}
template <typename T> void printv(T l, T r) {
    for (; l != r; ++l) cout << *l << " \n"[l + 1 == r];
}
template <typename A, typename B> istream& operator >> (istream& o, pair<A, B> &a) {
    return o >> a.X >> a.Y;
}
template <typename A, typename B> ostream& operator << (ostream& o, pair<A, B> a) {
    return o << '(' << a.X << ", " << a.Y << ')';
}
template <typename T> ostream& operator << (ostream& o, vector<T> a) {
    bool is = false;
    if (a.empty()) return o << "{}";
    for (T i : a) {o << (is ? ' ' : '{'), is = true, o << i;}
    return o << '}';
}
template <typename T> struct vv : vector <vector <T>> {
    vv(int n, int m, T v) : vector <vector <T>> (n, vector <T>(m, v)) {}
    vv() {}
};
template <typename T> struct vvv : vector <vv <T>> {
    vvv(int n, int m, int k, T v) : vector <vv <T>> (n, vv <T>(m, k, v)) {}
    vvv() {}
};
#ifdef Doludu
#define test(args...) abc("[" + string(#args) + "]", args)
#define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout); 
#else
#define test(args...) void(0)
#define owo ios::sync_with_stdio(false); cin.tie(0)
#endif
const int mod = 1e9 + 7, N = 1001, logN = 20, K = 111, C = 7;

void trans (vector <lli> &dp, int x) {
    vector <lli> pre = dp;
    for (int i = 0; i < C; ++i) {
        dp[i ^ x] += pre[i];
        if (dp[i ^ x] >= mod)
            dp[i ^ x] -= mod;
    }
}

int pre[N][N][C][C], pw[N << 7];

int main () {
    owo;
    pw[0] = 1;
    for (int i = 1; i < N << 7; ++i) {
        pw[i] = pw[i - 1] + pw[i - 1];
        if (pw[i] >= mod)
            pw[i] -= mod;
    }
    int n, q;
    cin >> n;
    vector <int> a(n);
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    cin >> q;
    for (int i = 0, l, r, x; i < q; ++i) {
        cin >> l >> r >> x, --l;
        // pre[l ~ r][l ~ r]++
        for (int ii = 0; ii < C; ++ii) if (x >> ii & 1)
            for (int jj = 0; jj < C; ++jj) if (x >> jj & 1)
                pre[l][l][ii][jj]++, pre[l][r][ii][jj]--, pre[r][l][ii][jj]--, pre[r][r][ii][jj]++;
    }
    for (int i = 0; i <= n; ++i) for (int j = 0; j <= n; ++j) for (int ii = 0; ii < C; ++ii) for (int jj = 0; jj < C; ++jj) {
        if (i && j)
            pre[i][j][ii][jj] -= pre[i - 1][j - 1][ii][jj];
        if (i)
            pre[i][j][ii][jj] += pre[i - 1][j][ii][jj];
        if (j)
            pre[i][j][ii][jj] += pre[i][j - 1][ii][jj];
    }
    lli ans = 0;
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) {
        for (int ii = 0; ii < C; ++ii) for (int jj = 0; jj < C; ++jj) {
            int cnt11 = pre[i][j][ii][jj], cnt10 = pre[i][i][ii][ii] - cnt11, cnt01 = pre[j][j][jj][jj] - cnt11, cnt00 = q - cnt01 - cnt10 - cnt11;
            int curi[2], curj[2];
            if (cnt10)
                curi[0] = curi[1] = pw[cnt10 - 1];
            else
                curi[0] = 1, curi[1] = 0;
            if (cnt01)
                curj[0] = curj[1] = pw[cnt01 - 1];
            else
                curj[0] = 1, curj[1] = 0;
            int bi = a[i] >> ii & 1, bj = a[j] >> jj & 1, now = 0;
            if (cnt11) {
                now = (1ll * curi[bi] * curj[bj] + 1ll * curi[bi ^ 1] * curj[bj ^ 1]) % mod * pw[cnt11 - 1] % mod;
            } else {
                now = 1ll * curi[bi ^ 1] * curj[bj ^ 1] % mod;
            }
            (ans += 1ll * now % mod * pw[ii + jj] % mod * (min(i, j) + 1) % mod * (n - max(i, j)) % mod * pw[cnt00]) %= mod;
        }
    }
    cout << ans << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 828 KB Output is correct
2 Correct 1 ms 832 KB Output is correct
3 Correct 1 ms 844 KB Output is correct
4 Correct 1 ms 844 KB Output is correct
5 Correct 2 ms 828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 828 KB Output is correct
2 Correct 1 ms 832 KB Output is correct
3 Correct 1 ms 844 KB Output is correct
4 Correct 1 ms 844 KB Output is correct
5 Correct 2 ms 828 KB Output is correct
6 Correct 17 ms 3148 KB Output is correct
7 Correct 12 ms 3216 KB Output is correct
8 Correct 12 ms 3216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 3960 KB Output is correct
2 Correct 15 ms 3276 KB Output is correct
3 Correct 14 ms 3220 KB Output is correct
4 Correct 13 ms 3212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1125 ms 192976 KB Output is correct
2 Correct 1065 ms 192972 KB Output is correct
3 Correct 1077 ms 192988 KB Output is correct
4 Correct 1064 ms 192972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1100 KB Output is correct
2 Correct 3 ms 1100 KB Output is correct
3 Correct 2 ms 1080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1100 KB Output is correct
2 Correct 3 ms 1100 KB Output is correct
3 Correct 2 ms 1080 KB Output is correct
4 Correct 4 ms 1100 KB Output is correct
5 Correct 4 ms 1100 KB Output is correct
6 Correct 4 ms 1180 KB Output is correct
7 Correct 4 ms 1100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 828 KB Output is correct
2 Correct 1 ms 832 KB Output is correct
3 Correct 1 ms 844 KB Output is correct
4 Correct 1 ms 844 KB Output is correct
5 Correct 2 ms 828 KB Output is correct
6 Correct 17 ms 3148 KB Output is correct
7 Correct 12 ms 3216 KB Output is correct
8 Correct 12 ms 3216 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 3 ms 1100 KB Output is correct
11 Correct 2 ms 1080 KB Output is correct
12 Correct 15 ms 3204 KB Output is correct
13 Correct 14 ms 3148 KB Output is correct
14 Correct 14 ms 3276 KB Output is correct
15 Correct 16 ms 3220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 828 KB Output is correct
2 Correct 1 ms 832 KB Output is correct
3 Correct 1 ms 844 KB Output is correct
4 Correct 1 ms 844 KB Output is correct
5 Correct 2 ms 828 KB Output is correct
6 Correct 17 ms 3148 KB Output is correct
7 Correct 12 ms 3216 KB Output is correct
8 Correct 12 ms 3216 KB Output is correct
9 Correct 2 ms 1100 KB Output is correct
10 Correct 3 ms 1100 KB Output is correct
11 Correct 2 ms 1080 KB Output is correct
12 Correct 4 ms 1100 KB Output is correct
13 Correct 4 ms 1100 KB Output is correct
14 Correct 4 ms 1180 KB Output is correct
15 Correct 4 ms 1100 KB Output is correct
16 Correct 15 ms 3204 KB Output is correct
17 Correct 14 ms 3148 KB Output is correct
18 Correct 14 ms 3276 KB Output is correct
19 Correct 16 ms 3220 KB Output is correct
20 Correct 329 ms 52072 KB Output is correct
21 Correct 314 ms 52108 KB Output is correct
22 Correct 322 ms 51992 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 828 KB Output is correct
2 Correct 1 ms 832 KB Output is correct
3 Correct 1 ms 844 KB Output is correct
4 Correct 1 ms 844 KB Output is correct
5 Correct 2 ms 828 KB Output is correct
6 Correct 17 ms 3148 KB Output is correct
7 Correct 12 ms 3216 KB Output is correct
8 Correct 12 ms 3216 KB Output is correct
9 Correct 33 ms 3960 KB Output is correct
10 Correct 15 ms 3276 KB Output is correct
11 Correct 14 ms 3220 KB Output is correct
12 Correct 13 ms 3212 KB Output is correct
13 Correct 1125 ms 192976 KB Output is correct
14 Correct 1065 ms 192972 KB Output is correct
15 Correct 1077 ms 192988 KB Output is correct
16 Correct 1064 ms 192972 KB Output is correct
17 Correct 2 ms 1100 KB Output is correct
18 Correct 3 ms 1100 KB Output is correct
19 Correct 2 ms 1080 KB Output is correct
20 Correct 4 ms 1100 KB Output is correct
21 Correct 4 ms 1100 KB Output is correct
22 Correct 4 ms 1180 KB Output is correct
23 Correct 4 ms 1100 KB Output is correct
24 Correct 15 ms 3204 KB Output is correct
25 Correct 14 ms 3148 KB Output is correct
26 Correct 14 ms 3276 KB Output is correct
27 Correct 16 ms 3220 KB Output is correct
28 Correct 329 ms 52072 KB Output is correct
29 Correct 314 ms 52108 KB Output is correct
30 Correct 322 ms 51992 KB Output is correct
31 Correct 1327 ms 194040 KB Output is correct
32 Correct 1157 ms 194040 KB Output is correct
33 Correct 1397 ms 193948 KB Output is correct
34 Correct 1219 ms 193880 KB Output is correct
35 Correct 1304 ms 193848 KB Output is correct
36 Correct 1313 ms 193828 KB Output is correct