QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#549553 | #7523. Partially Free Meal | ccsurzw | WA | 598ms | 100500kb | C++20 | 2.7kb | 2024-09-06 17:26:31 | 2024-09-06 17:26:31 |
Judging History
answer
#include <array>
#include <iostream>
#include <algorithm>
#include <assert.h>
using namespace std;
typedef long long ll;
const int N = 2e5 + 3;
const int M = 1e7;
const ll INF = 5e18;
array<int, 2> a[N];
namespace persistentWeightSegmentTree
{
int tot, q, rt[N], C[N];
struct node
{
int l, r, num;
ll sum;
} st[M];
void modify(int& id, int pre, int l, int r, int pos, int val)
{
id = ++tot;
st[id] = st[pre];
++st[id].num;
st[id].sum += val;
if (l == r)
return;
int mid = (l + r) / 2;
if (pos <= mid)
modify(st[id].l, st[id].l, l, mid, pos, val);
else
modify(st[id].r, st[id].r, mid + 1, r, pos, val);
}
void init(int n)
{
tot = 0;
for (int i = 1; i <= n; ++i)
C[i] = a[i][1];
sort(C + 1, C + n + 1);
q = unique(C + 1, C + n + 1) - C - 1;
for (int i = 1; i <= n; ++i)
modify(rt[i], rt[i - 1], 1, q, lower_bound(C + 1, C + q + 1, a[i][1]) - C, a[i][1]);
assert(tot < M);
}
ll query(int u, int v, int l, int r, int k)
{
if (st[v].num - st[u].num <= k)
return st[v].sum - st[u].sum;
else if (l == r)
return (st[v].sum - st[u].sum) / (ll)(st[v].num - st[u].num) * (ll)k;
int mid = (l + r) / 2, x = st[st[v].l].num - st[st[u].l].num;
ll res = query(st[u].l, st[v].l, l, mid, k);
if (x < k)
res += query(st[u].r, st[v].r, mid + 1, r, k - x);
return res;
}
ll ask(int l, int r, int k)
{
return query(rt[l - 1], rt[r], 1, q, k);
}
};
ll ans[N];
struct T {
ll v, i;
bool operator<(const T b) {
return v < b.v;
}
}b[N];
void solve()
{
int n, hash[N];
cin >> n;
for (int i = 1; i <= n; ++i)
{
cin >> a[i][1] >> a[i][0];
hash[i] = 100;
ans[i] = 1e18;
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i)
{
b[i].v = a[i][1] + a[i][0];
b[i].i = i;
}
sort(b + 1, b + 1 + n);
persistentWeightSegmentTree::init(n);
int l = 1, r = 1;
for (int i = 1; i <= n; i++) {
if (r > b[i].i)continue;
r = b[i].i;
for (int k = 1; k <= r; ++k)
{
ll val = persistentWeightSegmentTree::ask(1, k - 1, r - 1) + b[i].v;
ans[k] = min(ans[k], val);
hash[k]--;
}
while (hash[l] <= 0)l++;
}
for (int i = 1; i <= n; ++i)
cout << ans[i] << "\n";
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 9768kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 598ms
memory: 100500kb
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 351413963 543694861 816829028 1635583950 2283035814 2290157528 2296389378 2438238136 3380243284 3731261565 3890078844 4452213643 4530698209 4669868592 5219159034 5749963609 6742618015 7241388621 7729213573 8317935572 8905796223 9851574351 10097902766 10290621110 10830434951 10987394092 11432...
result:
wrong answer 2nd lines differ - expected: '3208018', found: '351413963'