QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#537602#7523. Partially Free MealOIer_kzc#WA 726ms100380kbC++172.6kb2024-08-30 16:27:332024-08-30 16:27:33

Judging History

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

  • [2024-08-30 16:27:33]
  • 评测
  • 测评结果:WA
  • 用时:726ms
  • 内存:100380kb
  • [2024-08-30 16:27:33]
  • 提交

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;
constexpr int dx[4] = {-1, 1, 0, 0}, dy[4] = {0, 0, -1, 1};

int n;
int ra[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;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7948kb

input:

3
2 5
4 3
3 7

output:

7
11
16

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 726ms
memory: 100380kb

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:

1318594
3208018
6227622
8110124
10374115
11259522
12332210
13476823
14788280
16172895
17856201
19549166
20693779
22005236
23389851
25073157
26760338
28509336
30294967
32093959
34154691
35953683
37788037
39670539
41587936
43509424
46244669
48030300
49829292
50499183
52079411
53762717
55449898
5705990...

result:

wrong answer 3rd lines differ - expected: '5570526', found: '6227622'