YCOJ734 [ 20231114 NOIP 模拟赛 T3 ] 二次函数

发布时间 2023-11-14 16:27:59作者: cxqghzj

题意

给定 \(n\) 个形如 \(f(x) = (x - m) ^ 2 + k\) 的二次函数。

  • \(1, m, k\) 表示加入一个顶点位 \((m, k)\) 的二次函数。
  • \(2, x, t\) 表示删除所有 \(f(x) \le t\) 的二次函数。

求每次操作结束后还剩余几个二次函数。

Sol

注意到题中二次系数为 \(1\),这就意味着每一个函数都长得一样。

注意到是二次,固然可以发现当前的 \(x\) 距离对称轴超过 \(316\) 时,就已经超过值域限制了。

所以我们直接对于每一个 \(m\) 开一个 \(set\) 维护,每次操作直接暴力修改即可。

Code

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <array>
#include <set>
#define int long long
#define pii pair <int, int>
using namespace std;
#ifdef ONLINE_JUDGE

#define getchar() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[1 << 23], *p1 = buf, *p2 = buf, ubuf[1 << 23], *u = ubuf;

#endif
int read() {
	int p = 0, flg = 1;
	char c = getchar();
	while (c < '0' || c > '9') {
		if (c == '-') flg = -1;
		c = getchar();
	}
	while (c >= '0' && c <= '9') {
		p = p * 10 + c - '0';
		c = getchar();
	}
	return p * flg;
}
void write(int x) {
	if (x < 0) {
		x = -x;
		putchar('-');
	}
	if (x > 9) {
		write(x / 10);
	}
	putchar(x % 10 + '0');
}
const int N = 1e5 + 5;
array <set <int>, N> isl;

signed main() {
	int n = read(), q = read();
	int cur = 0;
	for (int i = 1; i <= n; i++) {
		int m = read(), k = read();
		isl[m].insert(k), cur++;
	}
	while (q--) {
		int op = read();
		if (op == 1) {
			int m = read(), k = read();
			isl[m].insert(k), cur++;
		}
		else {
			int x = read(), t = read();
			for (int i = max(1ll, x - 400); i <= min((int)1e5, x + 400); i++) {
				for (auto it = isl[i].begin(); it != isl[i].end(); ) {
					if ((x - i) * (x - i) + *it > t) break;
					it = isl[i].erase(it), cur--;
				}
			}
		}
		write(cur), puts("");
	}
	return 0;
}