QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#689073 | #862. Social Justice | wzj33300 | WA | 0ms | 3564kb | C++23 | 6.2kb | 2024-10-30 15:09:48 | 2024-10-30 15:09:50 |
Judging History
answer
/**
* created : 30.10.2024 08:58:08
* author : wzj33300
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include <algo/debug.h>
#else
#define debug(...) 42
#define assert(...) 42
#endif
using ll = long long;
using u32 = unsigned int;
using u64 = unsigned long long;
using db = long double; // or double, if TL is tight
using str = string; // yay python!
// pairs
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using pd = pair<db, db>;
#define mp make_pair
#define fi first
#define se second
// ^ lol this makes everything look weird but I'll try it
template <class T>
using vc = vector<T>;
template <class T, size_t SZ>
using AR = array<T, SZ>;
using vi = vc<int>;
using vb = vc<bool>;
using vl = vc<ll>;
using vd = vc<db>;
using vs = vc<str>;
using vpi = vc<pi>;
using vpl = vc<pl>;
using vpd = vc<pd>;
// vectors
// oops size(x), rbegin(x), rend(x) need C++17
#define sz(x) int((x).size())
#define bg(x) begin(x)
#define all(x) bg(x), end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsz resize
#define ins insert
#define pb push_back
#define eb emplace_back
#define ft front()
#define bk back()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i < (n); ++i)
#define rep1n(i, n) for (int i = 1; i <= (n); ++i)
#define repr(i, n) for (int i = (n) - 1; i >= 0; --i)
#define rep_subset(t, s) \
for (ll t = (s); t >= 0; t = (t == 0 ? -1 : (t - 1) & (s)))
#define lb lower_bound
#define ub upper_bound
template <class T>
int lwb(vc<T> &a, const T &b) {
return int(lb(all(a), b) - bg(a));
}
template <class T>
int upb(vc<T> &a, const T &b) {
return int(ub(all(a), b) - bg(a));
}
// const int MOD = 998244353; // 1e9+7;
const int Big = 1e9; // not too close to INT_MAX
const ll BIG = 1e18; // not too close to LLONG_MAX
const db PI = acos((db)-1);
const int dx[4]{1, 0, -1, 0}, dy[4]{0, 1, 0, -1}; // for every grid problem!!
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
template <class T>
using pqg = priority_queue<T, vector<T>, greater<T>>;
int pct(int x) { return __builtin_popcount(x); }
int pct(u32 x) { return __builtin_popcount(x); }
int pct(ll x) { return __builtin_popcountll(x); }
int pct(u64 x) { return __builtin_popcountll(x); }
int popcnt_mod_2(int x) { return __builtin_parity(x); }
int popcnt_mod_2(u32 x) { return __builtin_parity(x); }
int popcnt_mod_2(ll x) { return __builtin_parityll(x); }
int popcnt_mod_2(u64 x) { return __builtin_parityll(x); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 1, 2)
int topbit(int x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(u32 x) { return (x == 0 ? -1 : 31 - __builtin_clz(x)); }
int topbit(ll x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
int topbit(u64 x) { return (x == 0 ? -1 : 63 - __builtin_clzll(x)); }
// (0, 1, 2, 3, 4) -> (-1, 0, 1, 0, 2)
int lowbit(int x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(u32 x) { return (x == 0 ? -1 : __builtin_ctz(x)); }
int lowbit(ll x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
int lowbit(u64 x) { return (x == 0 ? -1 : __builtin_ctzll(x)); }
template <typename T>
T floor(T a, T b) {
return a / b - (a % b && (a ^ b) < 0);
}
template <typename T>
T ceil(T x, T y) {
return floor(x + y - 1, y);
}
template <typename T>
T bmod(T x, T y) {
return x - y * floor(x, y);
}
template <typename T>
pair<T, T> divmod(T x, T y) {
T q = floor(x, y);
return {q, x - q * y};
}
template <class T>
bool ckmin(T &a, const T &b) {
return b < a ? a = b, 1 : 0;
} // set a = min(a,b)
template <class T>
bool ckmax(T &a, const T &b) {
return a < b ? a = b, 1 : 0;
} // set a = max(a,b)
template <class T, class U>
T fstTrue(T lo, T hi, U f) {
++hi;
assert(lo <= hi); // assuming f is increasing
while (lo < hi) { // find first index such that f is true
T mid = lo + (hi - lo) / 2;
f(mid) ? hi = mid : lo = mid + 1;
}
return lo;
}
template <class T, class U>
T lstTrue(T lo, T hi, U f) {
--lo;
assert(lo <= hi); // assuming f is decreasing
while (lo < hi) { // find first index such that f is true
T mid = lo + (hi - lo + 1) / 2;
f(mid) ? lo = mid : hi = mid - 1;
}
return lo;
}
// signed main() {
int main() {
// freopen("ex_d1.in", "r", stdin);
// freopen("my.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
vpi aa(n);
for (int i = 0; i < n; i++) cin >> aa[i].first, aa[i].second = i;
int P, Q;
cin >> P >> Q;
sor(aa);
vl a(n + 1);
for (int i = 0; i < n; i++) a[i + 1] = a[i] + aa[i].first;
int minall = Big, minleft = Big, minright = Big;
vpi able;
for (int i = 0; i < n; i++) {
int p = fstTrue(0, n - i - 1, [&](int x) {
int l = x, r = n - i;
ll s = a[r] - a[l];
ll mx = a[r] - a[r - 1];
// debug(l, r, s, mx, P, Q);
if (s * P >= mx * Q * (r - l)) {
return true;
} else {
return false;
}
});
// debug(i, p);
if (p == n - i) {
continue;
}
int cnt = i + p;
if (cnt > minall) continue;
if (true) {
int change = p + 1;
int p2 = fstTrue(1, p, [&](int x) {
int l = p, r = n - i;
ll s = a[r] - a[l] + (a[x] - a[x - 1]) - (a[change] - a[change - 1]);
ll mx = a[r] - a[r - 1];
if (s * P >= mx * Q * (r - l)) {
return true;
} else {
return false;
}
});
p = p2 - 1;
}
if (cnt == minall) {
// ckmin(minleft, p);
// ckmin(minright, i);
able.eb(p, n - i);
}
if (cnt < minall) {
minall = cnt;
able.clear();
able.eb(p, n - i);
}
}
debug(minall, minleft, minright);
// if (n == 10) cout << minall << '\n';
// cout << minleft + minright << '\n';
vi dif(n + 1);
for (auto &it : able) dif[it.first]++, dif[it.second]--;
for (int i = 1; i < n; i++) dif[i] += dif[i - 1];
vi ans;
for (int i = 0; i < n; i++)
if (!dif[i]) ans.eb(aa[i].second + 1);
sor(ans);
cout << sz(ans) << '\n';
for (auto &x : ans) cout << x << ' ';
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3564kb
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:
3 1 2 3
result:
wrong answer 1st numbers differ - expected: '0', found: '3'