QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#208627 | #7523. Partially Free Meal | SolitaryDream# | TL | 1ms | 8040kb | C++17 | 1.6kb | 2023-10-09 19:27:45 | 2023-10-09 19:27:45 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int, int> pii;
const int N = 2e5 + 10;
namespace Seg {
const int S = N * 32;
int si[S], sm[S], c[S][2], size;
inline void Add(int &v, int x, int l = 1, int r = 1e9) {
int nv = ++size;
si[nv] = si[v]; sm[nv] = sm[v];
c[nv][0] = c[v][0]; c[nv][1] = c[v][1];
v = nv;
++si[v]; sm[v] += x;
if (l == r) return;
int mid = (l + r) >> 1;
if (x <= mid) Add(c[v][0], x, l, mid); else Add(c[v][1], x, mid + 1, r);
}
inline int Ask(int v, int k) {
if (si[v] == k) return sm[v];
if (si[c[v][0]] >= k) return Ask(c[v][0], k);
else return sm[c[v][0]] + Ask(c[v][1], k - si[c[v][0]]);
}
}
int n, ans[N];
pii a[N];
int rt[N];
inline void Solve(int l, int r, int bl, int br) {
int v = (l + r) >> 1;
int minf = 1e15, mini = -1;
for (int i = max(v, bl); i <= br; ++i) {
int curf = a[i].first + Seg::Ask(rt[i], v);
if (curf < minf) minf = curf, mini = i;
}
// printf("%lld %lld %lld\n", v, a[mini].first, minf);
ans[v] = minf;
if (l < v) Solve(l, v - 1, bl, mini);
if (v < r) Solve(v + 1, r , mini, br);
}
signed main() {
scanf("%lld", &n);
for (int i = 1; i <= n; ++i) {
scanf("%lld%lld", &a[i].second, &a[i].first);
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; ++i) Seg::Add(rt[i] = rt[i - 1], a[i].second);
Solve(1, n, 1, n);
for (int i = 1; i <= n; ++i) printf("%lld\n", ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8040kb
input:
3 2 5 4 3 3 7
output:
7 11 16
result:
ok 3 lines
Test #2:
score: -100
Time Limit Exceeded
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...