답안 #342357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
342357 2021-01-01T23:42:52 Z kekw Intergalactic ship (IZhO19_xorsum) C++17
100 / 100
852 ms 13932 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define range(i, n) for (int i = 0; i < (n); ++i)
#define ar array
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()


typedef long long ll;
typedef long double ld;
using namespace std;

//using namespace __gnu_pbds;

const ll INF = 1e18 + 5;
const int INFi = 1e9;
const int maxN = 1e5 + 1500;
const int md2 = 998244353;
const int md = 1e9 + 7;


int add(int a, int b) {
    if (a + b >= md) return a + b - md;
    return a + b;
}

int sub(int a, int b) {
    if (a - b < 0) return a - b + md;
    return a - b;
}

int mul(int a, int b) {
    return (1ll * a * b) % md;
}

int st2[100001];
int a[1000];
int b[100000][3];

int Cnt[3][1005][1005];

void solve() {
    int n;
    cin >> n;
    range(i, n) cin >> a[i];
    int q;
    cin >> q;
    st2[0] = 1;
    for (int i = 1; i <= q; ++i) st2[i] = mul(st2[i - 1], 2);
    range(i, q) range(j, 3) cin >> b[i][j];
    int ans = 0;
    range(b1, 8) {
        range(b2, 8) {
            int result = 0;
            range(i, n) range(e, 3) memset(Cnt[e][i], 0, sizeof(Cnt[e][i]));
            auto ADD = [&](int x1, int y1, int x2, int y2, int m) {
                Cnt[m][x1][y1] += 1;
                Cnt[m][x2 + 1][y2 + 1] += 1;
                Cnt[m][x1][y2 + 1] -= 1;
                Cnt[m][x2 + 1][y1] -= 1;
            };
            range(i, q) {
                int l = b[i][0];
                int r = b[i][1];
                int x = b[i][2];
                if ((x & (1 << b1)) && (x & (1 << b2))) {
                    ADD(l - 1, l - 1, r - 1, r - 1, 0);
                    ADD(l - 1, r, r - 1, n, 1);
                    if (l != 1) ADD(0, l - 1, l - 2, r - 1, 2);
                } else if (x & (1 << b1)) {
                    ADD(l - 1, 0, r - 1, n, 1);
                } else if (x & (1 << b2)) {
                    ADD(0, l - 1, n, r - 1, 2);
                }
            }
            range(i, n) {
                range(j, n) {
                    range(e, 3) {
                        if (i) Cnt[e][i][j] += Cnt[e][i - 1][j];
                        if (j) Cnt[e][i][j] += Cnt[e][i][j - 1];
                        if (i && j) Cnt[e][i][j] -= Cnt[e][i - 1][j - 1];
                    }
                }
            }
            range(i, n) {
                for (int j = i; j < n; ++j) {
                    int cur = 0;
                    if (Cnt[1][i][j] && Cnt[2][i][j]) {
                        cur = st2[q - 2];
                    } else if (Cnt[1][i][j] && Cnt[0][i][j]) {
                        cur = st2[q - 2];
                    } else if (Cnt[2][i][j] && Cnt[0][i][j]) {
                        cur = st2[q - 2];
                    } else if (Cnt[1][i][j]) {
                        if (a[j] & (1 << b2)) {
                            cur = st2[q - 1];
                        }
                    } else if (Cnt[2][i][j]) {
                        if (a[i] & (1 << b1)) {
                            cur = st2[q - 1];
                        }
                    } else if (Cnt[0][i][j]) {
                        int A = (a[i] >> b1) & 1;
                        int B = (a[j] >> b2) & 1;
                        if (A == B) {
                            cur = st2[q - 1];
                        }
                    } else if (((a[i] >> b1) & 1) && ((a[j] >> b2) & 1)) {
                        cur = st2[q];
                    }
                    result = add(result, mul(1 + (i != j), mul(cur, mul(i + 1, n - j))));
                }
            }
            ans = add(ans, mul(result, 1 << (b1 + b2)));
        }
    }
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    // cout << setprecision(15) << fixed;
    int tests = 1;
    //cin >> tests;
    range(_, tests) {
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 10 ms 1516 KB Output is correct
7 Correct 12 ms 1516 KB Output is correct
8 Correct 12 ms 1644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 85 ms 3180 KB Output is correct
2 Correct 17 ms 1772 KB Output is correct
3 Correct 11 ms 1516 KB Output is correct
4 Correct 10 ms 1516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 683 ms 12268 KB Output is correct
2 Correct 690 ms 12268 KB Output is correct
3 Correct 666 ms 12268 KB Output is correct
4 Correct 662 ms 12140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 6 ms 748 KB Output is correct
5 Correct 6 ms 748 KB Output is correct
6 Correct 6 ms 748 KB Output is correct
7 Correct 6 ms 748 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 10 ms 1516 KB Output is correct
7 Correct 12 ms 1516 KB Output is correct
8 Correct 12 ms 1644 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 11 ms 1516 KB Output is correct
13 Correct 11 ms 1516 KB Output is correct
14 Correct 13 ms 1516 KB Output is correct
15 Correct 10 ms 1516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 10 ms 1516 KB Output is correct
7 Correct 12 ms 1516 KB Output is correct
8 Correct 12 ms 1644 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 2 ms 748 KB Output is correct
12 Correct 6 ms 748 KB Output is correct
13 Correct 6 ms 748 KB Output is correct
14 Correct 6 ms 748 KB Output is correct
15 Correct 6 ms 748 KB Output is correct
16 Correct 11 ms 1516 KB Output is correct
17 Correct 11 ms 1516 KB Output is correct
18 Correct 13 ms 1516 KB Output is correct
19 Correct 10 ms 1516 KB Output is correct
20 Correct 311 ms 7948 KB Output is correct
21 Correct 291 ms 7916 KB Output is correct
22 Correct 229 ms 7788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 10 ms 1516 KB Output is correct
7 Correct 12 ms 1516 KB Output is correct
8 Correct 12 ms 1644 KB Output is correct
9 Correct 85 ms 3180 KB Output is correct
10 Correct 17 ms 1772 KB Output is correct
11 Correct 11 ms 1516 KB Output is correct
12 Correct 10 ms 1516 KB Output is correct
13 Correct 683 ms 12268 KB Output is correct
14 Correct 690 ms 12268 KB Output is correct
15 Correct 666 ms 12268 KB Output is correct
16 Correct 662 ms 12140 KB Output is correct
17 Correct 3 ms 748 KB Output is correct
18 Correct 2 ms 748 KB Output is correct
19 Correct 2 ms 748 KB Output is correct
20 Correct 6 ms 748 KB Output is correct
21 Correct 6 ms 748 KB Output is correct
22 Correct 6 ms 748 KB Output is correct
23 Correct 6 ms 748 KB Output is correct
24 Correct 11 ms 1516 KB Output is correct
25 Correct 11 ms 1516 KB Output is correct
26 Correct 13 ms 1516 KB Output is correct
27 Correct 10 ms 1516 KB Output is correct
28 Correct 311 ms 7948 KB Output is correct
29 Correct 291 ms 7916 KB Output is correct
30 Correct 229 ms 7788 KB Output is correct
31 Correct 852 ms 13932 KB Output is correct
32 Correct 805 ms 13804 KB Output is correct
33 Correct 734 ms 13804 KB Output is correct
34 Correct 742 ms 13804 KB Output is correct
35 Correct 740 ms 13804 KB Output is correct
36 Correct 743 ms 13676 KB Output is correct