树状数组 WA 求助
查看原帖
树状数组 WA 求助
637796
Xy_top楼主2023/7/2 15:14

rtrt,先排序,然后用类似双指针求出每个点后面 2d 个能到哪里,接着用树状数组区间修改这些怪都被扣了多少血。

每一回合先把这个怪物的血减掉之前扣的再统计。

#include <cmath>
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;
int n, d, atk, ans;
int c[200005];
struct Node {int x, h;}a[200005];
bool cmp (Node n1, Node n2) {return n1.x < n2.x;}
void add (int x, int y) {for (; x <= n; x += x & -x) c[x] += y;}
int query (int x) {
	int res = 0;
	for (; x > 0; x -= x & -x) res += c[x];
	return res;
}
signed main () {
	cin >> n >> d >> atk;
	d *= 2;
	for (int i = 1; i <= n; i ++) cin >> a[i].x >> a[i].h;
	sort (a + 1, a + n + 1, cmp);
	int r = 1;
	for (int i = 1; i <= n; i ++) {
		while (r != n && a[r + 1].x - a[i].x <= d) ++ r;
		a[i].h -= query (i);
		int tmp = ceil (a[i].h * 1.0 / atk);
		ans += tmp;
		add (i, tmp * atk);
		add (r + 1, -tmp * atk);
	}
	cout << ans;
	return 0;
}
2023/7/2 15:14
加载中...