QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#128259#5024. 【模板】双端队列pandapythoner#0 164ms19276kbC++203.6kb2023-07-20 19:41:302024-07-04 00:48:41

Judging History

你现在查看的是最新测评结果

  • [2024-07-04 00:48:41]
  • 评测
  • 测评结果:0
  • 用时:164ms
  • 内存:19276kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-20 19:41:30]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

mt19937 rnd(234);
const ll inf = 1e18;

int n;
vector<ll> a;
vector<ll> b;
vector<ll> p;
vector<vector<unordered_map<int, int>>> dp;

int get_dp(int l, int r, int xr1) {
    if (l == r) {
        return xr1;
    }
    int xr2 = xr1 ^ 1 ^ (p[r] ^ p[l]);
    auto it = dp[l][xr1].find(r);
    if (it != dp[l][xr1].end()) {
        return it->second;
    }
    int rs = 0;
    bool fndd = false;
    if ((r - l) % 2 == 0) {
        if ((p[r] ^ p[l]) == 1) {
            rs = 1;
            fndd = true;
        }
    }
    if ((r - l) % 2 == 1) {
        if ((p[r] ^ p[l]) == 0 && xr1 == 1) {
            rs = 1;
            fndd = true;
        }
    }
    if (!fndd && get_dp(l + 1, r, xr2) == 0) {
        rs = 1;
        fndd = true;
    }
    if (!fndd && get_dp(l, r - 1, xr2) == 0) {
        rs = 1;
        fndd = true;
    }
    dp[l][xr1][r] = rs;
    return rs;
}

int solve_slow() {
    ll xrall = 0;
    for (int i = 0; i < n; i += 1) {
        xrall ^= a[i];
    }
    if (xrall == 0) {
        return -1;
    }
    int bt = 0;
    while ((1 << bt) <= xrall) {
        bt += 1;
    }
    bt -= 1;
    b.resize(n);
    for (int i = 0; i < n; i += 1) {
        b[i] = ((a[i] >> bt) & 1);
    }
    p.resize(n + 1);
    p[0] = 0;
    for (int i = 0; i < n; i += 1) {
        p[i + 1] = p[i] ^ b[i];
    }
    dp.assign(n, vector<unordered_map<int, int>>(2, unordered_map<int, int>()));
    /*
    for(int l = 0; l <= n; l += 1){
        for(int r = 0; r <= n; r += 1){
            for(int xr1 = 0; xr1 < 2; xr1 += 1){
                for(int xr2 = 0; xr2 < 2; xr2 += 1){
                    dp[l][r][xr1][xr2] = 0;
                }
            }
        }
        dp[l][l][1][0] = 1;
    }
    for(int l = n - 1; l >= 0; l -= 1){
        for(int r = l + 1; r <= n; r += 1){
            for(int xr1 = 0; xr1 < 2; xr1 += 1){
                for(int xr2 = 0; xr2 < 2; xr2 += 1){
                    dp[l][r][xr1][xr2] = 0;
                    if(dp[l + 1][r][xr2][xr1 ^ b[l]] == 0){
                        dp[l][r][xr1][xr2] = 1;
                    }
                    if(dp[l][r - 1][xr2][xr1^ b[r - 1]] == 0){
                        dp[l][r][xr1][xr2] = 1;
                    }
                }
            }
        }
    }
    if(dp[0][n][0][0]){
        return 0;
    }
    */
    if (get_dp(0, n, 0)) {
        return 0;
    }
    return 1;
}

int32_t main() {
    if (0) {
        n = 7;
        for (int mask = 0; mask < (1 << n); mask += 1) {
            a.resize(n);
            for (int i = 0; i < n; i += 1) {
                a[i] = ((mask >> i) & 1);
            }
            int rs = solve_slow();
            if (rs == 0) {
                for (int i = 0; i < n; i += 1) {
                    cout << a[i];
                }
                cout << " " << rs << "\n";
            }
        }
    }
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    int T;
    cin >> T;
    while (T--) {
        cin >> n;
        a.resize(n);
        for (int i = 0; i < n; i += 1) {
            cin >> a[i];
        }
        int rs = solve_slow();
        if (rs == -1) {
            cout << "Draw"
                 << "\n";
        } else if (rs == 0) {
            cout << "First"
                 << "\n";
        } else {
            cout << "Second"
                 << "\n";
        }
    }
    return 0;
}

/*
2
5
1 1 0 0 1
5
1 0 0 1 1


*/

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3532kb

input:

40
15
1042186166 1065050038 1052442342 117744385 1044381358 996146407 947617159 1031691934 27328777 130294601 1065311743 1065082111 12845136 941620871 1042177446
15
1068465534 15766217 69219008 95461385 1048542590 1051709438 1048575351 1072652151 978275647 1044381687 999247358 1062194999 1054829887 ...

output:

First
First
Second
First
First
Second
First
Draw
Draw
Draw
Draw
First
Second
First
Second
First
First
Draw
Second
Second
Second
Draw
First
Draw
Draw
First
First
First
Draw
Second
First
First
First
First
First
First
First
First
First
Draw

result:

wrong answer 1st words differ - expected: 'Second', found: 'First'

Subtask #2:

score: 0
Wrong Answer

Test #2:

score: 0
Wrong Answer
time: 4ms
memory: 3920kb

input:

40
987
1073733087 9437225 570431533 1031755263 1031755251 579873284 571521061 536872960 546353705 43000364 535780827 1065313790 536834043 41953824 503270871 1040175099 8426021 537960961 1054732 545292837 34648585 34603052 546314244 537965060 9439748 41953292 43037189 9447949 536864767 1073698294 503...

output:

Second
First
First
First
First
First
First
First
Second
First
Draw
First
First
First
First
First
First
First
Draw
Draw
Draw
Draw
First
First
First
First
First
First
First
First
Draw
First
First
First
First
Draw
First
First
First
First

result:

wrong answer 2nd words differ - expected: 'Second', found: 'First'

Subtask #3:

score: 0
Wrong Answer

Test #4:

score: 0
Wrong Answer
time: 155ms
memory: 19276kb

input:

40
49999
30704571 23631198 10459697 452884 909025 3745220 5633170 29257098 24428644 21991837 21100897 21249665 18667093 13809790 21220831 32750672 29531337 31709216 17139349 4444339 787544 14509794 3855820 201034 13281440 26541636 31476242 10318360 20485824 26793325 8264891 22349828 20554718 7556006...

output:

Second
First
First
First
First
Second
First
First
First
Second
Second
First
First
First
Second
Second
Second
Second
First
First
First
Second
Second
First
First
First
First
First
First
First
First
First
First
Second
First
First
First
First
First
First

result:

wrong answer 3rd words differ - expected: 'Second', found: 'First'

Subtask #4:

score: 0
Wrong Answer

Test #6:

score: 0
Wrong Answer
time: 164ms
memory: 19240kb

input:

40
49035
1073176430 531291499 1005508607 675350672 368768 867368831 139504132 1321089 134482448 464248170 1068169195 68946580 469491567 738764816 742459920 535197167 531887598 672172545 609558673 608209040 335282031 532674543 72878741 610117777 138447508 398155759 71608464 672172165 402325355 609845...

output:

First
First
First
First
First
First
Draw
First
First
Draw
First
First
First
First
First
First
First
First
First
Draw
First
First
Draw
First
First
First
First
First
First
First
First
Draw
First
First
First
First
First
First
First
First

result:

wrong answer 2nd words differ - expected: 'Second', found: 'First'