QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#815961#9871. Just another Sorting Problemtamir#WA 0ms3608kbC++201.2kb2024-12-15 19:44:312024-12-15 19:44:31

Judging History

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

  • [2024-12-15 19:44:31]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3608kb
  • [2024-12-15 19:44:31]
  • 提交

answer

#include<bits/stdc++.h>
// #include<iostream>
using namespace std;

using ll = long long;
template <class T>
struct BIT {
    int n;
    vector<T> s;
    BIT(int n): n(n), s(n + 1) {

    }
    void add(int i, const T &v) {
        for(i++; i <= n; i += i & -i) {
            s[i] += v;
        }
    }
    T sum(int i) {
        T ans{};
        for(; i; i -= i & -i) {
            ans += s[i];
        }
        return ans;
    }
    T sum(int l, int r) {
        return sum(r) - sum(l);
    }
};
void solve() {
    int n; string st;
    cin >> n >> st;
    
    vector<int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    if(n == 2){
        cout << "Alice\n";
        return;
    }
    BIT<int> bit(n + 5);
    ll inv = 0;
    for(int i = 0; i < n; i++){
        inv += bit.sum(a[i] + 1, n + 1);
        bit.add(a[i], 1);
    }
    if(st == "Bob" && inv & 1) {
        cout << "Bob\n";
        return;
    }
    if(st == "Alice" && inv % 2 == 0){
        cout << "Bob\n";
        return;
    }
    cout << "Alice\n";
}

int main() {
    ios::sync_with_stdio(0); cin.tie(nullptr);
    int t = 1;
    cin >> t;
    while(t--) {
        solve();
    }
}

详细

Test #1:

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

input:

3
2 Alice
2 1
3 Bob
1 3 2
10 Bob
1 2 3 4 5 6 7 8 10 9

output:

Alice
Bob
Bob

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

2
2 Alice
2 1
2 Bob
2 1

output:

Alice
Alice

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3544kb

input:

10
3 Bob
2 3 1
3 Alice
3 1 2
3 Bob
3 1 2
3 Alice
1 3 2
3 Alice
3 2 1
3 Bob
2 1 3
3 Bob
1 3 2
3 Alice
2 1 3
3 Alice
2 3 1
3 Bob
3 2 1

output:

Alice
Bob
Alice
Alice
Alice
Bob
Bob
Alice
Bob
Bob

result:

ok 10 lines

Test #4:

score: -100
Wrong Answer
time: 0ms
memory: 3484kb

input:

46
4 Alice
4 1 3 2
4 Bob
4 1 3 2
4 Bob
3 2 4 1
4 Bob
2 4 1 3
4 Bob
1 4 3 2
4 Bob
4 1 2 3
4 Alice
1 2 4 3
4 Alice
3 2 1 4
4 Bob
2 1 4 3
4 Bob
4 3 1 2
4 Alice
1 3 2 4
4 Bob
3 1 4 2
4 Bob
1 3 2 4
4 Alice
2 4 1 3
4 Bob
2 1 3 4
4 Alice
2 1 3 4
4 Bob
4 2 3 1
4 Bob
3 4 2 1
4 Alice
4 1 2 3
4 Bob
2 4 3 1
4 B...

output:

Bob
Alice
Alice
Bob
Bob
Bob
Alice
Alice
Alice
Bob
Alice
Bob
Bob
Alice
Bob
Alice
Bob
Bob
Alice
Alice
Alice
Bob
Alice
Alice
Alice
Bob
Alice
Bob
Bob
Bob
Alice
Alice
Alice
Bob
Bob
Bob
Bob
Bob
Alice
Bob
Alice
Alice
Bob
Alice
Bob
Alice

result:

wrong answer 2nd lines differ - expected: 'Bob', found: 'Alice'