QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#125257#5665. AA Country and King DreamoonWaveletWA 20ms11780kbC++143.1kb2023-07-16 12:58:492023-07-16 12:58:51

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-16 12:58:51]
  • 评测
  • 测评结果:WA
  • 用时:20ms
  • 内存:11780kb
  • [2023-07-16 12:58:49]
  • 提交

answer

#include <bits/stdc++.h>
#define up(l, r, i) for(int i = l, END##i = r;i <= END##i;++ i)
#define dn(l, r, i) for(int i = l, END##i = r;i >= END##i;-- i)
using namespace std;
using i64  = long long;
int qread(){
    int w = 1, c = 0, r = 0;
    while(!isdigit(c = getchar())) w = c == '-' ? -1 : 1; r = c - '0';
    while( isdigit(c = getchar())) r = r * 10 + c - '0';
    return w * r;
}
const int MAXN= 3e5 + 3;
const int MAXM= 6e5 + 3;
int P[MAXM], O[MAXM], X[MAXN], Y[MAXN], H[MAXM]; bool V[MAXN];
int main(){
    up(1, qread(), _){
        int n = qread();
        up(1, 2 * n - 1, i) P[i] = qread();
        P[1] = P[2 * n - 1] = 1;
        stack <int> A; A.push(1);
        stack <int> B; B.push(1);
        {
            int s = 1, ss = 0;
            up(2, 2 * n - 1, i) if(P[i]){
                if(P[i] == ss) ss = s, s = A.top(), A.pop();
                    else ss = s, A.push(s = P[i]);
            } else break;
        }
        {
            int s = 1, ss = 0;
            dn(2 * n - 2, 2, i) if(P[i]){
                if(P[i] == ss) ss = s, s = B.top(), B.pop();
                    else ss = s, B.push(s = P[i]);
            } else break;
        }
        int xx = 0; while(!A.empty()) X[++ xx] = A.top(), A.pop();
        int yy = 0; while(!B.empty()) Y[++ yy] = B.top(), B.pop();
        up(xx + 1, n, i) X[i] = 0;
        up(yy + 1, n, i) Y[i] = 0;
        reverse(X + 1, X + 1 + xx);
        reverse(Y + 1, Y + 1 + yy);
        up(1,     n    , i) V[  i ] = false;
        up(1, 2 * n - 1, i) V[P[i]] = true;
        int h = 0, q = 0;
        up(1, n, i) if(V[i] == false)
            H[++ h] = i;
        int o = 0;
        // printf("xx = %d. ", xx); up(1, xx, i) printf("%d ", X[i]); puts("");
        // printf("yy = %d. ", yy); up(1, yy, i) printf("%d ", Y[i]); puts("");
        while(1){
            // up(1, o, i) printf("%d, ", O[i]); puts("");
            if(xx > yy || X[xx] != Y[xx]){
                int u = X[xx - 1];
                if(q < h){
                    int v = H[q + 1];
                    // printf("A : %d, %d\n", u, v);
                    if(u < v) -- xx, O[++ o] = u, X[xx + 1] = 0;
                        else  ++  q, O[++ o] = v, X[++ xx] = v;
                } else -- xx, O[++ o] = u, X[xx + 1] = 0;
            } else if(xx < yy){
                int u = Y[xx + 1];
                if(q < h){
                    int v = H[q + 1];
                    if(u < v) ++ xx, O[++ o] = u, X[xx] = u;
                        else  ++  q, O[++ o] = v, X[++ xx] = v;
                } else ++ xx, O[++ o] = u, X[xx] = u;
            } else if(q < h){
                int u = H[q + 1];
                ++ q, O[++ o] = u, X[++ xx] = u;
            } else break;
        }
        int g = 0;
        up(1, 2 * n - 1, i){
            if(P[i] == 0) printf("%d ", O[++ g]);
                else printf("%d ", P[i]);
        }
        puts("");
    }
    return 0;
}
/*
9
5
1 2 3 2 0 2 1 5 1
5
1 2 3 0 0 2 1 5 1
5
1 2 0 0 0 2 1 5 1
5
1 2 0 0 0 0 1 5 1
5
1 0 0 0 0 0 1 5 1
5
1 0 0 0 0 0 0 5 1
5
1 0 0 0 0 0 0 0 1
5
1 0 0 0 0 0 0 0 0
5
0 0 0 0 0 0 0 0 0
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 11776kb

input:

9
5
1 2 3 2 0 2 1 5 1
5
1 2 3 0 0 2 1 5 1
5
1 2 0 0 0 2 1 5 1
5
1 2 0 0 0 0 1 5 1
5
1 0 0 0 0 0 1 5 1
5
1 0 0 0 0 0 0 5 1
5
1 0 0 0 0 0 0 0 1
5
1 0 0 0 0 0 0 0 0
5
0 0 0 0 0 0 0 0 0

output:

1 2 3 2 4 2 1 5 1 
1 2 3 2 4 2 1 5 1 
1 2 3 2 4 2 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 
1 2 1 3 1 4 1 5 1 

result:

ok 9 lines

Test #2:

score: -100
Wrong Answer
time: 20ms
memory: 11780kb

input:

28668
2
0 2 1
2
0 0 1
2
0 0 0
2
1 0 1
2
1 0 0
2
1 2 0
3
0 2 1 3 1
3
0 0 1 3 1
3
0 0 0 3 1
3
0 0 0 0 1
3
0 0 0 0 0
3
1 0 1 3 1
3
1 0 0 3 1
3
1 0 0 0 1
3
1 0 0 0 0
3
1 2 0 3 1
3
1 2 0 0 1
3
1 2 0 0 0
3
1 2 1 0 1
3
1 2 1 0 0
3
1 2 1 3 0
3
0 2 3 2 1
3
0 0 3 2 1
3
0 0 0 2 1
3
1 0 3 2 1
3
1 0 0 2 1
3
1 2 ...

output:

1 2 1 
1 2 1 
1 2 1 
1 2 1 
1 2 1 
1 2 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 1 3 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3...

result:

wrong answer 72nd lines differ - expected: '1 2 1 3 1 4 1', found: '1 2 1 3 1 3 1 '