QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#678400#9250. Max GCDveg#TL 40ms8080kbC++201.3kb2024-10-26 14:49:282024-10-26 14:49:28

Judging History

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

  • [2024-10-26 14:49:28]
  • 评测
  • 测评结果:TL
  • 用时:40ms
  • 内存:8080kb
  • [2024-10-26 14:49:28]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
struct AAA {
	int l, r, g;
} q[150005];
vector<AAA> seq;
int n, Q, c[150005], ans[150005], a[150005];
vector<int> num[1000005];
void add(int x, int y) {
	for (; x; x -= x & -x)
		c[x] = max(c[x], y);
}
int ask(int x) {
	int y = 0;
	for (; x <= n; x += x & -x)
		y = max(y, c[x]);
	return y;
}
int main() {
	scanf("%d%d", &n, &Q);
	for (int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		num[a[i]].push_back(i);
	}
	for (int i = 1; i <= Q; ++i) {
		scanf("%d%d", &q[i].l, &q[i].r);
		q[i].g = i;
	}
	sort(q + 1, q + Q + 1, [](AAA p, AAA q) { return p.r < q.r; });
	for (int i = 1; i <= 1000000; ++i) {
		vector<int> v;
		for (int j = i; j <= 1000000; j += i)
			for (int k : num[j])
				v.push_back(k);
		sort(v.begin(), v.end());
		for (int j = 0; j + 1 < v.size(); ++j) {
			int x = v[j], y = v[j + 1];
			auto p = lower_bound(v.begin(), v.end(), y + y - x);
			if (p != v.end()) seq.push_back((AAA){x, *p, i});
		}
	}
	sort(seq.begin(), seq.end(), [](AAA p, AAA q) { return p.r < q.r; });
	int t = 0;
	for (int i = 1; i <= Q; ++i) {
		while (t <= seq.size() && seq[t].r <= q[i].r) {
			add(seq[t].l, seq[t].g);
			t++;
		}
		ans[q[i].g] = ask(q[i].l);
	}
	for (int i = 1; i <= Q; ++i) printf("%d\n", ans[i]);
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 40ms
memory: 8080kb

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
Time Limit Exceeded

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:


result: