QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#537629#7512. Almost Prefix ConcatenationOIer_kzc#WA 0ms3576kbC++172.8kb2024-08-30 17:00:382024-08-30 17:00:39

Judging History

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

  • [2024-08-30 17:00:39]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3576kb
  • [2024-08-30 17:00:38]
  • 提交

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);
}

struct Dat {
	int c; LL d;
	bool operator < (const Dat &t) const {
		return c < t.c || c == t.c && d < t.d;
	}
	Dat operator + (int tc) const {
		return (Dat){c + tc, d};
	}
} q[N];

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

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];
		q[i] = qry(rt[x], md - w[x].b);
		maxc = max(maxc, q[i].c);
	}
	
	vector<int> nv;
	Dat t = (Dat){-1, -1};
	for (int i = 0; i < v.size(); ++i) {
		if (!(q[i] < t)) {
			nv.eb(v[i]);
			t = q[i];
		}
	}
	solve(l, maxc, vl, md, nv);
	
	nv.clear();
	t = (Dat){-1, -1};
	for (int i = v.size() - 1; ~i; --i) {
		if (t < q[i]) {
			nv.eb(v[i]);
			t = q[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: 0
Wrong Answer
time: 0ms
memory: 3576kb

input:

ababaab
aba

output:


result:

wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements