QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#708359 | #7523. Partially Free Meal | test_algth | WA | 434ms | 108984kb | C++14 | 3.2kb | 2024-11-03 21:44:16 | 2024-11-03 21:44:17 |
Judging History
answer
#include <bits/stdc++.h>
const int MAXN = 2.01E5;
using i64 = long long;
i64 f[MAXN];
int A[MAXN], B[MAXN], C[MAXN], rt[MAXN], D[MAXN], E[MAXN];
std::vector <int> pos[MAXN];
int N, top2, top;
struct Node {
int cnts;
i64 value;
Node() {}
Node(int a, i64 b) : cnts(a), value(b) {}
friend Node operator + (const Node& x, const Node& y) {
return Node(x.cnts + y.cnts, x.value + y.value);
}
friend Node operator - (const Node& x, const Node& y) {
return Node(x.cnts - y.cnts, x.value - y.value);
}
};
struct SEG {
struct tree {
int ls, rs;
Node values;
};
tree seg[MAXN * 50];
int tot = 1;
inline Node update(Node x, int k) {
if (k > x.cnts) return x;
return Node(k, x.value / x.cnts * k);
}
int Ins(int o, int l, int r, int p, Node ad) {
int now = ++tot, mid = l + r >> 1;
seg[now] = seg[o];
if (l == r) return seg[now].values = seg[now].values + ad, now;
if (p <= mid) seg[now].ls = Ins(seg[now].ls, l, mid, p, ad);
else seg[now].rs = Ins(seg[now].rs, mid + 1, r, p, ad);
seg[now].values = seg[seg[now].ls].values + seg[seg[now].rs].values;
return now;
}
Node query(int o, int l, int r, int k) {
if (!o) return Node(0, 0);
if (l == r) return update(seg[o].values, k);
int mid = l + r >> 1, lValues = seg[seg[o].ls].values.cnts;
if (k <= lValues)
return query(seg[o].ls, l, mid, k);
return seg[seg[o].ls].values + query(seg[o].rs, mid + 1, r, k - lValues);
}
} seg;
inline int findBest(int now, int l, int r) {
int bestPos = -1;
i64 bestAns = 1e18;
for (int i = l; i <= r; ++i) {
auto res = seg.query(rt[i], 1, top2, now);
if (res.cnts < now) continue;
assert(res.cnts == now);
if (res.value + C[i] < bestAns)
bestAns = res.value + C[i], bestPos = l;
}
f[now] = std::min(bestAns, f[now]);
return bestPos;
}
void solve(int l, int r, int ansL, int ansR) {
if (ansL > ansR) return ;
if (l == r) {
for (int i = ansL; i <= ansR; ++i) {
Node res = seg.query(rt[l], 1, top2, i);
if (res.cnts == i)
f[i] = std::min(f[i], res.value + C[l]);
}
return ;
}
int mid = ansL + ansR >> 1;
int best = findBest(mid, l, r);
solve(l, best, ansL, mid - 1);
solve(best, r, mid + 1, ansR);
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
std::cin >> N;
for (int i = 1; i <= N; ++i) {
std::cin >> A[i] >> B[i];
C[i] = B[i];
D[i] = A[i];
f[i] = 1e18;
}
std::sort(C + 1, C + 1 + N);
std::sort(D + 1, D + 1 + N);
top = std::unique(C + 1, C + 1 + N) - C - 1;
top2 = std::unique(D + 1, D + 1 + N) - D - 1;
for (int i = 1; i <= N; ++i) {
int rk = std::lower_bound(C + 1, C + 1 + top, B[i]) - C;
pos[rk].push_back(i);
E[i] = std::lower_bound(D + 1, D + 1 + top2, A[i]) - D;
}
for (int i = 1; i <= top; ++i) {
rt[i] = rt[i - 1];
for (int a : pos[i]) {
rt[i] = seg.Ins(rt[i], 1, top2, E[a], Node(1, A[a]));
}
}
solve(1, top, 1, N);
for (int i = 1; i <= N; ++i) {
std::cout << f[i] << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 15932kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 434ms
memory: 108984kb
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:
350098164 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000...
result:
wrong answer 1st lines differ - expected: '1318594', found: '350098164'