QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#537609#7523. Partially Free MealOIer_kzc#WA 1ms8132kbC++172.6kb2024-08-30 16:37:342024-08-30 16:37:34

Judging History

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

  • [2024-08-30 16:37:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:8132kb
  • [2024-08-30 16:37:34]
  • 提交

answer

#include <stdio.h>
#include <string.h>

#include <vector>
#include <algorithm>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

#define eb emplace_back

using namespace std;

typedef long long LL;
constexpr int N = 200005, TC = 30 * N;

int n;
struct Pair {
	int a, b, k;
} w[N];
bool cmpA(const Pair &x, const Pair &y) {
	return x.a < y.a;
}
bool cmpB(const Pair &x, const Pair &y) {
	return x.b < y.b;
}

#define L (tr[z].l)
#define R (tr[z].r)

struct Tree {
	int l, r, c; LL v;
} tr[TC];
int rt[N], ids;

void mdf(int &z, int x, int c, int l = 0, int r = n) {
	z = ++ids;
	tr[z].v = c;
	tr[z].c = 1;
	if (l == r) {
		return;
	}
	int mid = l + r >> 1;
	if (x <= mid) {
		mdf(L, x, c, l, mid);
	} else {
		mdf(R, x, c, mid + 1, r);
	}
}

void merge(int &y, int x, int l = 0, int r = n) {
	if (!x) {
		return;
	}
	if (!y) {
		y = x;
		return;
	}
	tr[y].v += tr[x].v;
	tr[y].c += tr[x].c;
	if (l == r) {
		return;
	}
	int mid = l + r >> 1;
	merge(tr[y].l, tr[x].l, l, mid);
	merge(tr[y].r, tr[x].r, mid + 1, r);
}

int qry(int z, LL v, int l = 0, int r = n) {
	if (l == r) {
		return 0;
	}
	int mid = l + r >> 1;
	if (tr[L].v <= v) {
		return tr[L].c + qry(R, v - tr[L].v, mid + 1, r);
	}
	return qry(L, v, l, mid);
}

int c[N];
LL res[N];

void solve(int l, int r, LL vl, LL vr, const vector<int> &v) {
	if (l > r) {
		return;
	}
	if (vl == vr) {
		for (int k = l; k <= r; ++k) {
			res[k] = vr;
		}
		return;
	}
	LL md = (vl + vr) >> 1;
	int maxc = 0;
	for (int i = 0; i < v.size(); ++i) {
		int x = v[i];
		c[i] = qry(rt[x], md - w[x].b);
		maxc = max(maxc, c[i]);
	}
	
	vector<int> nv;
	int mx = -1;
	for (int i = 0; i < v.size(); ++i) {
		if (c[i] >= mx) {
			nv.eb(v[i]);
			mx = c[i];
		}
	}
	solve(l, maxc, vl, md, nv);
	
	nv.clear();
	mx = -1;
	for (int i = v.size() - 1; ~i; --i) {
		if (c[i] > mx) {
			nv.eb(v[i]);
			mx = c[i];
		}
	}
	reverse(nv.begin(), nv.end());
	solve(maxc + 1, r, md + 1, vr, nv);
}

int main() {
	scanf("%d", &n);
	LL suma = 0; int maxb = 0;
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d", &w[i].a, &w[i].b);
		suma += w[i].a;
		maxb = max(maxb, w[i].b);
	}
	sort(w + 1, w + n + 1, cmpA);
	for (int i = 1; i <= n; ++i) {
		w[i].k = i - 1;
	}
	sort(w + 1, w + n + 1, cmpB);
	for (int i = 1; i <= n; ++i) {
		mdf(rt[i], w[i].k, w[i].a);
		merge(rt[i], rt[i - 1]);
	}
	vector<int> v(n);
	iota(v.begin(), v.end(), 1);
	solve(1, n, 0, suma + maxb, v);
	for (int i = 1; i <= n; ++i) {
		printf("%lld\n", res[i]);
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 8132kb

input:

3
2 5
4 3
3 7

output:

7
12
16

result:

wrong answer 2nd lines differ - expected: '11', found: '12'