답안 #564472

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
564472 2022-05-19T09:31:36 Z Stickfish Intergalactic ship (IZhO19_xorsum) C++17
62 / 100
2000 ms 3576 KB
#include <iostream>
#include <vector>
#include <bitset>
using namespace std;
using ll = long long;

const int MAXN = 1008;
const ll MOD = 1000000007;
const int MAXVAL = 128;
int a[MAXN];

void updt(bitset<MAXVAL>& bs, int t) {
    if (bs[bs._Find_first() ^ t])
        return;
    vector<int> it;
    for (int i = bs._Find_first(); i < MAXVAL; i = bs._Find_next(i)) {
        it.push_back(i ^ t);
    }
    for (auto i : it)
        bs[i] = 1;
}

ll pw(ll a, ll m) {
    if (!m)
        return 1;
    a %= MOD;
    if (m % 2)
        return a * pw(a, m - 1) % MOD;
    return pw(a * a, m / 2);
}

bool in(pair<int, int> sg, int i) {
    return sg.first <= i && i < sg.second;
}

vector<pair<int, int>> events[MAXN];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int q;
    cin >> q;
    for (int i = 0; i < q; ++i) {
        int l, r, x;
        cin >> l >> r >> x;
        --l;
        events[l].push_back({r, x});
        events[r].push_back({l, x});
    }
    ll ans = 0;
    vector<int> genij0(MAXVAL, 0);
    bitset<MAXVAL> genbsij0;
    for (int i = 0; i < n; ++i) {
        for (auto [e, x] : events[i]) {
            if (e < i)
                genbsij0[x] = --genij0[x];
            else
                genbsij0[x] = ++genij0[x];
        }
        vector<int> geni(MAXVAL);
        bitset<MAXVAL> genbsi;
        vector<int> genj(MAXVAL);
        bitset<MAXVAL> genbsj;
        vector<int> genij = genij0;
        bitset<MAXVAL> genbsij = genbsij0;

        for (int j = i; j < n; ++j) {
            if (j > i) {
                for (auto [e, x] : events[j]) {
                    if (e <= i) {
                        genbsij[x] = --genij[x];
                        genbsi[x] = ++geni[x];
                    } else if (e < j) {
                        genbsj[x] = --genj[x];
                    } else {
                        genbsj[x] = ++genj[x];
                    }
                }
            }
            bitset<MAXVAL> bsi;
            bitset<MAXVAL> bsj;
            bitset<MAXVAL> bsij;
            bsi[a[i]] = bsj[a[j]] = bsij[0] = 1;
            //cout << "---" << i << ' ' << j << "---\n";
            for (int xi = genbsi._Find_first(); xi < MAXVAL; xi = genbsi._Find_next(xi)) {
                //cout << xi << ' ';
                updt(bsi, xi);
            }
            //cout << endl;
            for (int xj = genbsj._Find_first(); xj < MAXVAL; xj = genbsj._Find_next(xj)) {
                //cout << xj << ' ';
                updt(bsj, xj);
            }
            //cout << endl;
            for (int xij = genbsij._Find_first(); xij < MAXVAL; xij = genbsij._Find_next(xij)) {
                //cout << xij << ' ';
                updt(bsij, xij);
            }
            //cout << endl;
            ll addans = 0;
            vector<int> xj_from_xij(MAXVAL);
            for (int xij = bsij._Find_first(); xij < MAXVAL; xij = bsij._Find_next(xij)) {
                for (int xj = bsj._Find_first(); xj < MAXVAL; xj = bsj._Find_next(xj)) {
                    xj_from_xij[xij] += xj ^ xij;
                    xj_from_xij[xij] %= MOD;
                }
            }
            if (i != j) {
                for (int xij = bsij._Find_first(); xij < MAXVAL; xij = bsij._Find_next(xij)) {
                    xj_from_xij[xij] *= 2;
                    xj_from_xij[xij] %= MOD;
                }
            }
            for (int xi = bsi._Find_first(); xi < MAXVAL; xi = bsi._Find_next(xi)) {
                for (int xij = bsij._Find_first(); xij < MAXVAL; xij = bsij._Find_next(xij)) {
                    addans += 1ll * xj_from_xij[xij] * (xi ^ xij);
                    addans %= MOD;
                }
            }
            addans *= (i + 1) * (n - j);
            addans %= MOD;
            addans *= pw(2, q);
            addans %= MOD;
            //cout << bsi.count() << ' ' << bsj.count() << ' ' << bsij.count() << endl;
            addans *= pw(bsi.count() * bsj.count() * bsij.count(), MOD - 2);
            ans += addans;
            ans %= MOD;
            //cout << i << ' ' << j << ": " << ans - ans0 << endl;
        }
    }
    cout << ans << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 6 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 106 ms 2472 KB Output is correct
2 Correct 33 ms 604 KB Output is correct
3 Correct 10 ms 340 KB Output is correct
4 Correct 3 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 259 ms 344 KB Output is correct
2 Correct 250 ms 348 KB Output is correct
3 Correct 214 ms 340 KB Output is correct
4 Correct 224 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 3 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 10 ms 516 KB Output is correct
5 Correct 10 ms 468 KB Output is correct
6 Correct 10 ms 468 KB Output is correct
7 Correct 9 ms 468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 6 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 832 ms 348 KB Output is correct
13 Correct 888 ms 348 KB Output is correct
14 Correct 35 ms 340 KB Output is correct
15 Correct 246 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 6 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 3 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 10 ms 516 KB Output is correct
13 Correct 10 ms 468 KB Output is correct
14 Correct 10 ms 468 KB Output is correct
15 Correct 9 ms 468 KB Output is correct
16 Correct 832 ms 348 KB Output is correct
17 Correct 888 ms 348 KB Output is correct
18 Correct 35 ms 340 KB Output is correct
19 Correct 246 ms 460 KB Output is correct
20 Execution timed out 2073 ms 3576 KB Time limit exceeded
21 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 6 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 3 ms 340 KB Output is correct
9 Correct 106 ms 2472 KB Output is correct
10 Correct 33 ms 604 KB Output is correct
11 Correct 10 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 259 ms 344 KB Output is correct
14 Correct 250 ms 348 KB Output is correct
15 Correct 214 ms 340 KB Output is correct
16 Correct 224 ms 340 KB Output is correct
17 Correct 2 ms 340 KB Output is correct
18 Correct 3 ms 340 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 10 ms 516 KB Output is correct
21 Correct 10 ms 468 KB Output is correct
22 Correct 10 ms 468 KB Output is correct
23 Correct 9 ms 468 KB Output is correct
24 Correct 832 ms 348 KB Output is correct
25 Correct 888 ms 348 KB Output is correct
26 Correct 35 ms 340 KB Output is correct
27 Correct 246 ms 460 KB Output is correct
28 Execution timed out 2073 ms 3576 KB Time limit exceeded
29 Halted 0 ms 0 KB -