Submission #331940

# Submission time Handle Problem Language Result Execution time Memory
331940 2020-11-30T18:49:35 Z keko37 Intergalactic ship (IZhO19_xorsum) C++14
100 / 100
219 ms 5100 KB
#include<bits/stdc++.h>

using namespace std;

typedef long long llint;

const int MAXN = 1005;
const int MAXQ = 200005;
const int MOD = 1000000007;

int n, q, ans;
llint sol[MAXQ];
int w[MAXN], lef[MAXQ], rig[MAXQ], val[MAXQ];
int cnt[MAXN][7], del[7][MAXN][7];
vector <int> v[MAXN], r[MAXN];

void precompute () {
    int br[7];
    memset(br, 0, sizeof br);
    for (int i = 0; i < n; i++) {
        for (auto q : v[i]) {
            for (int j = 0; j < 7; j++) {
                if (val[q] & (1 << j)) br[j]++;
            }
        }
        for (int j = 0; j < 7; j++) cnt[i][j] = br[j];
        for (auto q : r[i]) {
            for (int j = 0; j < 7; j++) {
                if (val[q] & (1 << j)) br[j]--;
            }
        }
    }
}

void upd (int q, int k) {
    for (int i = 0; i < 7; i++) {
        if (!(val[q] & (1 << i))) continue;
        for (int j = 0; j < 7; j++) {
            if (val[q] & (1 << j)) del[i][lef[q]][j] += k;
        }
    }
}

void sweep () {
    int br[7][7];
    for (int i = 0; i < n; i++) {
        for (auto q : v[i]) upd(q, +1);
        bool bta, btb;
        memset(br, 0, sizeof br);
        for (int a = 0; a < 7; a++) {
            bta = w[i] & (1 << a);
            for (int j = 0; j <= i; j++) {
                int d = (j + 1) * (n - i);
                if (j < i) d *= 2;
                for (int b = 0; b < 7; b++) {
                    br[a][b] += del[a][j][b];
                    btb = w[j] & (1 << b);

                    int samo_a = cnt[i][a] - br[a][b];
                    int samo_b = cnt[j][b] - br[a][b];
                    //cout << "bla " << i << " " << a << "    " << j << " " << b << "     " << samo_a << " " << samo_b << " " << br[a][b] << endl;
                    if (samo_a > 0 && samo_b > 0) {
                        sol[a + b + q - 2] += d;
                    } else if (samo_a == 0 && samo_b == 0) {
                        if (bta == btb) {
                            if (br[a][b] > 0) sol[a + b + q - 1] += d; else if (bta == 1) sol[a + b + q] += d;
                        }
                    } else if (samo_a == 0) {
                        if (br[a][b] > 0) sol[a + b + q - 2] += d; else if (bta == 1) sol[a + b + q - 1] += d;
                    } else {
                        if (br[a][b] > 0) sol[a + b + q - 2] += d; else if (btb == 1) sol[a + b + q - 1] += d;
                    }
                }
            }
        }
        for (auto q : r[i]) upd(q, -1);
    }
}

int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> w[i];
    }
    cin >> q;
    for (int i = 0; i < q; i++) {
        cin >> lef[i] >> rig[i] >> val[i];
        lef[i]--; rig[i]--;
        v[lef[i]].push_back(i);
        r[rig[i]].push_back(i);
    }
    precompute();
    sweep();
    int pot = 1;
    for (int i = 0; i < q + 20; i++) {
        sol[i] %= MOD;
        ans = (ans + (llint) pot * sol[i]) % MOD;
        pot = pot * 2 % MOD;
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory 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
# Verdict Execution time Memory 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 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 48 ms 3564 KB Output is correct
2 Correct 9 ms 876 KB Output is correct
3 Correct 2 ms 492 KB Output is correct
4 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 219 ms 620 KB Output is correct
2 Correct 202 ms 620 KB Output is correct
3 Correct 172 ms 620 KB Output is correct
4 Correct 164 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 3 ms 620 KB Output is correct
5 Correct 3 ms 620 KB Output is correct
6 Correct 3 ms 620 KB Output is correct
7 Correct 3 ms 620 KB Output is correct
# Verdict Execution time Memory 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 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 1 ms 492 KB Output is correct
14 Correct 2 ms 492 KB Output is correct
15 Correct 3 ms 492 KB Output is correct
# Verdict Execution time Memory 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 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 1 ms 492 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 1 ms 492 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 3 ms 620 KB Output is correct
15 Correct 3 ms 620 KB Output is correct
16 Correct 2 ms 492 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 2 ms 492 KB Output is correct
19 Correct 3 ms 492 KB Output is correct
20 Correct 79 ms 4972 KB Output is correct
21 Correct 106 ms 4716 KB Output is correct
22 Correct 63 ms 4844 KB Output is correct
# Verdict Execution time Memory 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 2 ms 492 KB Output is correct
7 Correct 2 ms 492 KB Output is correct
8 Correct 2 ms 364 KB Output is correct
9 Correct 48 ms 3564 KB Output is correct
10 Correct 9 ms 876 KB Output is correct
11 Correct 2 ms 492 KB Output is correct
12 Correct 2 ms 492 KB Output is correct
13 Correct 219 ms 620 KB Output is correct
14 Correct 202 ms 620 KB Output is correct
15 Correct 172 ms 620 KB Output is correct
16 Correct 164 ms 748 KB Output is correct
17 Correct 1 ms 492 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 1 ms 492 KB Output is correct
20 Correct 3 ms 620 KB Output is correct
21 Correct 3 ms 620 KB Output is correct
22 Correct 3 ms 620 KB Output is correct
23 Correct 3 ms 620 KB Output is correct
24 Correct 2 ms 492 KB Output is correct
25 Correct 1 ms 492 KB Output is correct
26 Correct 2 ms 492 KB Output is correct
27 Correct 3 ms 492 KB Output is correct
28 Correct 79 ms 4972 KB Output is correct
29 Correct 106 ms 4716 KB Output is correct
30 Correct 63 ms 4844 KB Output is correct
31 Correct 158 ms 5100 KB Output is correct
32 Correct 155 ms 4948 KB Output is correct
33 Correct 104 ms 4972 KB Output is correct
34 Correct 121 ms 4324 KB Output is correct
35 Correct 118 ms 4324 KB Output is correct
36 Correct 134 ms 4284 KB Output is correct