QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#797693#9426. Relearn through ReviewboringhackerWA 113ms7760kbC111.6kb2024-12-03 16:39:542024-12-03 16:39:54

Judging History

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

  • [2024-12-03 16:39:54]
  • 评测
  • 测评结果:WA
  • 用时:113ms
  • 内存:7760kb
  • [2024-12-03 16:39:54]
  • 提交

answer

#include <stdio.h>
#include <stdlib.h>

#define L	19	// L = ceil(log2(n + 1))
#define N	300000

long long max(long long i, long long j) { return i < j ? j : i; }

long long gcd(long long i, long long j) { return j ? gcd(j, i % j) : i; }

long long *ff[L];
int l2[N + 1];

long long query(int l, int r) {
	int h = l2[r - l];

	return gcd(ff[h][l], ff[h][r - (1 << h)]);
}

int main() {
	int n, t;
	int i, j;
	int cnt, cnt_;
	long long k;
	static int pp[N], qq[N];
	static long long aa[N], pg[N], sg[N];

	scanf("%d", &t);
	while (t--) {
		long long g;

		scanf("%d%lld", &n, &k);
		for (i = 0; i < n; ++i)
			scanf("%lld", aa + i);
		l2[0] = -1;
		for (i = 1; i <= n; ++i)
			l2[i] = l2[i / 2] + 1;
		ff[0] = (long long *) malloc(n * sizeof *ff[0]);
		for (i = 0; i < n; ++i)
			ff[0][i] = aa[i] + k;
		for (i = 1; (1 << i) <= n; ++i) {
			ff[i] = (long long *) malloc((n - (1 << i) + 1) * sizeof *ff[i]);
			for (j = 0; j + (1 << i) <= n; ++j)
				ff[i][j] = gcd(ff[i - 1][j], ff[i - 1][j + (1 << (i - 1))]);
		}
		cnt = cnt_ = 0;
		pg[0] = aa[0], sg[n - 1] = aa[n - 1];
		for (i = 1; i < n; ++i)
			pg[i] = gcd(pg[i - 1], aa[i]);
		for (i = n - 1; i--;)
			sg[i] = gcd(sg[i + 1], aa[i]);
		for (i = 0; i < n - 1; ++i)
			if (pg[i] != pg[i + 1])
				pp[cnt++] = i;
		for (i = n; --i;)
			if (sg[i] != sg[i - 1])
				qq[cnt_++] = i;
		g = sg[0];
		for (i = 0; i < cnt; ++i)
			for (j = 0; j < cnt_; ++j)
				if (pp[i] + 1 < qq[j])
					g = max(g, gcd(pg[pp[i]], gcd(sg[qq[j]], query(pp[i] + 1, qq[j]))));
		printf("%lld\n", g);
		for (i = 0; (1 << i) <= n; ++i)
			free(ff[i]);
	}
	return 0;
}

详细

Test #1:

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

input:

2
6 2
5 3 13 8 10 555
3 0
3 6 9

output:

5
3

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 113ms
memory: 7760kb

input:

100000
1 608611451460421713
33155506392034032
1 743116173559300609
6138108577573005
7 364454564010802125
657035115675878115 657035115675878115 657035115675878115 657035115675878115 657035115675878115 292580551665075990 657035115675878115
4 316648374341335221
365788422120542814 182894211060271407 731...

output:

33155506392034032
6138108577573005
657035115675878115
3
1
98423435849394582
1
1
484915690810412536
3
149180825015886938
361813583202892479
915781395066183375
37337367838628559
632093288650732211
1
2
494408344393555851
1
1
118387461231999184
1
1
1
809535299113892268
580787185875674097
3
4435168108152...

result:

wrong answer 1st lines differ - expected: '641766957852455745', found: '33155506392034032'