QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#525512#8727. DvobojGrand_ElfCompile Error//C++171001b2024-08-20 17:22:472024-08-20 17:22:48

Judging History

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

  • [2024-08-20 17:22:48]
  • 评测
  • [2024-08-20 17:22:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

const int N = 2e5 + 5;

int n, q, a[N], Left[N][9];

int solve(int l, int k) {
	if (k <= 8) {
		return Left[l][k];
	}
	return abs(solve(l, k - 1) - solve(l + (1 << k - 1), k - 1));
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> q;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		Left[i][0] = a[i];
	}
	for (int j = 1; j <= 8; j++) {
		for (int i = 1; i + (1 << j) - 1 <= n; i++) {
			Left[i][j] = abs(Left[i][j - 1] - Left[i + (1 << j - 1)][j - 1]);
		}
	}
	for (int i = 1; i <= q; i++) {
		int op;
		cin >> op;
		if (op == 1) {
			int x, v;
			cin >> x >> v;
			a[x] = v;
			Left[x][0] = a[x];
			for (int j = 1; j <= 8; j++) {
				for (int i = max(x - (1 << k) + 1, 1); i <= min(x, n - (1 << k) + 1); i++) {
					Left[i][j] = abs(Left[i][j - 1] - Left[i + (1 << j - 1)][j - 1]);
				}
			}
		} else {
			int l, k;
			cin >> l >> k;
			cout << solve(l, k) << '\n';
		}
	}

	return 0;
}

Details

answer.code: In function ‘int main()’:
answer.code:36:60: error: ‘k’ was not declared in this scope
   36 |                                 for (int i = max(x - (1 << k) + 1, 1); i <= min(x, n - (1 << k) + 1); i++) {
      |                                                            ^