QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#555250#9250. Max GCDPurslane#WA 2714ms501188kbC++141.2kb2024-09-09 21:04:302024-09-09 21:04:31

Judging History

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

  • [2024-09-09 21:04:31]
  • 评测
  • 测评结果:WA
  • 用时:2714ms
  • 内存:501188kb
  • [2024-09-09 21:04:30]
  • 提交

answer

#include<bits/stdc++.h>
#define ffor(i,a,b) for(int i=(a);i<=(b);i++)
#define roff(i,a,b) for(int i=(a);i>=(b);i--)
using namespace std;
const int MAXN=2e5+10,MAXM=1e6+10;
int n,q,ans[MAXN],a[MAXN];
vector<int> occ[MAXM];
int tr[MAXN];
vector<pair<int,int>> upd[MAXN],qr[MAXN];
void update(int pos,int v) {
	while(pos<=n) tr[pos]=max(tr[pos],v),pos+=pos&-pos;
	return ;	
}
int query(int pos) {
	int ans=1;
	while(pos) ans=max(ans,tr[pos]),pos-=pos&-pos;
	return ans;
}
int main() {
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin>>n>>q;
	ffor(i,1,n) {
		cin>>a[i];
		ffor(j,1,a[i]/j) if(a[i]%j==0) {
			occ[j].push_back(i);
			if(a[i]/j!=j) occ[a[i]/j].push_back(i);
		}
	}
	ffor(i,1,q) {int l,r;cin>>l>>r,qr[l].push_back({r,i});}
	ffor(i,2,1000000) if(occ[i].size()>=3) {
		ffor(j,0,occ[i].size()-3) {
			int id1=occ[i][j],id2=occ[i][j+1],id3=2*id2-id1;
			int pos=lower_bound(occ[i].begin(),occ[i].end(),id3)-occ[i].begin();
			if(pos>=occ[i].size()) continue ;
			upd[id1].push_back({occ[i][pos],i});
		}
	}
	roff(i,n,1) {
		for(auto pr:upd[i]) update(pr.first,pr.second);
		for(auto pr:qr[i]) ans[pr.second]=query(pr.first);	
	}
	ffor(i,1,q) cout<<ans[i]<<'\n';
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 5ms
memory: 38724kb

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: 2714ms
memory: 501188kb

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'