QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#718765#9250. Max GCDleafmaple#WA 1733ms607784kbC++201.9kb2024-11-06 21:23:122024-11-06 21:23:13

Judging History

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

  • [2024-11-06 21:23:13]
  • 评测
  • 测评结果:WA
  • 用时:1733ms
  • 内存:607784kb
  • [2024-11-06 21:23:12]
  • 提交

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 = -1;
		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;
		vector<int>fac;
		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;
		vector<array<int,3>>edg;
		// map<<pair<int,int>>,int>mp;
		
		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<=M; i++)if(g[i].size() >= 3){
			// int pos = 3;
			// for(int j = 0; j+2 < g[i].size(); j++){
				// int l = g[i][j];
				// int m = g[i][j+1];
				// int pos = lower_bound(g[i].begin(), g[i].end(), 2*m-l) - g[i].begin();
				// if(pos >= g[i].size())break;
				// int r = g[i][pos];
				// fk[r].push_back({l, i});
			// }
		// }
		for(int i=1; i<=n; 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]){
				// cout << i << ' ' << pos << ' ' << val << endl;
				//pos~n
				add(pos, val);
			}
			for(auto [pos, id]: ask[i]){
				ans[id] = cal(pos);
			}
		}
		for(int i=1; i<=n; i++) cout << ans[i] << endl;
	
		
	
	} 
	

詳細信息

Test #1:

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

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: 1733ms
memory: 607784kb

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'