QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#88562#5665. AA Country and King DreamoonCCSU_WineWA 61ms3376kbC++201.6kb2023-03-16 15:35:512023-03-16 15:35:52

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-16 15:35:52]
  • 评测
  • 测评结果:WA
  • 用时:61ms
  • 内存:3376kb
  • [2023-03-16 15:35:51]
  • 提交

answer

#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 3e5 + 10;
int a[N * 2];
int vis[N], fa[N], cnt, st[N];
int n, m;
void solve()
{
    for(int i = 0; i <= n; i ++) {
        vis[i] = st[i] = fa[i] = 0;
    }

    cin >> n;
    m = n * 2 - 1;
    for(int i = 1; i <= m; i ++) cin >> a[i];

    a[1] = a[m] = 1;
    int tot = 0;
    for(int i = 1; a[i] && i <= m; tot = i ++){//建树
        if(!vis[a[i]]) fa[a[i]] = a[i - 1];
        vis[a[i]] = 1;
    }

    int tid = 0;
    for(int i = m; a[i] && i >= 1; tid = i --){
        if(!vis[a[i]]) fa[a[i]] = a[i + 1];
        vis[a[i]] = st[a[i]] = 1; //标记后面出现过的点
    }

    cnt = 1;
    int id = a[tot];
    while(cnt <= n){
        while(cnt <= n && vis[cnt]) ++ cnt;
        if(cnt > n) break;
        while(fa[id] && !st[id] && fa[id] < cnt){
            id = fa[id];
            a[++ tot] = id;
        }
        // printf("id1 = %d\n",id);
        fa[cnt] = id;
        a[++ tot] = cnt;
        vis[cnt] = 1;
        id = cnt;
        // printf("id2 = %d fa[id] = %d\n",id,fa[id]);
    }
	// printf("tot = %d tid = %d\n")
    while(tot + 1 <= m && !a[tot + 1] && fa[a[tot]] && !st[a[tot]]){
        a[tot + 1] = fa[a[tot]]; tot ++;
    }
    while(tid - 1 >= 1 && !a[tid - 1] && fa[a[tid]]){
        a[tid - 1] = fa[a[tid]]; tid --;
    }

    for(int i = 1; i <= m; i ++){
        cout << a[i] << " ";
    }
    cout << "\n";
}

int main(){
    ios::sync_with_stdio(false);
    cout.tie(NULL);
    int t;
    cin >> t;
    while(t --){
        solve();
    }
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 3272kb

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: 61ms
memory: 3376kb

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 3 1 2 1 
1 2 3 2 1 
1 3 1 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3 2 1 
1 2 3...

result:

wrong answer 24th lines differ - expected: '1 2 3 2 1', found: '1 3 1 2 1 '