답안 #681594

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
681594 2023-01-13T12:23:46 Z grandmast3r Intergalactic ship (IZhO19_xorsum) C++17
36 / 100
2000 ms 6608 KB
#include <bits/stdc++.h>
 
#define ll long long
#define ld long double
#define vi vector<int>
#define pii pair<int, int>
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
 
using namespace std;
 
const int MOD = 1e9 + 7;
 
int add(int a, int b){
    a += b;
    if (a >= MOD){
        a -= MOD;
    }
    return a;
}
 
int sub(int a, int b){
    a -= b;
    if (a < 0){
        a += MOD;
    }
    return a;
}
 
int mul(int a, int b){
    return (a * 1ll * b) % MOD;
}
 
int naive(vector<int> a, vector<vector<int>> req){
    int n = a.size() - 1;
    int q = req.size();
    int res = 0;
    for (int i = 1; i <= n; i++){
        for (int j = i; j <= n; j++){
            vector<vector<vector<int>>> dp0((1 << 7), vector<vector<int>>(7, vector<int>(2)));
            vector<vector<vector<int>>> dp1((1 << 7), vector<vector<int>>(7, vector<int>(2)));
            for (int k = 0; k < 7; k++){
                dp0[a[i]][k][bool(a[j] & (1 << k))]++;
            }
            for (int w = 0; w < q; w++){
                dp1 = dp0;
                int x = 0;
                int y = 0;
                if (req[w][0] <= i && i <= req[w][1]){
                    x = req[w][2];
                }
                if (req[w][0] <= j && j <= req[w][1]){
                    y = req[w][2];
                }
                for (int s = 0; s < (1 << 7); s++){
                    for (int k = 0; k < 7; k++){
                        if (y & (1 << k)){
                            swap(dp0[s][k][0], dp0[s][k][1]);
                        }
                        dp1[s ^ x][k][0] = add(dp1[s ^ x][k][0], dp0[s][k][0]);
                        dp1[s ^ x][k][1] = add(dp1[s ^ x][k][1], dp0[s][k][1]);
                    }
                }
                dp1.swap(dp0);
            }
            int segcnt = mul(i, n - j + 1);
            int t = mul(segcnt, 1 + (i != j));
            for (int s = 0; s < (1 << 7); s++){
                for (int k = 0; k < 7; k++){
                    res = add(res, mul(mul(s, mul(dp0[s][k][1], (1 << k))), t));
                }
            }
        }
    }
    return res;
}

vector<vector<vector<int>>> pref;

int count(int x, int i1, int j1, int i2, int j2){
    if (i1 > i2 || j1 > j2){
        return 0;
    }
    return pref[x][i2][j2] - pref[x][i1 - 1][j2] - pref[x][i2][j1 - 1] + pref[x][i1 - 1][j1 - 1];
}

signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    #ifdef ON_PC
        freopen("input.txt", "r", stdin);
    #endif
    // freopen("output.txt", "w", stdout);
    vector<int> pw2(1e3 + 10);
    pw2[0] = 1;
    for (int i = 1; i < 1e3 + 10; i++){
        pw2[i] = mul(pw2[i - 1], 2);
    }
    int T = 1;
    // cin >> T;
    while (T--){
        int n;
        cin >> n;
        vector<int> a(n + 1);
        for (int i = 1; i <= n; i++){
            cin >> a[i];
        }
        int q;
        cin >> q;
        vector<vector<int>> req(q);
        for (int id = 0; id < q; id++){
            req[id].resize(3);
            for (int i = 0; i < 3; i++){
                cin >> req[id][i];
            }
        }
        #ifdef ON_PC
            cout << naive(a, req) << "\n";
        #endif
        int res = 0;
        for (int i = 1; i <= n; i++){
            for (int j = i; j <= n; j++){
                int segcnt = mul(i, n - j + 1);
                int t = mul(segcnt, 1 + (i != j));
                int sum = 0;
                for (int x = 0; x < 7; x++){
                    for (int y = 0; y < 7; y++){
                        vector<int> dp0(4);
                        vector<int> dp1(4);
                        dp0[(bool(a[i] & (1 << x)) << 1) | (bool(a[j] & (1 << y)))] = 1;
                        for (int k = 0; k < q; k++){
                            dp1 = dp0;
                            int i1 = 0;
                            if (req[k][0] <= i && i <= req[k][1]){
                                i1 = bool(req[k][2] & (1 << x));
                            }
                            int i2 = 0;
                            if (req[k][0] <= j && j <= req[k][1]){
                                i2 = bool(req[k][2] & (1 << y));
                            }
                            int s = (i1 << 1) | i2;
                            for (int w = 0; w < 4; w++){
                                dp1[w ^ s] = add(dp1[w ^ s], dp0[w]);
                            }
                            dp1.swap(dp0);
                        }
                        sum = add(sum, mul(pw2[x + y], dp0[3]));
                    }
                }
                sum = mul(sum, t);
                res = add(res, sum);
            }
        }
        cout << res << "\n";
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 328 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
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 328 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 54 ms 212 KB Output is correct
7 Correct 47 ms 212 KB Output is correct
8 Correct 53 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2075 ms 6608 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 2080 ms 340 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 324 KB Output is correct
2 Correct 10 ms 328 KB Output is correct
3 Correct 10 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 324 KB Output is correct
2 Correct 10 ms 328 KB Output is correct
3 Correct 10 ms 212 KB Output is correct
4 Execution timed out 2084 ms 596 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 328 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 54 ms 212 KB Output is correct
7 Correct 47 ms 212 KB Output is correct
8 Correct 53 ms 308 KB Output is correct
9 Correct 9 ms 324 KB Output is correct
10 Correct 10 ms 328 KB Output is correct
11 Correct 10 ms 212 KB Output is correct
12 Correct 1468 ms 340 KB Output is correct
13 Correct 1471 ms 340 KB Output is correct
14 Correct 1274 ms 340 KB Output is correct
15 Correct 1474 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 328 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 54 ms 212 KB Output is correct
7 Correct 47 ms 212 KB Output is correct
8 Correct 53 ms 308 KB Output is correct
9 Correct 9 ms 324 KB Output is correct
10 Correct 10 ms 328 KB Output is correct
11 Correct 10 ms 212 KB Output is correct
12 Execution timed out 2084 ms 596 KB Time limit exceeded
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 328 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 54 ms 212 KB Output is correct
7 Correct 47 ms 212 KB Output is correct
8 Correct 53 ms 308 KB Output is correct
9 Execution timed out 2075 ms 6608 KB Time limit exceeded
10 Halted 0 ms 0 KB -