QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#670713#9242. An Easy Geometry ProblemAndycraftWA 376ms41108kbC++206.5kb2024-10-23 23:29:312024-10-23 23:29:31

Judging History

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

  • [2024-10-23 23:29:31]
  • 评测
  • 测评结果:WA
  • 用时:376ms
  • 内存:41108kb
  • [2024-10-23 23:29:31]
  • 提交

answer

#define DEBUG 0
#define LOCAL 0
#define LOCAL_DEBUG 0
#define MBF 0
#include <iostream>
#include <algorithm>
#include <chrono>
#include <random>
#include <cassert>
#include <vector>
typedef long long LL;
template <class T> using Arr = std::vector<T>;
const int base = 998244353;
typedef long long LL;
#define MID ((l + r) >> 1)
#define LS (p << 1)
#define RS (LS | 1)
const long long MOD = 100055128505716009l;

int Rand() {
	std::mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
	int r = rng();
	return r < 0 ? -r : r;
}
int Rand(int l, int r) { return Rand() % (r - l + 1) + l; }

#if 1
typedef unsigned long long ULL;
#else
struct ULL {
	long long _;
	ULL(long long __) : _(__) {}
	ULL() : _(0) {}
	friend ULL operator+(ULL u, ULL v) { return (u._ + v._) % MOD; }
	friend ULL &operator+=(ULL &u, ULL v) { return u = ((u._ + v._) % MOD); }
	friend ULL &operator*=(ULL &u, ULL v) { return u = u * v; }
	friend ULL operator-(ULL u, ULL v) { return (u._ - v._) % MOD; }
	friend ULL operator*(ULL u, ULL v) { return (ULL)((__int128(u._) * v._) % MOD); }
	friend bool operator!=(ULL u, ULL v) { return (u._ % MOD + MOD) % MOD != (v._ % MOD + MOD) % MOD; }
	friend bool operator==(ULL u, ULL v) { return (u._ % MOD + MOD) % MOD == (v._ % MOD + MOD) % MOD; }
};
#endif

const int MAXN = 200002;
const int B = 5e8;
int n, q, K, b;
int a[MAXN];
ULL pw[MAXN], ppw[MAXN];
ULL tr1[MAXN << 2], tag1[MAXN << 2], add1[MAXN << 2], hash1[MAXN];
ULL tr2[MAXN << 2], tag2[MAXN << 2], add2[MAXN << 2], hash2[MAXN];

void build(ULL tr[], ULL hash[], int p, int l, int r) {
	if (l == r) {
		tr[p] = hash[l];
		return;
	}
	build(tr, hash, LS, l, MID);
	build(tr, hash, RS, MID + 1, r);
}

ULL cons(int l, int r) {
	return ppw[r - l] * pw[l];
}

ULL ask(ULL tr[], ULL tag[], ULL add[], int p, int l, int r, int ps) {
	if (ps < l || ps > r)
		return 0;
	ULL delta = tag[p] * cons(l, ps) + add[p];
	if (l == r)
		return tr[p] + delta;
	return delta + (ask(tr, tag, add, LS, l, MID, ps) + ask(tr, tag, add, RS, MID + 1, r, ps));
}

ULL ask_int(int l, int r, ULL tr[], ULL tag[], ULL add[]) {
	ULL ls = ask(tr, tag, add, 1, 1, n, l - 1);
	ULL rs = ask(tr, tag, add, 1, 1, n, r);
	// printf("ask_int %d %d %llu %llu\n", l, r, ls, rs);
	return rs - ls;
}

void add_add(ULL add[], int p, int l, int r, int lp, int rp, ULL v) {
	if (rp < l || lp > r)
		return;
	if (lp <= l && r <= rp) {
		add[p] += v;
		return;
	}
	add_add(add, LS, l, MID, lp, rp, v);
	add_add(add, RS, MID + 1, r, lp, rp, v);
}

void add_tag(ULL add[], ULL tag[], int p, int l, int r, int lp, int rp, ULL v) {
	if (rp < l || lp > r)
		return;
#if LOCAL_DEBUG
	printf("add_tag %d %d %d\n", p, l, r);
#endif
	if (lp <= l && r <= rp) {
		tag[p] += v;
		return;
	}
	add_tag(add, tag, LS, l, MID, lp, rp, v);
	add_tag(add, tag, RS, MID + 1, r, lp, rp, v);
	if (rp >= MID + 1 && lp <= MID)
		add_add(add, RS, MID + 1, r, MID + 1, rp, v * cons(std::max(lp, l), MID));
}

