QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#718812#9250. Max GCDleafmaple#WA 1192ms608720kbC++201.4kb2024-11-06 21:31:072024-11-06 21:31:12

Judging History

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

  • [2024-11-06 21:31:12]
  • 评测
  • 测评结果:WA
  • 用时:1192ms
  • 内存:608720kb
  • [2024-11-06 21:31:07]
  • 提交

answer

	#include<bits/stdc++.h>
	using namespace std;
	#define ll long long  
	#define endl '\n'
	const int N = 1e6+5;
	vector<int>g[N];
	vector<pair<int,int>>fk[N], ask[N];
	int a[N], ans[N];
	int tr[N];
	
	void add(int x, int y){
		for(;x; x-=(x&-x)){
			tr[x] = max(tr[x], y);
		}
	}
	int cal(int x){
		int y = 0;
		for(;x<=200000; x+=(x&-x)){
			y = max(y, tr[x]);
		}
		return y;
	} 
	
	
	signed main (){
		std::ios::sync_with_stdio(false);  
		cin.tie(NULL); 
		cout.tie(NULL);
		// memset(tr, -1, sizeof(tr));
		int n, q; cin >> n >> q;
		for(int i=1; i<=n; i++){
			cin >> a[i];
			for(int j = 1; j*j <= a[i]; j++)if(a[i]%j == 0){
				g[j].push_back(i);
				if(j*j != a[i]) g[a[i]/j].push_back(i);
			}
		}
		const int M = 1e6;
		for(int i=1; i<=M; i++)if(g[i].size() >= 3){
			int pos = 2;
			for(int j = 0; j+2 < g[i].size(); j++){
				pos = max(pos, j+2);
				int l = g[i][j];
				int m = g[i][j+1];
				while(g[i][pos] - m < m - l){
					pos++;
					if(pos >= g[i].size())break;
				}
				if(pos >= g[i].size())break;
				int r = g[i][pos];
				fk[r].push_back({l, i});
			}
		}
		for(int i=1; i<=q; i++){
			int l, r; cin >> l >> r;
			ask[r].push_back({l, i});
		}
		for(int i=1; i<=n; i++){
			for(auto [pos, val]: fk[i]){
				add(pos, val);
			}
			for(auto [pos, id]: ask[i]){
				ans[id] = cal(pos);
			}
		}
		for(int i=1; i<=q; i++) cout << ans[i] << endl;
	
		
	
	} 
	

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4ms
memory: 7696kb

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: 1192ms
memory: 608720kb

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'