Submission #564451

# Submission time Handle Problem Language Result Execution time Memory
564451 2022-05-19T08:58:33 Z Stickfish Intergalactic ship (IZhO19_xorsum) C++17
37 / 100
2000 ms 2224 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;
}

signed main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    int q;
    cin >> q;
    vector<pair<pair<int, int>, int>> qrs(q);
    for (int i = 0; i < q; ++i) {
        cin >> qrs[i].first.first >> qrs[i].first.second >> qrs[i].second;
        --qrs[i].first.first;
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            bitset<MAXVAL> bsi;
            bitset<MAXVAL> bsj;
            bitset<MAXVAL> bsij;
            bsi[a[i]] = bsj[a[j]] = bsij[0] = 1;
            for (auto [sg, x] : qrs) {
                bool ini = in(sg, i);
                bool inj = in(sg, j);
                if (ini && !inj) {
                    updt(bsi, x);
                } else if (!ini && inj)
                    updt(bsj, x);
                else if (ini && inj)
                    updt(bsij, x);
            }
            ll addans = 0;
            for (int xi = bsi._Find_first(); xi < MAXVAL; xi = bsi._Find_next(xi)) {
                for (int xj = bsj._Find_first(); xj < MAXVAL; xj = bsj._Find_next(xj)) {
                    for (int xij = bsij._Find_first(); xij < MAXVAL; xij = bsij._Find_next(xij)) {
                        if (i != j)
                            addans += 2ll * (xi ^ xij) * (xj ^ xij);
                        else
                            addans += 1ll * (xi ^ xij) * (xj ^ 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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 6 ms 212 KB Output is correct
7 Correct 3 ms 212 KB Output is correct
8 Correct 4 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2066 ms 2224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 611 ms 296 KB Output is correct
2 Correct 532 ms 308 KB Output is correct
3 Correct 283 ms 288 KB Output is correct
4 Correct 203 ms 288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 212 KB Output is correct
2 Correct 3 ms 212 KB Output is correct
3 Correct 4 ms 212 KB Output is correct
4 Correct 121 ms 340 KB Output is correct
5 Correct 126 ms 380 KB Output is correct
6 Correct 124 ms 376 KB Output is correct
7 Correct 121 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 6 ms 212 KB Output is correct
7 Correct 3 ms 212 KB Output is correct
8 Correct 4 ms 212 KB Output is correct
9 Correct 5 ms 212 KB Output is correct
10 Correct 3 ms 212 KB Output is correct
11 Correct 4 ms 212 KB Output is correct
12 Execution timed out 2091 ms 212 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 6 ms 212 KB Output is correct
7 Correct 3 ms 212 KB Output is correct
8 Correct 4 ms 212 KB Output is correct
9 Correct 5 ms 212 KB Output is correct
10 Correct 3 ms 212 KB Output is correct
11 Correct 4 ms 212 KB Output is correct
12 Correct 121 ms 340 KB Output is correct
13 Correct 126 ms 380 KB Output is correct
14 Correct 124 ms 376 KB Output is correct
15 Correct 121 ms 380 KB Output is correct
16 Execution timed out 2091 ms 212 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 6 ms 212 KB Output is correct
7 Correct 3 ms 212 KB Output is correct
8 Correct 4 ms 212 KB Output is correct
9 Execution timed out 2066 ms 2224 KB Time limit exceeded
10 Halted 0 ms 0 KB -