QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#24197#862. Social JusticeDoorKickersWA 36ms3704kbC++202.3kb2022-03-27 18:58:132022-04-30 05:15:13

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-04-30 05:15:13]
  • 评测
  • 测评结果:WA
  • 用时:36ms
  • 内存:3704kb
  • [2022-03-27 18:58:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main() {
    int tt; cin >> tt;
    while (tt--) {
        int n; cin >> n;
        vector<pair<int, int>> a(n + 1);
        for (int i = 1; i <= n; i++) {
            cin >> a[i].first;
            a[i].second = i;
        }
        int p, q; cin >> p >> q;
        int r = 1;
        int sum = 0;
        int mx = 0;
        sort(a.begin() + 1, a.begin() + 1 + n);
        for (int i = 1; i <= n; i++) {
            r = max(r, i + 1);
            sum += a[i].first;
            while (r <= n && a[r].first * q * (r - i + 1) <= (a[r].first + sum) * p) {
                sum += a[r].first;
                r++;
            }
            mx = max(mx, r - i);
            sum -= a[i].first;
        }
        // cout << "mx = " << mx << '\n';
        sum = 0;
        for (int i = 2; i <= mx; i++) {
            sum += a[i].first;
        }
        vector<int> ans;
        vector<int> vis(n + 2);
        for (int i = mx; i <= n; i++) {
            int l = 1;
            int r = i - mx + 1;
            while (l < r) {
                int mid = (l + r) >> 1;
                if (a[i].first * q * mx <= (sum + a[mid].first) * p) {
                    r = mid;
                }
                else {
                    l = mid + 1;
                }
            }
            if (a[i].first * q * mx <= (sum + a[l].first) * p) {
                vis[l]++;
                vis[i + 1]--;
            }
            if (i == n) break;
            sum -= a[i - mx + 2].first;
            sum += a[i + 1].first;
        }
        int fl = 0;
        for (int i = 1; i <= n; i++) {
            fl += vis[i];
            if (fl == 0) {
                ans.push_back(a[i].second);
            }
        }
        sort(ans.begin(), ans.end());
        cout << ans.size() << '\n';
        if (ans.size() == 20) {
            cout << "n = " << n << '\n';
            for (int i = 1; i <= n; i++) cout << a[i].first << ' ';
            cout << '\n';
            cout << "p = " << p << ' ' << "q = " << q << '\n';
        }
        for (int i = 0; i < ans.size(); i++) {
            cout << ans[i] << ' ';
        }
        cout << '\n';
    }
    return 0;
}
/*
1
6
1 2 3 4 1000 10000
4 3
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
4
1 2 3 4
3 2
5
1 15 2 5 1
2 1
5
1 2 3 1000 10000
4 3

output:

0

1
2 
2
4 5 

result:

ok 6 numbers

Test #2:

score: -100
Wrong Answer
time: 36ms
memory: 3704kb

input:

1000
1
10
3 2
2
10 100
3 2
3
10 10 100
3 2
4
1 2 3 4
3 2
5
1 15 2 5 1
2 1
5
1 2 3 1000 10000
4 3
6
1 2 3 4 1000 10000
4 3
5
50000 2 1 1 5000
2 1
10
1 15 2 5 1 10000 1 1 1 1
2 1
20
1 15 2 5 1 10000 1 1 1 1 1 15 2 5 1 10000 1 1 1 1
2 1
25
1 15 2 5 1 10000 1 1 1 1 1 15 2 5 1 10000 1 1 1 1 1 15 2 5 1
2 ...

output:

0

0

1
3 
0

1
2 
2
4 5 
3
1 5 6 
2
1 5 
3
2 4 6 
6
2 4 6 12 14 16 
8
2 4 6 12 14 16 22 24 
20
n = 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 
p = 30 q = 29
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 
20
n = 20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 
p = 10 q = 9
1 2 ...

result:

wrong answer 38th numbers differ - expected: '13', found: '20'