QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#720258#7523. Partially Free Mealcyb1010WA 814ms152548kbC++172.0kb2024-11-07 11:27:052024-11-07 11:27:06

Judging History

你现在查看的是最新测评结果

  • [2024-11-07 11:27:06]
  • 评测
  • 测评结果:WA
  • 用时:814ms
  • 内存:152548kb
  • [2024-11-07 11:27:05]
  • 提交

answer

/**
 * @author : cyb1010
 * @date   : 2024-11-07 11:07:20
 * @file   : sales.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
#define ALL(v) (v).begin(), (v).end()
#define SZ(v) int(v.size())
typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
void ckmx(int &x, int y) { x < y && (x = y); }
void ckmn(int &x, int y) { x > y && (x = y); }
const int N = 200010, V = 1e9 + 10;
const ll inf = 1e16;
int __, n;
ll f[N];
pair<int, int> a[N];

struct node {
    int l, r, cnt;
    ll sum;
} t[N * 31];
int rt[N], tot;
int ins(int p, int l, int r, int k) {
    int res = ++tot, mid = l + r >> 1;
    t[res] = t[p], t[res].cnt++, t[res].sum += k;
    if (l < r)
        k <= mid ? (t[res].l = ins(t[p].l, l, mid, k))
                 : (t[res].r = ins(t[p].r, mid + 1, r, k));
    return res;
}
ll qsum(int p, int l, int r, int k) {
    if (l == r) return k * l;
    int mid = l + r >> 1;
    if (t[t[p].l].cnt >= k) return qsum(t[p].l, l, mid, k);
    return t[t[p].l].sum + qsum(t[p].r, mid + 1, r, k - t[t[p].l].cnt);
}

ll qry(int x, int y) { return a[x].fi + qsum(rt[x], 0, V, y); }
void solve(int l, int r, int L, int R) {
    if (l > r) return;
    int mid = l + r >> 1, pos = 0;
    for (int i = max(L, mid), v; i <= R; i++)
        if ((v = qry(i, mid)) < f[mid]) f[mid] = v, pos = i;
    solve(l, mid - 1, L, pos), solve(mid + 1, r, pos, R);
}
int main() {
    // fo("sales");
    cin.tie(0)->sync_with_stdio(0);
    cin >> n;
    // for (int i = 1; i <= n; i++) cin >> a[i].fi;
    // for (int i = 1; i <= n; i++) cin >> a[i].se;
    for (int i = 1; i <= n; i++) cin >> a[i].se >> a[i].fi;
    sort(a + 1, a + 1 + n), fill(f + 1, f + 1 + n, inf);
    for (int i = 1; i <= n; i++) rt[i] = ins(rt[i - 1], 0, V, a[i].se);
    solve(1, n, 1, n);
    for (int i = 1; i <= n; i++) cout << f[i] << '\n';
    return 0 ^ __ ^ 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5744kb

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 814ms
memory: 152548kb

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:

7131603
199412501
472546668
822642037
1470093901
-2006118473
-1999885459
-1858028972
-1507003532
-1604804894
-2108901488
-1862562255
-2000686265
-1975547702
-1887329288
-2101503281
-2128208538
-2109615271
-2108466156
-2138244721
-1997657005
-2116267810
-2055462072
-2113623977
-2038375143
-2128494159...

result:

wrong answer 1st lines differ - expected: '1318594', found: '7131603'