#if MBF
struct BF_t {
	Arr<int> a;
	void init() {
		a.resize(n);
		for (int i = 0; i < n; ++i)
			a[i] = (::a[i + 1] - B + K * (i + 1)) / 2;
	}
	void op1(int l, int r, int v) {
		for (int i = l - 1; i < r; ++i)
			a[i] += v;
#if LOCAL_DEBUG
		printf("* ");
		for (int i = 0; i < n; ++i)
			printf("%d ", a[i]);
		puts("");
		Arr<ULL> hash(n + 1);
		for (int i = 0; i < n; ++i) {
			hash[i + 1] = hash[i] + (a[i] * 2 - K * (i + 1) + B + 2 * b) * pw[i + 1];
			ULL LHS = hash[i + 1], RHS = ask(tr1, tag1, add1, 1, 1, n, i + 1);
			printf("[] %d %llu %llu\n", i + 1, LHS, RHS);
			assert(LHS == RHS);
		}
#endif
	}
	int op2(int p) {
		int r = 1;
		for (--p; p - r >= 0 && p + r < n && a[p + r] - a[p - r] == K * r + b; ++r)
			;
		return r - 1;
	}
} BF;
#endif

int main() {
	std::ios::sync_with_stdio(false);
#if LOCAL
	n = 30, q = 100, K = 0, b = Rand(-10, 10);
	printf("%d %d %d %d\n", n, q, K, b);
#else
	std::cin >> n >> q >> K >> b;
#endif
	for (int i = 1; i <= n; ++i) {
#if LOCAL
		a[i] = Rand(-10, 10);
		printf("%d ", a[i]);
#else
		std::cin >> a[i];
#endif
		a[i] = a[i] * 2 - K * i;
		a[i] += B;
		assert(a[i] > 0);
	}
#if LOCAL
	puts("");
#endif
#if MBF
	BF.init();
#endif
	pw[0] = 1;
	ppw[0] = 1;
	for (int i = 1; i < MAXN; ++i) {
		pw[i] = pw[i - 1] * base;
		ppw[i] = ppw[i - 1] + pw[i];
	}
	for (int i = 1; i <= n; ++i)
		hash1[i] = hash1[i - 1] + pw[i] * (a[i] + 2 * b);
	for (int i = 1; i <= n; ++i)
		hash2[i] = hash2[i - 1] + pw[i] * a[n - i + 1];
	build(tr1, hash1, 1, 1, n);
	build(tr2, hash2, 1, 1, n);
	// puts("HELLO");
#if DEBUG
	for (int i = 1; i <= n; ++i)
		printf("%llu ", hash1[i]);
	puts("");
	printf("! %llu %llu\n", hash1[2] * pw[5], (hash2[6] - hash2[4]) * pw[1]);
	for (int i = 1; i <= n; ++i)
		printf("%llu ", hash2[i]);
	puts("");
	for (int i = 1; i <= n; ++i)
		printf("%llu ", ask(tr1, tag1, add1, 1, 1, n, i));
	puts("");
#endif
	for (int i = 1; i <= q; ++i) {
		int op;
#if LOCAL
		op = Rand(1, 2);
		printf("%d ", op);
#else
		std::cin >> op;
#endif
		if (op == 1) {
			int l, r, v;
#if LOCAL
			l = Rand(1, n), r = Rand(1, n);
			if (l > r)
				std::swap(l, r);
			v = Rand(-10, 10);
			printf("%d %d %d\n", l, r, v);
#else
			std::cin >> l >> r >> v;
#endif
			v *= 2;
			add_tag(add1, tag1, 1, 1, n, l, r, v);
			add_tag(add2, tag2, 1, 1, n, n - r + 1, n - l + 1, v);
			add_add(add1, 1, 1, n, r + 1, n, v * cons(l, r));
			add_add(add2, 1, 1, n, n - l + 2, n, v * cons(n - r + 1, n - l + 1));
#if MBF
			BF.op1(l, r, v / 2);
#endif
		} else {
			int x;
#if LOCAL
			x = Rand(1, n);
			printf("%d\n", x);
#else
			std::cin >> x;
#endif
#if MBF
			int mbf = BF.op2(x);
#endif
			int h = 0;
			for (; x - (1 << h) >= 1 && x + (1 << h) <= n; ++h) {
				int lp = x - (1 << h), rp = x + (1 << h);
				ULL l = ask_int(lp, x - 1, tr1, tag1, add1);
				ULL r = ask_int(n - rp + 1, n - (x + 1) + 1, tr2, tag2, add2);
#if DEBUG
				printf("== %llu %llu\n", l, r);
#endif
				// l += 2 * b * cons(lp, x - 1);
				l *= pw[n - rp + 1];
				r *= pw[lp];
#if DEBUG
				printf("= %llu %llu\n", l, r);
#endif
				if (l != r)
					break;
			}
			if (h == 0) {
#if MBF
				if (mbf)
					printf("= %d\n", mbf);
				assert(mbf == 0);
#endif
				puts("0");
				continue;
			}
			int ans = 1 << (h - 1);
			for (--h; h >= 0; --h) {
				int lp = x - (ans + (1 << h));
				int rp = x + (ans + (1 << h));
				if (lp < 1 || rp > n)
					continue;
				ULL l = ask_int(lp, x - 1, tr1, tag1, add1);
				ULL r = ask_int(n - rp + 1, n - (x + 1) + 1, tr2, tag2, add2);
				// l += 2 * b * cons(lp, x - 1);
				l *= pw[n - rp + 1];
				r *= pw[lp];
				// printf("# %llu %llu\n", l, r);
				if (l == r)
					ans += (1 << h);
			}
#if MBF
			assert(ans == mbf);
#endif
			printf("%d\n", ans);
		}
	}
	return 0;
}

