QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#472490#7523. Partially Free Meal333zhanWA 394ms129652kbC++202.9kb2024-07-11 16:44:452024-07-11 16:44:46

Judging History

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

  • [2024-07-11 16:44:46]
  • 评测
  • 测评结果:WA
  • 用时:394ms
  • 内存:129652kb
  • [2024-07-11 16:44:45]
  • 提交

answer

 #include <bits/stdc++.h>
#define int long long

using namespace std;

const int N = 2E5 + 10; 
const int inf = 1E18; 

inline int read () {
    int w = 1, s = 0; char ch = getchar ();
    for (; ! isdigit (ch); ch = getchar ()) if (ch == '-') w = -1;
    for (; isdigit (ch); ch = getchar ()) s = (s << 1) + (s << 3) + (ch ^ 48);
    return s * w;
}

vector <int> all;

struct Info {
    int l, r;
    int sum = 0;
    int cnt = 0;
} tr[N * 19];

int idx = 0;

int add (int p, int l, int r, int x, int y) {
    int q = ++ idx;
    tr[q] = tr[p];
    tr[q].sum += y;
    tr[q].cnt ++;
    if (l == r) {
        return q;
    }
    int mid = (l + r) / 2;
    if (x <= mid) {
        tr[q].l = add (tr[p].l, l, mid, x, y);
    } else {
        tr[q].r = add (tr[p].r, mid + 1, r, x, y);
    }
    return q;
}

int query (int v1, int v2, int l, int r, int k) {
    if (l == r) {
        return k * all[l];
    }
    if (tr[v2].cnt - tr[v1].cnt <= k) {
        return tr[v2].sum - tr[v1].sum;
    }
    int mid = (l + r) / 2;
    int sum = tr[tr[v2].l].sum - tr[tr[v1].l].sum;
    int cnt = tr[tr[v2].l].cnt - tr[tr[v1].l].cnt;
    return sum + query (tr[v1].r, tr[v2].r, mid + 1, r, k - cnt);
}

void solve () {
	int n = read ();
	
	vector <pair <int, int>> p (n + 1);
	for (int i = 1; i <= n; i ++) {
		p[i].first = read ();
		p[i].second = read ();
		all.push_back (p[i].first);
	}
	sort (p.begin (), p.end (),
        [&] (pair <int, int> x, pair <int, int> y) {
            return x.second < y.second;
        }
    );
	
	sort (all.begin (), all.end ());
    all.erase (unique (all.begin (), all.end ()), all.end ());

	const int N = all.size ();

	auto find = [&] (int x) -> int {
        return lower_bound (all.begin (), all.end (), x) - all.begin ();// + 1;
    };

	vector <int> root (n + 1);
    for (int i = 1; i <= n; i ++) {
        root[i] = add (root[i - 1], 0, N - 1, find (p[i].first), p[i].first);
    }

    vector <int> ans (n + 1);

    auto solve = [&] (auto &&self, int al, int ar, int ql, int qr) -> void {
        if (al > ar) {
            return;
        }
        int x = (al + ar) / 2;
        int id = 0;
        int minn = inf;
        for (int i = max (x, ql); i <= qr; i ++) {
            int sum = query (root[0], root[i - 1], 0, N - 1, x - 1);
            sum += p[i].first + p[i].second;
            if (sum < minn) {
                minn = sum;
                id = i;
            }
        }
        ans[x] = minn;
        self (self, al, x - 1, ql, id);
        self (self, x + 1, ar, id, qr);
    };
    solve (solve, 1, n, 1, n);

    for (int i = 1; i <= n; i ++) {
        printf ("%lld\n", ans[i]);
    }
}

signed main () {
	// ios::sync_with_stdio (false);
    // cin.tie (nullptr);
    
	int T = 1; 
	// cin >> T;
	// T = read ();

	while (T --) {
		solve ();
	}
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 394ms
memory: 129652kb

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:

-106423878002333
-106422878005275
-106421878008217
-106420878011159
-106419878014101
-106418878017043
-106417878019985
-106416878022927
-106415878025869
-106414878028811
-106413878031753
-106412878034695
-106411878037637
-106410878040579
-106409878043521
-106408878046463
-106407878049405
-1064068780...

result:

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