我真的无语,为什么编译失败连原因都没给?
查看原帖
我真的无语,为什么编译失败连原因都没给?
682314
influ3nza楼主2022/3/29 22:09
#include <iostream>
#include <cstdio>
using namespace std;

#define lowbit(x) ((x) & (-x))
const int MAX = 1e6 + 5;

struct BIT {
	int low = 2e6;
	int high = -2e6;
	int val = 0;
}tree[MAX];

void build(int pos, int value) {
	tree[pos].val = value;
	for (int x = pos; x < MAX; x += lowbit(x)) {
		tree[x].high = max(tree[x].high, value);
		tree[x].low = min(tree[x].low, value);
	}
}

bool inquire(int left, int right, int gap) {
	int low = 2e6;
	int high = -2e6;
	while (left <= right) {
		for (; right - lowbit(right) >= left; right -= lowbit(right)) {
			low = min(low, tree[right].low);
			high = max(high, tree[right].high);
		}
		low = min(low, tree[right].val);
		high = max(high, tree[right].val);
		right--;
	}
	if (abs(low - high) <= gap) return true;
	return false;
}

int main() {
	int n, m, c;
	scanf("%d%d%d", &n, &m, &c);
	int x;
	int cnt = 0;
	for (int i = 1; i <= n; i++) {
		scanf("%d", &x);
		build(i, x);
	}
	for (int i = 1; i <= n - m + 1; i++) {
		if (inquire(i, i + m - 1, c)) {
			printf("%d", i);
			cnt++;
		}
	}
	if (cnt == 0) printf("NONE");
}

调了不知道多久了,初步感觉是爆栈了,但是我看题解里面都可以开这么大的啊?所以是发生什么事了,萌新真的晕了。

2022/3/29 22:09
加载中...