QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#292599 | #7523. Partially Free Meal | cyb1010 | WA | 360ms | 153804kb | C++14 | 1.7kb | 2023-12-28 09:20:21 | 2023-12-28 09:20:21 |
Judging History
answer
/**
* @author : cyb1010
* @date : 2023-12-28 08:59:53
* @file : frog.cpp
*/
#include <bits/stdc++.h>
using namespace std;
#define fo(s) freopen(s ".in", "r", stdin), freopen(s ".out", "w", stdout)
#define fi first
#define se second
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
int __, n, tot, rt[200010], inf = 1e9;
ll ans[200010], llinf = 1e16;
pair<int, int> a[200010];
struct SMT {
int l, r, cnt;
ll sum;
} t[10000010];
int ins(int p, int l, int r, int k) {
int tmp = ++tot;
t[tmp] = t[p], t[tmp].cnt++, t[tmp].sum += k;
if (l < r) {
int mid = l + r >> 1;
k <= mid ? t[tmp].l = ins(t[p].l, l, mid, k)
: t[tmp].r = ins(t[p].r, mid + 1, r, k);
}
return tmp;
}
ll qry(int p, int k) {
if (t[p].cnt <= k) return t[p].sum;
if (t[t[p].l].cnt >= k) return qry(t[p].l, k);
return t[t[p].l].sum + qry(t[p].r, k - t[t[p].l].cnt);
}
ll w(int k, int x) {
if (k < x) return llinf;
return a[k].fi + a[k].se + qry(rt[k - 1], x - 1);
}
void solve(int l, int r, int lp, int rp) {
if (l > r) return;
int mid = l + r >> 1, pos = rp;
ans[mid] = w(rp, mid);
for (int i = lp; i < rp; i++) {
ll tmp = w(i, mid);
if (tmp < ans[mid]) ans[mid] = tmp, pos = i;
}
solve(l, mid - 1, lp, pos), solve(mid + 1, r, pos, rp);
}
int main() {
// fo("frog");
cin.tie(0)->sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) cin >> a[i].se >> a[i].fi;
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++) rt[i] = ins(rt[i - 1], 1, inf, a[i].se);
solve(1, n, 1, n);
for (int i = 1; i <= n; i++) cout << ans[i] << "\n";
return 0 ^ __ ^ 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5672kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 360ms
memory: 153804kb
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 13476823 14788280 16172895 17768627 19336633 20693779 22005236 23389851 25073157 26760338 28509336 30294967 32093959 33976461 35893858 37754030 39588384 41470886 43388283 45309771 47309654 48837539 50417767 52079411 53762717 55190044 56577630...
result:
wrong answer 25827th lines differ - expected: '894878200462', found: '894808916501'