QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#556953#9250. Max GCDzltWA 1880ms782404kbC++142.1kb2024-09-10 22:41:292024-09-10 22:41:29

Judging History

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

  • [2024-09-10 22:41:29]
  • 评测
  • 测评结果:WA
  • 用时:1880ms
  • 内存:782404kb
  • [2024-09-10 22:41:29]
  • 提交

answer

#include <bits/stdc++.h>
#define pb emplace_back
#define fst first
#define scd second
#define mkp make_pair
#define mems(a, x) memset((a), (x), sizeof(a))

using namespace std;
typedef long long ll;
typedef double db;
typedef unsigned long long ull;
typedef long double ldb;
typedef pair<int, int> pii;

const int maxn = 1000100;
const int maxm = 1000100;
const int N = 1000000;

int n, m, a[maxn], b[maxn], ans[maxn];
vector<int> di[maxm], vc[maxm];
vector<pii> md[maxn], qq[maxn];

namespace DS {
	int bel[maxn], blo, L[maxn], R[maxn], a[maxn], b[maxn];
	
	inline void init() {
		blo = sqrt(n);
		for (int i = 1; i <= n; ++i) {
			bel[i] = (i - 1) / blo + 1;
			if (!L[bel[i]]) {
				L[bel[i]] = i;
			}
			R[bel[i]] = i;
		}
	}
	
	inline void update(int x, int y) {
		a[x] = max(a[x], y);
		b[bel[x]] = max(b[bel[x]], y);
	}
	
	inline int query(int x) {
		int ans = 0;
		for (int i = x; i <= R[bel[x]]; ++i) {
			ans = max(ans, a[i]);
		}
		for (int i = bel[x] + 1; i <= bel[n]; ++i) {
			ans = max(ans, b[i]);
		}
		return ans;
	}
}

void solve() {
	for (int i = 1; i <= N; ++i) {
		for (int j = i; j <= N; j += i) {
			di[j].pb(i);
		}
	}
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		for (int x : di[a[i]]) {
			vc[x].pb(i);
		}
	}
	for (int i = 1, l, r; i <= m; ++i) {
		scanf("%d%d", &l, &r);
		if (r - l <= 1) {
			continue;
		}
		qq[r].pb(l, i);
	}
	DS::init();
	for (int i = 1; i <= N; ++i) {
		int tot = 0;
		for (int x : vc[i]) {
			b[++tot] = x;
		}
		if (tot <= 2) {
			continue;
		}
		for (int j = 1, k = 1; j < tot; ++j) {
			while (k <= tot && b[k] < b[j + 1] * 2 - b[j]) {
				++k;
			}
			if (k > tot) {
				break;
			}
			md[b[k]].pb(b[j], i);
		}
	}
	for (int i = 1; i <= n; ++i) {
		for (pii p : md[i]) {
			DS::update(p.fst, p.scd);
		}
		for (pii p : qq[i]) {
			ans[p.scd] = DS::query(p.fst);
		}
	}
	for (int i = 1; i <= m; ++i) {
		printf("%d\n", ans[i]);
	}
}

int main() {
	int T = 1;
	// scanf("%d", &T);
	while (T--) {
		solve();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 693ms
memory: 196652kb

input:

8 8
8 24 4 6 6 7 3 3
1 5
2 6
3 7
5 8
4 8
1 3
2 5
3 8

output:

4
2
3
1
3
4
2
3

result:

ok 8 tokens

Test #2:

score: -100
Wrong Answer
time: 1880ms
memory: 782404kb

input:

150000 100000
982800 554400 665280 982800 997920 720720 786240 831600 997920 982800 786240 982800 942480 831600 887040 665280 831600 960960 786240 982800 786240 942480 665280 831600 942480 665280 982800 960960 960960 997920 720720 960960 960960 665280 982800 665280 982800 942480 786240 997920 554400...

output:

997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920...

result:

wrong answer 5108th words differ - expected: '997920', found: '982800'