QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#561893#9242. An Easy Geometry ProblemMysterious_CatWA 8ms31364kbC++142.7kb2024-09-13 12:26:432024-09-13 12:26:44

Judging History

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

  • [2024-09-13 12:26:44]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:31364kb
  • [2024-09-13 12:26:43]
  • 提交

answer

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

const int N = 2e5 + 5;
const int base = 1e8 + 7;
const int mod[3] = {(int)1e9 + 7, (int)1e9 + 9, (int)1e9 + 23};

int n, q, k, b, pw[N][3], a[N], d[N];

struct V {
	int l, v[3];

	V (int l_ = 0, int v_ = 0) {
		l = l_;
		v[0] = v_;
		v[1] = v_;
		v[2] = v_;
	}

	V operator + (const V &b) const {
		V res;
		res.l = l + b.l;
		for (int j = 0; j < 3; j++) {
			res.v[j] = (1ll * v[j] * pw[b.l][j] + b.v[j]) % mod[j];
		}
		return res;
	}

	bool operator == (const V &b) const {
		return v[0] == b.v[0] && v[1] == b.v[1] && v[2] == b.v[2];
	}
} val[N * 4][2];

void build(int p, int l, int r) {
	if (l == r) {
		val[p][0] = V(1, d[l]);
		val[p][1] = V(1, k - d[l]);
		return;
	}
	int mid = l + r >> 1;
	build(p * 2, l, mid);
	build(p * 2 + 1, mid + 1, r);
	val[p][0] = val[p * 2][0] + val[p * 2 + 1][0];
	val[p][1] = val[p * 2][1] + val[p * 2 + 1][1];
}

void modify(int p, int l, int r, int x) {
	if (l == r) {
		val[p][0] = V(1, d[x]);
		val[p][1] = V(1, k - d[x]);
		return;
	}
	int mid = l + r >> 1;
	if (x <= mid) {
		modify(p * 2, l, mid, x);
	} else {
		modify(p * 2 + 1, mid + 1, r, x);
	}
	val[p][0] = val[p * 2][0] + val[p * 2 + 1][0];
	val[p][1] = val[p * 2][1] + val[p * 2 + 1][1];
}

V query(int p, int l, int r, int a, int b, int t) {
	if (l >= a && r <= b) {
		return val[p][t];
	}
	int mid = l + r >> 1;
	if (b <= mid) {
		return query(p * 2, l, mid, a, b, t);
	} else if (a > mid) {
		return query(p * 2 + 1, mid + 1, r, a, b, t);
	} else {
		return query(p * 2, l, mid, a, b, t) + query(p * 2 + 1, mid + 1, r, a, b, t);
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n >> q >> k >> b;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int j = 0; j < 3; j++) {
		pw[0][j] = 1;
		for (int i = 1; i <= n; i++) {
			pw[i][j] = 1ll * pw[i - 1][j] * base % mod[j];
		}
	}
	for (int i = 1; i < n; i++) {
		d[i] = a[i + 1] - a[i];
	}
	build(1, 1, n - 1);
	for (int i = 1; i <= q; i++) {
		int op;
		cin >> op;
		if (op == 1) {
			int l, r, v;
			cin >> l >> r >> v;
			if (l - 1 >= 1) {
				d[l - 1] += v;
				modify(1, 1, n - 1, l - 1);
			}
			if (r < n) {
				d[r] -= v;
				modify(1, 1, n - 1, r);
			}
		} else {
			int x;
			cin >> x;
			if (x == 1 || x == n || d[x - 1] + d[x] != k + b) {
				cout << "0\n";
			} else if (x == 2 || x == n - 1 || d[x - 2] + d[x + 1] != k) {
				cout << "1\n";
			} else {
				int l = 2, r = min(x - 1, n - x);
				while (l < r) {
					int mid = l + r + 1 >> 1;
					if (query(1, 1, n - 1, x - l, x - 2, 1) == query(1, 1, n - 1, x + 1, x + l - 1, 0)) {
						l = mid;
					} else {
						r = mid - 1;
					}
				}
				cout << l << '\n';
			}
		}
	}

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 31364kb

input:

6 6 6 2
1 5 9 10 15 18
2 2
1 3 3 -3
2 2
1 3 4 3
2 3
2 4

output:

1
0
2
0

result:

ok 4 number(s): "1 0 2 0"

Test #2:

score: -100
Wrong Answer
time: 8ms
memory: 30356kb

input:

5000 5000 2 0
-329 -328 -327 -326 -325 -324 -323 -322 -321 -320 -319 -318 -317 -316 -315 -314 -313 -312 -311 -310 -309 -308 -307 -306 -305 -304 -303 -302 -301 -300 -299 -298 -297 -296 -295 -294 -293 -292 -291 -290 -289 -288 -287 -286 -285 -284 -283 -282 -281 -280 -279 -278 -277 -276 -275 -274 -273 -...

output:

942
1051
399
423
854
1045
754
281
88
991
359
905
519
797
463
408
1121
914
523
1052
448
302
835
295
1040
737
891
1
924
1226
468
989
351
869
804
376
542
171
963
186
1
708
507
672
22
205
893
1135
423
1
1023
1000
766
826
460
783
1078
419
119
798
234
825
475
560
534
446
32
1164
526
1074
526
509
59
1157
5...

result:

wrong answer 1st numbers differ - expected: '2', found: '942'