Submission #564104

# Submission time Handle Problem Language Result Execution time Memory
564104 2022-05-18T14:54:11 Z Stickfish Intergalactic ship (IZhO19_xorsum) C++17
28 / 100
2000 ms 1460 KB
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;

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

vector<int> updt(vector<int>& cnts, int t) {
    vector<int> ans = cnts;
    for (int i = 0; i < 128; ++i) {
        ans[i ^ t] += cnts[i];
        if (ans[i ^ t] >= MOD)
            ans[i ^ t] -= MOD;
    }
    return ans;
}

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) {
        //vector<int> cnts(128);
        //cnts[a[i]] = 1;
        //for (auto [sg, x] : qrs) {
            //if (in(sg, i))
                //cnts = updt(cnts, x);
        //}
        //for (int x = 0; x < 128; ++x) {
            //ans += 1ll * (i + 1) * (n - i) * x * x % MOD * cnts[x];
            //ans %= MOD;
        //}
    //}
    for (int i = 0; i < n; ++i) {
        for (int j = i; j < n; ++j) {
            vector<int> cntsi(128);
            vector<int> cntsj(128);
            vector<int> cntsij(128);
            cntsi[a[i]] = cntsj[a[j]] = cntsij[0] = 1;
            for (auto [sg, x] : qrs) {
                bool ini = in(sg, i);
                bool inj = in(sg, j);
                if (ini && !inj) {
                    cntsi = updt(cntsi, x);
                } else if (!ini && inj)
                    cntsj = updt(cntsj, x);
                else if (ini && inj)
                    cntsij = updt(cntsij, x);
                else
                    cntsij = updt(cntsij, 0);
            }
            ll ans0 = ans;
            ll addans = 0;
            for (int xi = 0; xi < 128; ++xi) {
                if (cntsi[xi] == 0)
                    continue;
                for (int xj = 0; xj < 128; ++xj) {
                    if (cntsj[xj] == 0)
                        continue;
                    for (int xij = 0; xij < 128; ++xij) {
                        if (cntsij[xij] == 0)
                            continue;
                        if (i != j)
                            addans += 2ll * (xi ^ xij) * (xj ^ xij) * cntsi[xi] % MOD * cntsj[xj] % MOD * cntsij[xij];
                        else
                            addans += 1ll * (xi ^ xij) * (xj ^ xij) * cntsi[xi] % MOD * cntsj[xj] % MOD * cntsij[xij];
                        addans %= MOD;
                    }
                }
            }
            addans *= (i + 1) * (n - j);
            ans += addans;
            ans %= MOD;
            //cout << i << ' ' << j << ": " << ans - ans0 << endl;
        }
    }
    cout << ans << endl;
}

Compilation message

xorsum.cpp: In function 'int main()':
xorsum.cpp:67:16: warning: unused variable 'ans0' [-Wunused-variable]
   67 |             ll ans0 = ans;
      |                ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 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 0 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 30 ms 312 KB Output is correct
7 Correct 15 ms 304 KB Output is correct
8 Correct 16 ms 312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2077 ms 1460 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2088 ms 212 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 11 ms 212 KB Output is correct
2 Correct 9 ms 304 KB Output is correct
3 Correct 13 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 212 KB Output is correct
2 Correct 9 ms 304 KB Output is correct
3 Correct 13 ms 212 KB Output is correct
4 Correct 660 ms 380 KB Output is correct
5 Correct 653 ms 380 KB Output is correct
6 Correct 648 ms 340 KB Output is correct
7 Correct 652 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 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 30 ms 312 KB Output is correct
7 Correct 15 ms 304 KB Output is correct
8 Correct 16 ms 312 KB Output is correct
9 Correct 11 ms 212 KB Output is correct
10 Correct 9 ms 304 KB Output is correct
11 Correct 13 ms 212 KB Output is correct
12 Execution timed out 2025 ms 212 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 30 ms 312 KB Output is correct
7 Correct 15 ms 304 KB Output is correct
8 Correct 16 ms 312 KB Output is correct
9 Correct 11 ms 212 KB Output is correct
10 Correct 9 ms 304 KB Output is correct
11 Correct 13 ms 212 KB Output is correct
12 Correct 660 ms 380 KB Output is correct
13 Correct 653 ms 380 KB Output is correct
14 Correct 648 ms 340 KB Output is correct
15 Correct 652 ms 376 KB Output is correct
16 Execution timed out 2025 ms 212 KB Time limit exceeded
17 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 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 30 ms 312 KB Output is correct
7 Correct 15 ms 304 KB Output is correct
8 Correct 16 ms 312 KB Output is correct
9 Execution timed out 2077 ms 1460 KB Time limit exceeded
10 Halted 0 ms 0 KB -