Submission #146180

# Submission time Handle Problem Language Result Execution time Memory
146180 2019-08-22T17:14:19 Z imeimi2000 Intergalactic ship (IZhO19_xorsum) C++17
100 / 100
982 ms 6996 KB
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
typedef long long llong;

const int mod = 1e9 + 7;

int n, q;
int A[1001];
struct _qs {
    int l, r, x;
    void scan() {
        cin >> l >> r >> x;
    }
} qs[100000];

int P2[100001];
int cnt[1001][1001];
int S[7][1002];
int solve(int a, int b) {
    for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= i; ++j) {
            cnt[j][i] = 0;
        }
    }
    for (int it = 0; it < q; ++it) {
        _qs i = qs[it];
        bool b1 = (i.x >> a) & 1, b2 = (i.x >> b) & 1;
        if (!b1 || !b2) continue;
        ++cnt[i.l][i.r];
    }
    for (int l = 1; l <= n; ++l) {
        for (int r = n - 1; l <= r; --r) {
            cnt[l][r] = (cnt[l][r] + cnt[l][r + 1]) % mod;
        }
    }
    for (int l = 2; l <= n; ++l) {
        for (int r = n; l <= r; --r) {
            cnt[l][r] = (cnt[l][r] + cnt[l - 1][r]) % mod;
        }
    }
    llong ret = 0;
    for (int l = 1; l <= n; ++l) {
        for (int r = 1; r <= n; ++r) {
            if (l > r) cnt[l][r] = cnt[r][l];
            llong C[2][2] = {};
            C[1][1] = cnt[l][r];
            C[1][0] = S[a][l] - C[1][1];
            C[0][1] = S[b][r] - C[1][1];
            C[0][0] = q - C[0][1] - C[1][0] - C[1][1];
            llong sum = 0;
            int x = (A[l] >> a) & 1; x ^= 1;
            int y = (A[r] >> b) & 1; y ^= 1;
            int v = q;
            for (int i = 0; i < 2; ++i) {
                for (int j = 0; j < 2; ++j) {
                    if (i == 0 && j == 0) continue;
                    if (C[i][j] > 0) --v;
                }
            }
            v = P2[v];
            for (int i = 0; i < 2; ++i) {
                int k = i ^ x;
                int j = k ^ y;
                if (C[1][0] < i) continue;
                if (C[0][1] < j) continue;
                if (C[1][1] < k) continue;
                sum += v;
            }
            v = (n - max(l, r) + 1) * min(l, r);
            ret += (sum << a + b) % mod * v;
            ret %= mod;
        }
    }
    if (a != b) ret = (ret << 1) % mod;
    return ret;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; ++i) {
        cin >> A[i];
    }
    cin >> q;
    P2[0] = 1;
    for (int i = 0; i < q; ++i) {
        qs[i].scan();
        P2[i + 1] = (P2[i] << 1) % mod;
        for (int j = 0; j < 7; ++j) {
            if ((qs[i].x >> j) & 1) {
                ++S[j][qs[i].l];
                --S[j][qs[i].r + 1];
            }
        }
    }
    for (int j = 0; j < 7; ++j) {
        for (int i = 1; i <= n; ++i) {
            S[j][i] += S[j][i - 1];
        }
    }
    llong ans = 0;
    for (int i = 0; i < 7; ++i) {
        for (int j = 0; j <= i; ++j) {
            ans += solve(j, i);
        }
    }
    printf("%lld\n", ans % mod);
    return 0;
}

Compilation message

xorsum.cpp: In function 'int solve(int, int)':
xorsum.cpp:73:30: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
             ret += (sum << a + b) % mod * v;
                            ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 9 ms 764 KB Output is correct
7 Correct 11 ms 760 KB Output is correct
8 Correct 11 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 46 ms 3064 KB Output is correct
2 Correct 12 ms 1016 KB Output is correct
3 Correct 8 ms 760 KB Output is correct
4 Correct 10 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 916 ms 4376 KB Output is correct
2 Correct 909 ms 4344 KB Output is correct
3 Correct 982 ms 4344 KB Output is correct
4 Correct 944 ms 4344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 504 KB Output is correct
3 Correct 3 ms 504 KB Output is correct
4 Correct 5 ms 632 KB Output is correct
5 Correct 5 ms 632 KB Output is correct
6 Correct 5 ms 632 KB Output is correct
7 Correct 5 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 9 ms 764 KB Output is correct
7 Correct 11 ms 760 KB Output is correct
8 Correct 11 ms 760 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 8 ms 760 KB Output is correct
13 Correct 8 ms 760 KB Output is correct
14 Correct 9 ms 760 KB Output is correct
15 Correct 9 ms 760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 9 ms 764 KB Output is correct
7 Correct 11 ms 760 KB Output is correct
8 Correct 11 ms 760 KB Output is correct
9 Correct 3 ms 504 KB Output is correct
10 Correct 3 ms 504 KB Output is correct
11 Correct 3 ms 504 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
14 Correct 5 ms 632 KB Output is correct
15 Correct 5 ms 632 KB Output is correct
16 Correct 8 ms 760 KB Output is correct
17 Correct 8 ms 760 KB Output is correct
18 Correct 9 ms 760 KB Output is correct
19 Correct 9 ms 760 KB Output is correct
20 Correct 197 ms 4984 KB Output is correct
21 Correct 202 ms 5112 KB Output is correct
22 Correct 191 ms 4856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 248 KB Output is correct
4 Correct 2 ms 504 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
6 Correct 9 ms 764 KB Output is correct
7 Correct 11 ms 760 KB Output is correct
8 Correct 11 ms 760 KB Output is correct
9 Correct 46 ms 3064 KB Output is correct
10 Correct 12 ms 1016 KB Output is correct
11 Correct 8 ms 760 KB Output is correct
12 Correct 10 ms 760 KB Output is correct
13 Correct 916 ms 4376 KB Output is correct
14 Correct 909 ms 4344 KB Output is correct
15 Correct 982 ms 4344 KB Output is correct
16 Correct 944 ms 4344 KB Output is correct
17 Correct 3 ms 504 KB Output is correct
18 Correct 3 ms 504 KB Output is correct
19 Correct 3 ms 504 KB Output is correct
20 Correct 5 ms 632 KB Output is correct
21 Correct 5 ms 632 KB Output is correct
22 Correct 5 ms 632 KB Output is correct
23 Correct 5 ms 632 KB Output is correct
24 Correct 8 ms 760 KB Output is correct
25 Correct 8 ms 760 KB Output is correct
26 Correct 9 ms 760 KB Output is correct
27 Correct 9 ms 760 KB Output is correct
28 Correct 197 ms 4984 KB Output is correct
29 Correct 202 ms 5112 KB Output is correct
30 Correct 191 ms 4856 KB Output is correct
31 Correct 694 ms 6996 KB Output is correct
32 Correct 718 ms 6904 KB Output is correct
33 Correct 725 ms 6908 KB Output is correct
34 Correct 825 ms 6904 KB Output is correct
35 Correct 778 ms 6776 KB Output is correct
36 Correct 756 ms 6776 KB Output is correct