QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#806465#9873. Last Chance: Threads of DespairPessimismCompile Error//C++236.8kb2024-12-09 10:58:442024-12-09 10:58:45

Judging History

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

  • [2024-12-09 10:58:45]
  • 评测
  • [2024-12-09 10:58:44]
  • 提交

answer

#include<bits/stdc++.h>

#define endl "\n"
// #define int long long

using namespace std;

using i64 = long long;
using u64 = unsigned long long;

constexpr int N = 2e5 + 10, M = 2e6 + 10;
constexpr int P = 998244353;
constexpr int INF = 1e9;

void solve() {
    int n, m;
    cin >> n >> m;
    vector<int> h(n), g(m);
    priority_queue<int, vector<int>, greater<>> used;
    priority_queue<int, vector<int>, greater<>> emy;
    priority_queue<int, vector<int>, greater<>> my;
    bool has = false;
    int cnt = 0;
    bool first = false;
    int attack = 0;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        if (h[i] == 1) {
            if (!first) {
                attack++;
            }
            has = true;
            first = true;
            cnt++;
        } else {
            my.push(h[i]);
        }
    }
    for (int i = 0; i < m; i++) {
        cin >> g[i];
        emy.push(g[i]);
    }
    while (((has && !my.empty()) || my.size() > 1) && !emy.empty()) {
        if (!first) {
            if (!emy.empty() && emy.top() <= 1) {
                cnt++;
                emy.pop();
            } else if (!my.empty() && my.top() <= 1) {
                cnt++;
                attack++;
                my.pop();
            } else if (!used.empty() && used.top() <= 1) {
                cnt++;
                used.pop();
            } else {
                while (!emy.empty() && emy.top() > cnt && attack > 0) {
                    auto top = emy.top();
                    emy.pop();
                    emy.push(top - 1);
                    attack--;
                }
                while (!emy.empty() && emy.top() > cnt && ((has && !my.empty()) || my.size() > 1)) {
                    auto top = emy.top();
                    emy.pop();
                    emy.push(top - 1);

                    used.push(my.top() - 1);
                    my.pop();
                }
                if (emy.top() <= cnt) {
                    cnt++;
                    emy.pop();
                } else {
                    break;
                }
            }
            first = true;
        } else {
            if (!emy.empty() && emy.top() <= cnt) {
                cnt++;
                emy.pop();
            } else if (!my.empty() && my.top() <= cnt) {
                cnt++;
                attack++;
                my.pop();
            } else if (!used.empty() && used.top() <= cnt) {
                cnt++;
                used.pop();
            } else {
                while (!emy.empty() && emy.top() > cnt && attack > 0) {
                    auto top = emy.top();
                    emy.pop();
                    emy.push(top - 1);
                    attack--;
                }
                while (!emy.empty() && emy.top() > cnt && ((has && !my.empty()) || my.size() > 1)) {
                    auto top = emy.top();
                    emy.pop();
                    emy.push(top - 1);

                    used.push(my.top() - 1);
                    my.pop();
                }
                if (!emy.empty() && emy.top() <= cnt) {
                    cnt++;
                    emy.pop();
                } else {
                    break;
                }
            }
        }
    }
    while (!used.empty() && used.top() <= cnt) {
        cnt++;
        used.pop();
    }
    while (!emy.empty() && emy.top() <= cnt) {
        cnt++;
        emy.pop();
    }
    if (!has) {
        if (!emy.empty() && emy.top() <= 1) {
            cnt++;
            emy.pop();
        }
        while (!emy.empty() && emy.top() <= cnt) {
            cnt++;
            emy.pop();
        }
        while (!emy.empty() && emy.top() > cnt && attack > 0) {
            auto top = emy.top();
            emy.pop();
            emy.push(top - 1);
            attack--;
        }
        while (!emy.empty() && emy.top() > cnt && attack > 0) {
            auto top = emy.top();
            emy.pop();
            emy.push(top - 1);
            attack--;
        }
        while (!used.empty() && used.top() <= cnt) {
            cnt++;
            used.pop();
        }
        while (!emy.empty() && emy.top() <= cnt) {
            cnt++;
            emy.pop();
        }
        while (!emy.empty() && emy.top() > cnt && attack > 0) {
            auto top = emy.top();
            emy.pop();
            emy.push(top - 1);
            attack--;
        }
        while (!emy.empty() && emy.top() > cnt && attack > 0) {
            auto top = emy.top();
            emy.pop();
            emy.push(top - 1);
            attack--;
        }
        while (!used.empty() && used.top() <= cnt) {
            cnt++;
            used.pop();
        }
        while (!emy.empty() && emy.top() <= cnt) {
            cnt++;
            emy.pop();
        }
        if (!my.empty() && my.top() - 1 <= cnt) {
            cnt++;
            my.pop();
        }
        while (!emy.empty() && emy.top() <= cnt) {
            cnt++;
            emy.pop();
        }
        has = true;
    }
    while (!emy.empty() && emy.top() > cnt && !my.empty() {
        auto top = emy.top();
        emy.pop();
        emy.push(top - 1);

        used.push(my.top() - 1);
        my.pop();
    }
    while (!emy.empty() && emy.top() > cnt && attack > 0) {
        auto top = emy.top();
        emy.pop();
        emy.push(top - 1);
        attack--;
    }
    while (!my.empty() && my.top() <= cnt) {
        cnt++;
        my.pop();
        attack++;
    }
    while (!emy.empty() && emy.top() > cnt && attack > 0) {
        auto top = emy.top();
        emy.pop();
        emy.push(top - 1);
        attack--;
    }
    while (!used.empty() && used.top() <= cnt) {
        cnt++;
        used.pop();
    }
    while (!emy.empty() && emy.top() <= cnt) {
        cnt++;
        emy.pop();
    }
    while (!emy.empty() && emy.top() > cnt && attack > 0) {
        auto top = emy.top();
        emy.pop();
        emy.push(top - 1);
        attack--;
    }
    while (!my.empty() && my.top() <= cnt) {
        cnt++;
        my.pop();
        attack++;
    }
    while (!emy.empty() && emy.top() > cnt && attack > 0) {
        auto top = emy.top();
        emy.pop();
        emy.push(top - 1);
        attack--;
    }
    while (!used.empty() && used.top() <= cnt) {
        cnt++;
        used.pop();
    }
    while (!emy.empty() && emy.top() <= cnt) {
        cnt++;
        emy.pop();
    }
    // cout << cnt << endl;
    cout << (emy.empty() && has ? "YES\n" : "NO\n");
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int T;
    cin >> T;
    while (T--) {
        solve();
    }
}

Details

answer.code: In function ‘void solve()’:
answer.code:180:58: error: expected ‘)’ before ‘{’ token
  180 |     while (!emy.empty() && emy.top() > cnt && !my.empty() {
      |           ~                                              ^~
      |                                                          )