QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#549614#862. Social JusticeRafat_KabirAC ✓221ms10616kbC++204.3kb2024-09-06 18:47:072024-09-06 18:47:07

Judging History

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

  • [2024-09-06 18:47:07]
  • 评测
  • 测评结果:AC
  • 用时:221ms
  • 内存:10616kb
  • [2024-09-06 18:47:07]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <time.h>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <cstring>

using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <iostream>

using namespace __gnu_pbds;
using namespace std;
template <class T>
using Tree =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// to erase in multiset-> less_equal<T> and 
// s.erase(s.find_by_order(s.order_of_key(x)))
// lower_bound(x)=>(cannot use the stl lower_bound function)
// ll idx = s.order_of_key(x)
// if(idx == s.size()) -> no lower_bound
// else lb = *s.find_by_order(idx) // as 0-indexing
// idx-1 will give highest value which is strictly less than x
// for upper_bound->do the same with (x+1)

typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef tuple<ll, ll, ll> t64;
typedef vector<t64> vt64;
typedef vector<vt64> vvt64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
typedef vector<vector<p32> > vvp32;
typedef vector<bool> vb;
ll mod =  1e9+7, MOD = 998244353;
double eps = 1e-12;
// #define forn(i,e) for(ll i = 0; i < e; i++)
#define FOR(s, e, i) for(int i = s; i <= e; i++)
// #define rforn(i,s) for(ll i = s; i >= 0; i--)
#define ROF(s ,e, i) for(int i = s; i >= e; i--)
#define coutAll(A) for(auto asdafas : A) cout <<  asdafas << " "; cout << "\n";
#define foutAll(A) for(auto asdafas : A) fout <<  asdafas << " "; cout << "\n";
#define cinAll(A) for(auto &asdafas : A) cin >>  asdafas;
#define finAll(A) for(auto &asdafas : A) fin >>  asdafas;
#define minpq priority_queue<ll, v64, greater<ll>>
#define maxpq priority_queue<ll> 
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define fi first
#define se second
ll inf = LLONG_MAX;
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef pair<ll, ll> pll;
typedef pair<ll, ll> pii;
//#define MAXN 1000000

void solve(int it)
{
    int n; cin >> n;
    v64  pref(n + 1);
    vp64 A(n + 1);
    FOR(1, n, i){
        cin >> A[i].fi;
        A[i].se = i;
    }
    sort(all(A));
    FOR(1, n, i){
        pref[i] = pref[i-1] + A[i].fi;
    }
    ll p, q;
    cin >> p >> q;
    ll c = 1;
    ROF(n, 1, i){
        // if(i*q*A[i].fi <= p*(pref[i])){
        //     c = i;
        //     break;
        // }
        ll l = 1, r = i, res = -1;
        while(l <= r){
            ll mid = (l + r) / 2;
            ll m = i-mid+1;
            if(m*q*A[i].fi <= p*(pref[i]-pref[mid-1])){
                res = m;
                r = mid - 1;
            }else{
                l = mid + 1;
            }
        }
        c = max(c, res);
    }
    // cout << c << "\n";
    if(c == 1){
        cout << "0\n\n";
        return;
    }
    v32 ans;
    v32 pf(n + 2, 0);
    ROF(n, c, i){
        ll e = i-(c-1)+1;
        if(e > i) continue;
        ll sum = pref[i]-pref[e-1];
        ll l = 1, r = e-1, ps = -1;
        while(l <= r){
            ll mid = (l + r) / 2;
            if(c*q*A[i].fi <= p*(sum + A[mid].fi)){
                ps = mid;
                r = mid - 1;
            }else{
                l = mid + 1;
            }
        }
        if(ps!=-1){
            pf[ps]++;
            pf[i+1]--;
        }
    }
    // coutAll(pf);
    ll res = 0;
    FOR(1, n, i){
        res += pf[i];
        if(res == 0){
            ans.pb(A[i].se);
        }
    }
    sort(all(ans));
    cout << ans.size() << "\n";
    coutAll(ans);
    

}


int main()
{
    fast_cin();    
    ll t = 1;
    cin >> t;
    for(int it=1; it<=t; it++)
    {
        //cout << "Case " << it << ": ";
        solve(it);
    }
    return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 0
Accepted
time: 2ms
memory: 3628kb

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 
13
1 2 3 4 5 6 7 8 9 10 11 12 20 
15
1 2 3 4 5 6 7 8 9 10 11 12 18 19 20 
0

2
2 8 
2
9 12 
2
2 14 
10
1 4 5 6 7 13 14 15 18 20 
2
9 16 
2
16 18 
2
5 13 
10
4 5 6 9 11 15 16 18 19 20 
2
5 19 
2
5 13 
2
10 15...

result:

ok 6086 numbers

Test #3:

score: 0
Accepted
time: 107ms
memory: 4308kb

input:

125
5000
1 1 1 1000000000 1000000000 1000000000 1000000000 1 1 1 1 1 1000000000 1 1 1 1 1 1 1000000000 1000000000 1 1000000000 1000000000 1000000000 1 1000000000 1000000000 1000000000 1 1 1000000000 1000000000 1 1000000000 1 1 1 1000000000 1000000000 1000000000 1000000000 1000000000 1 1 1 1000000000...

output:

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

0

4491
3 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 25 26 27 28 29 30 31 32 33 34 35 36 37 39 40 42 43 44 45 46 48 49 50 51 53 54 55 56 57 58 59 62 63 64 66 67 68 70 71 72 74 75 76 77 78 79 80 81 82 83 84 85 87 88 89 90 93 94 95 96 97 ...

result:

ok 242748 numbers

Test #4:

score: 0
Accepted
time: 193ms
memory: 10616kb

input:

5
200000
512314734 33319999 85503340 443544695 92411616 149252701 723302421 176149500 143875507 972078271 907672089 585808794 390600756 700244129 848509047 550288071 859158053 356354007 437419096 572862734 118863313 959486458 472657137 107261032 199102866 190553436 489624108 79203044 147746132 47881...

output:

181062
1 2 3 4 5 6 7 8 9 12 13 14 15 16 17 18 19 20 21 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 42 43 44 45 46 47 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 79 80 81 82 83 84 85 86 87 88 89 90 91 92 94 95 96 98 99 100 101 102 103 104 105 106 1...

result:

ok 380173 numbers

Test #5:

score: 0
Accepted
time: 221ms
memory: 9604kb

input:

5
200000
15187692 56 41 5053827 3148366 6530 10 131 4381 380972680 499497 8727 371 555036936 2810792 641 3116415 4514225 22284 542730997 129 2227 173361 49408 4 528 1 2660 20568 466863 1 5348 206792 6 150 37 576581 240275683 318 24664 99 34829 38855 177 18018 189646 653 437641 2 219866 5294 3476 856...

output:

83879
2 3 7 8 9 13 16 21 22 25 26 27 28 31 34 35 36 39 41 44 47 49 52 54 58 60 61 66 67 68 69 70 71 72 73 75 77 81 84 86 88 90 92 93 95 96 97 98 99 100 105 106 107 114 117 119 121 122 123 125 126 130 131 135 136 146 147 148 149 152 153 154 156 158 160 161 163 168 170 171 174 179 180 182 184 186 189 ...

result:

ok 176756 numbers