QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#552987#9250. Max GCDucup-team2000#WA 1315ms506600kbC++231.5kb2024-09-08 05:03:432024-09-08 05:03:43

Judging History

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

  • [2024-09-08 05:03:43]
  • 评测
  • 测评结果:WA
  • 用时:1315ms
  • 内存:506600kb
  • [2024-09-08 05:03:43]
  • 提交

answer

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

int main() {
	cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit);
	int n,q; cin>>n>>q;
	vector<int> a(n);
	for (int& x: a) cin>>x;
	vector<array<int,3>> qs;
	for (int i=0; i<q; i++) {
		int l,r; cin>>l>>r, l--, r--;
		qs.push_back({l,r,i});
	}
	
	vector<vector<int>> isd(*max_element(a.begin(), a.end())+1);
	for (int i=0; i<n; i++) {
		isd[a[i]].push_back(i);
		for (int j=2; j*j<=a[i]; j++) {
			if (a[i]%j==0) {
				isd[j].push_back(i);
				if (j*j!=a[i]) isd[a[i]/j].push_back(i);
			}
		}
	}

	vector<vector<array<int,2>>> endpts(n);
	for (int i=2; i<isd.size(); i++) {
		int r=0;
		for (int l=0; l+1<isd[i].size(); l++) {
			int cur=isd[i][l], nxt=isd[i][l+1];
			while (r<isd[i].size() && nxt-cur > isd[i][r]-nxt) r++;
			if (r==isd[i].size()) break;
			endpts[cur].push_back({isd[i][r], i});
		}
	}

	sort(qs.begin(), qs.end(), greater<array<int,3>>());
	map<int, int> m;
	int cl=n-1;
	vector<int> ans(q, 0);
	for (auto [l,r,qi]: qs) {
		if (r-l<=1) continue;

		for (; l<=cl; cl--) {
			for (auto [right, val]: endpts[cl]) {
				auto it = m.upper_bound(right);
				if (it!=m.begin() && prev(it)->second >= val) continue;
				it = next(m.insert_or_assign(right, val).first);
				while (it!=m.end() && it->second<=val) it=m.erase(it);
			}
		}

		auto it = m.upper_bound(r);
		if (it==m.begin()) ans[qi]=1;
		else ans[qi]=prev(it)->second;
	}

	for (int v: ans) cout<<v<<"\n";
}

详细

Test #1:

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

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: 1315ms
memory: 506600kb

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'