QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#246412 | #7523. Partially Free Meal | ikefumy | WA | 1424ms | 22996kb | C++20 | 4.2kb | 2023-11-10 20:02:25 | 2023-11-10 20:02:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define db double
#define pii pair<int,int>
#define pli pair<ll,int>
#define pil pair<int,ll>
#define pll pair<ll,ll>
#define ti3 tuple<int,int,int>
#define int128 __int128_t
#define pii128 pair<int128,int128>
const int inf = 1 << 30;
const ll linf = 1e18;
const ll mod = 1e9 + 7;
const db EPS = 1e-10;
const db pi = acos(-1);
template<class T> bool chmin(T& x, T y){
if(x > y) {
x = y;
return true;
} else return false;
}
template<class T> bool chmax(T& x, T y){
if(x < y) {
x = y;
return true;
} else return false;
}
// overload macro
#define CAT( A, B ) A ## B
#define SELECT( NAME, NUM ) CAT( NAME, NUM )
#define GET_COUNT( _1, _2, _3, _4, _5, _6 /* ad nauseam */, COUNT, ... ) COUNT
#define VA_SIZE( ... ) GET_COUNT( __VA_ARGS__, 6, 5, 4, 3, 2, 1 )
#define VA_SELECT( NAME, ... ) SELECT( NAME, VA_SIZE(__VA_ARGS__) )(__VA_ARGS__)
// rep(overload)
#define rep( ... ) VA_SELECT(rep, __VA_ARGS__)
#define rep2(i, n) for (int i = 0; i < int(n); i++)
#define rep3(i, a, b) for (int i = a; i < int(b); i++)
#define rep4(i, a, b, c) for (int i = a; i < int(b); i += c)
// repll(overload)
#define repll( ... ) VA_SELECT(repll, __VA_ARGS__)
#define repll2(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repll3(i, a, b) for (ll i = a; i < (ll)(b); i++)
#define repll4(i, a, b, c) for (ll i = a; i < (ll)(b); i += c)
// rrep(overload)
#define rrep( ... ) VA_SELECT(rrep, __VA_ARGS__)
#define rrep2(i, n) for (int i = n - 1; i >= 0; i--)
#define rrep3(i, a, b) for (int i = b - 1; i >= a; i--)
#define rrep4(i, a, b, c) for (int i = b - 1; i >= a; i -= c)
// rrepll(overload)
#define rrepll( ... ) VA_SELECT(rrepll, __VA_ARGS__)
#define rrepll2(i, n) for (ll i = (ll)(n) - 1; i >= 0ll; i--)
#define rrepll3(i, a, b) for (ll i = b - 1; i >= (ll)(a); i--)
#define rrepll4(i, a, b, c) for (ll i = b - 1; i >= (ll)(a); i -= c)
// for_earh
#define fore(e, v) for (auto&& e : v)
// vector
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
int n;
int l[200010], r[200010], lb[200010], ub[200010];
ll ans[200010], idx[200010];
bool used[200010];
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cout << fixed << setprecision(20);
cin >> n;
vector<pll> m;
rep (i, 1, n + 1) {
int a, b;
cin >> a >> b;
m.push_back({b, a});
r[i] = n, ans[i] = linf;
}
sort(all(m));
vector<int> q = {(n + 2) / 2};
lb[(n + 2) / 2] = 1, ub[(n + 2) / 2] = n + 1;
while (!q.empty()) {
vector<int> nq;
ll res = linf, mnsum = 0;
multiset<ll> mn, rem;
fore (k, q) {
rep (i, l[k], r[k]) {
auto [b, a] = m[i];
if (!used[i]) rem.insert(a);
used[i] = true;
while (!rem.empty() && (int)mn.size() < k) {
mn.insert(*rem.begin());
mnsum += *rem.begin();
rem.erase(rem.begin());
}
while (!rem.empty() && !mn.empty()) {
int mnmx = *mn.rbegin(), remmn = *rem.begin();
if (mnmx > remmn) {
mnsum += remmn - mnmx;
mn.erase(mn.find(mnmx)), mn.insert(remmn);
rem.erase(rem.find(remmn)), rem.insert(mnmx);
} else {
break;
}
}
if ((int)mn.size() < k) continue;
if (ans[k] >= mnsum + b) ans[k] = mnsum + b, idx[k] = i;
}
auto update = [&](int x, int y, int nl, int nr) -> void {
if (x == y) return;
int mid = (x + y) / 2;
lb[mid] = x, ub[mid] = y, l[mid] = nl, r[mid] = nr;
nq.push_back(mid);
};
update(lb[k], k, l[k], idx[k] + 1);
update(k + 1, ub[k], idx[k], r[k]);
}
rep (i, n) used[i] = false;
q = nq;
}
rep (i, 1, n + 1) {
cout << ans[i] << '\n';
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7728kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 1424ms
memory: 22996kb
input:
200000 466436993 804989151 660995237 756645598 432103296 703610564 6889895 53276988 873617076 822481192 532911431 126844295 623111499 456772252 937464699 762157133 708503076 786039753 78556972 5436013 582960979 398984169 786333369 325119902 930705057 615928139 924915828 506145001 164984329 208212435...
output:
1318594 3208018 5570526 7340845 9223347 11149865 12332210 15340548 14788280 16172895 20191467 19336633 20693779 26188993 23389851 25073157 32634854 28509336 30294967 42390625 33976461 35893858 44732441 39588384 41470886 53695832 45309771 47309654 58053996 50417767 52079411 61915560 55190044 56577630...
result:
wrong answer 8th lines differ - expected: '13476823', found: '15340548'