QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#707140#8835. Goodmansenak#WA 2ms3848kbC++201.1kb2024-11-03 14:49:352024-11-03 14:49:37

Judging History

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

  • [2024-11-03 14:49:37]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3848kb
  • [2024-11-03 14:49:35]
  • 提交

answer

//预处理O(N)
//查询O(logM)
//组合数公式
#include<iostream>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<cstring>
#include<algorithm>
#define int long long
using namespace std;
const int N = 1e6 + 7;
pair<int, int> p[N];
void solve() {
    int n;
    cin >> n;
    bool vis = true;
    for (int i = 1; i <= n; i++) {
        cin >> p[i].first;
        if (p[i].first != p[i - 1].first + 1) {
            vis = false;
        }
        p[i].second = i;
    }

    if (vis) {
        for (int i = 1; i <= n; i++) {
            cout << i << ' ';
        }
        cout << endl;
        return;
    }

    sort(p + 1, p + 1 + n);

    vector<int> res;

    int idx1 = 1,idx2 = n;
    int cnt = 0;
    while (idx1 <= idx2) {
        if(cnt % 2 == 0)res.push_back(p[idx2--].second);
        else res.push_back(p[idx1++].second);
        cnt++;
    }

    for (auto it : res) {
        cout << it << ' ';
    }
    cout << endl;

}
signed main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T = 1;
    cin >> T;
    while(T--)solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

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

output:

1 2 3 4 
1 6 2 5 3 4 

result:

ok Correct (2 test cases)

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 3848kb

input:

873
6
1 5 2 4 6 3
6
5 1 6 4 3 2
4
1 4 3 2
6
2 1 6 5 4 3
6
4 5 1 3 6 2
6
6 2 1 5 4 3
5
1 5 4 3 2
6
1 2 6 3 5 4
4
2 1 3 4
6
1 6 4 2 3 5
6
6 1 3 5 2 4
6
2 1 4 5 3 6
6
3 4 1 5 2 6
6
4 1 5 2 6 3
6
5 2 1 4 6 3
6
4 1 6 2 3 5
6
5 1 3 4 6 2
6
6 2 5 4 1 3
6
6 2 5 1 4 3
6
5 2 3 6 4 1
6
6 1 2 5 4 3
6
2 3 4 6 1 ...

output:

5 1 2 3 4 6 
3 2 1 6 4 5 
2 1 3 4 
3 2 4 1 5 6 
5 3 2 6 1 4 
1 3 4 2 5 6 
2 1 3 5 4 
3 1 5 2 6 4 
4 2 3 1 
2 1 6 4 3 5 
1 2 4 5 6 3 
6 2 4 1 3 5 
6 3 4 5 2 1 
5 2 3 4 1 6 
5 3 1 2 4 6 
3 2 6 4 1 5 
5 2 1 6 4 3 
1 5 3 2 4 6 
1 4 3 2 5 6 
4 6 1 2 5 3 
1 2 4 3 5 6 
4 5 6 1 3 2 
2 5 1 3 4 6 
3 4 6 2 1 5...

result:

wrong answer Jury found better answer than participant (test case 1)