QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#550603#9250. Max GCDucup-team052#WA 1589ms674464kbC++231.3kb2024-09-07 13:34:512024-09-07 13:34:52

Judging History

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

  • [2024-09-07 13:34:52]
  • 评测
  • 测评结果:WA
  • 用时:1589ms
  • 内存:674464kb
  • [2024-09-07 13:34:51]
  • 提交

answer

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

typedef pair <int, int> pii;

const int N = 1e6 + 5;

vector <pii> vec2[N], qry[N];
vector <int> g[N], vec[N];
int ans[N], f[N];
int n, q;

void add(int x, int y) {
	while (x) {
		f[x] = max(f[x], y);
		x &= (x - 1);
	}
}

int query(int x) {
	int ans = 1;
	while (x <= n) {
		ans = max(ans, f[x]);
		x += (x & -x);
	}
	return ans;
}

int main() {
	for (int i = 2; i <= N - 5; i++) {
		for (int j = i; j <= N - 5; j += i) g[j].push_back(i);
	}
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; i++) {
		int a;
		scanf("%d", &a);
		for (auto j : g[a]) vec[j].push_back(i);
	}
	for (int i = 2; i <= N - 5; i++) {
		int len = (int)vec[i].size();
		int now = len - 1;
		for (int j = len - 2; j >= 1; j--) {
			int minr = vec[i][j] * 2 - vec[i][j - 1];
			while (vec[i][now - 1] >= minr) --now;
			if (vec[i][now] >= minr) {
				vec2[vec[i][now]].emplace_back(vec[i][j - 1], i);
			}
		}
	}
	for (int i = 1; i <= q; i++) {
		int l, r;
		scanf("%d%d", &l, &r);
		qry[r].emplace_back(l, i);
	}
	for (int i = 1; i <= n; i++) {
		for (auto j : vec2[i]) add(j.first, j.second);
		for (auto j : qry[i]) ans[j.second] = query(j.first);
	}
	for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 556ms
memory: 116404kb

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: 1589ms
memory: 674464kb

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 1518th words differ - expected: '0', found: '1'