详细

Test #1:

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

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: 0
Accepted
time: 10ms
memory: 12756kb

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:

2
304
73
29
61
292
139
48
17
99
6
5
53
93
3
91
65
29
33
306
21
24
17
21
281
12
16
1
33
7
18
96
7
40
39
13
7
46
43
16
1
72
33
16
22
5
6
189
27
1
35
107
43
34
3
27
20
21
44
56
96
36
2
27
22
30
32
6
5
105
27
37
12
58
2
21
154
17
110
57
3
7
33
15
24
94
68
25
1
14
10
4
10
2
25
39
36
33
164
11
19
181
11
3...

result:

ok 3337 numbers

Test #3:

score: 0
Accepted
time: 7ms
memory: 20488kb

input:

5000 5000 2 0
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 86...

output:

362
82
14
234
140
5
44
136
22
43
29
96
59
23
25
61
193
22
39
39
23
53
48
76
100
58
120
24
12
106
32
48
73
63
116
16
136
10
28
15
84
30
65
1
54
15
16
70
1
95
74
14
17
20
36
254
22
29
70
172
106
2
25
8
98
35
169
16
2
2
99
10
36
40
3
69
272
170
219
12
79
26
78
100
10
167
140
70
34
17
23
21
55
10
6
17
6...

result:

ok 3313 numbers

Test #4:

score: 0
Accepted
time: 10ms
memory: 12548kb

input:

5000 5000 2 0
-456 -455 -454 -453 -452 -451 -450 -449 -448 -447 -446 -445 -444 -443 -442 -441 -440 -439 -438 -437 -436 -435 -434 -433 -432 -431 -430 -429 -428 -427 -426 -425 -424 -423 -422 -421 -420 -419 -418 -417 -416 -415 -414 -413 -412 -411 -410 -409 -408 -407 -406 -405 -404 -403 -402 -401 -400 -...

output:

8
75
80
408
385
73
37
402
338
43
11
163
3
7
80
0
339
47
384
8
10
47
162
307
30
28
36
14
27
126
271
151
4
11
11
9
92
154
2
15
28
160
205
12
59
79
114
23
22
141
7
12
31
42
120
0
34
2
167
157
76
32
20
298
47
104
76
33
49
34
1
40
16
1
28
7
4
55
14
8
68
17
7
117
1
14
14
80
44
8
45
49
65
15
49
56
50
40
14...

result:

ok 3296 numbers

Test #5:

score: 0
Accepted
time: 268ms
memory: 40252kb

input:

200000 199999 -195 -119
-267 -146 191 -456 835 265 -226 -264 160 -101 739 -988 -967 890 -753 -854 514 491 -733 662 681 -362 804 -714 -1000 -790 931 -450 212 94 239 638 400 -167 -360 18 606 256 445 695 -509 643 -892 213 -32 42 400 733 -667 -986 225 493 -699 547 409 -35 394 920 -163 -908 -576 921 -997...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 133315 numbers

Test #6:

score: 0
Accepted
time: 269ms
memory: 39864kb

input:

200000 200000 -847 -858
977 -248 439 -318 -623 -838 -996 484 415 -888 550 940 -880 -224 95 666 -898 -36 922 346 538 858 619 771 234 909 182 -577 -399 -793 -217 -150 -805 -22 -35 -818 342 -469 -620 778 855 -156 699 464 923 935 -824 315 -156 -222 55 282 -800 -542 192 -358 -158 79 259 -57 842 -882 -690...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 133062 numbers

Test #7:

score: 0
Accepted
time: 272ms
memory: 41108kb

input:

199994 199991 -131 936
-384 633 390 191 -647 79 -481 -95 -719 -131 -225 654 392 -232 390 -520 671 440 814 95 945 -854 477 304 -29 -884 -823 -798 -386 -404 614 -875 -792 -630 875 -379 -412 -464 805 -749 952 -737 -765 -36 295 -20 571 419 -519 763 505 803 -14 307 -979 955 743 -210 159 935 499 13 -750 -...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 133017 numbers

Test #8:

score: -100
Wrong Answer
time: 376ms
memory: 40636kb

input:

200000 200000 448 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...

output:

5388
1796
9803
17353
10388
6660
29833
1132
10416
3492
28995
2953
5964
9845
4293
158
931
30
224
7765
7894
2412
21159
21128
8630
4778
3830
1241
3750
795
5013
529
2176
2266
566
194
2702
4520
2348
1577
6922
372
895
667
650
5530
8798
670
2806
2395
1525
4602
1558
1278
1635
5413
2804
1167
731
3000
1663
529...

result:

wrong answer 73518th numbers differ - expected: '19', found: '40'