QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#510686#5665. AA Country and King DreamoonchimeraCompile Error//C++112.3kb2024-08-09 11:02:592024-08-09 11:02:59

Judging History

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

  • [2024-08-09 11:02:59]
  • 评测
  • [2024-08-09 11:02:59]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define ll long long

vector<ll> process(ll N, vector<ll>& ops, set<ll>& avail) {
    vector<bool> istk(N, false);
    vector<ll> stk;

    for(auto x: ops) {
        if(istk[x]) {
            stk.pop_back();
        } else {
            if(avail.find(x) != avail.end()) avail.erase(x);
            stk.push_back(x); istk[x] = true;
        }
    }

    return stk;
}


void solve() {
    ll N; cin >> N; vector<ll> P(2*N-1); for(ll i = 0; i < 2*N-1; i++) cin >> P[i];

    if(P[0] == 0) P[0] = 1;
    if(P.back() == 0) P.back() = 1;

    set<ll> avail; for(ll i = 1; i <= N; i++) avail.insert(i);

    vector<ll> prefix;
    for(ll i = 0; i < N; i++) {
        if(P[i]) prefix.push_back(P[i]); else break;
    }

    vector<ll> suffix;
    for(ll i = 2*N-2; i >= 0; i--) {
        if(P[i]) suffix.push_back(P[i]); else break;
    }

    auto sstk = process(N, suffix, avail);
    auto pstk = process(N, prefix, avail);

    
    ll NCP = 0;
    while(NCP < pstk.size() && NCP < sstk.size() && pstk[NCP] == sstk[NCP]) NCP++;

    bool ICP = pstk.size() == NCP;

    for(ll i = 0; i < 2*N - 1; i++) {
        if(!P[i]) {
            ll obligation = 3*N;

            if(ICP) {
                if(sstk.size() > pstk.size()) {
                    obligation = sstk[pstk.size()];
                }

                if(!avail.size() || ((*avail.begin()) > obligation)) {
                    P[i] = obligation; pstk.push_back(obligation);
                } else {
                    P[i] = (*avail.begin()); pstk.push_back(*avail.begin()); avail.erase(avail.begin()); ICP = false;
                }
            } else {
                if(pstk.size() > 1) obligation = pstk[pstk.size()-2];
                if(!avail.size() || ((*avail.begin()) > obligation)) {
                    P[i] = obligation; pstk.pop_back()
                    ICP = (pstk.size() == 0) || (pstk.size() <= sstk.size() && pstk.back() == sstk[pstk.size()-1]);
                } else {
                    P[i] = (*avail.begin()); pstk.push_back(*avail.begin()); avail.erase(avail.begin()); ICP = false;
                }
            }


        }

        cout << P[i] << " ";
    }

    cout << "\n";


}


int main() {
    ll T; cin >> T;
    while(T--) solve();
}

Details

answer.code: In function ‘void solve()’:
answer.code:66:55: error: expected ‘;’ before ‘ICP’
   66 |                     P[i] = obligation; pstk.pop_back()
      |                                                       ^
      |                                                       ;
   67 |                     ICP = (pstk.size() == 0) || (pstk.size() <= sstk.size() && pstk.back() == sstk[pstk.size()-1]);
      |                     ~~~