QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#550353 | #9250. Max GCD | ucup-team3555# | WA | 2848ms | 721260kb | C++20 | 1.2kb | 2024-09-07 11:51:42 | 2024-09-07 11:51:42 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=1e6+5;
int n,m,a[N],mx,ql[N],qr[N],ans[N];
vector<int> p[N],G[N];
struct Nod{int x,v;};
vector<Nod> op[N];
vector<int> Q[N];
namespace BIT{
int tr[N];
int lowbit(int i){return i&(-i);}
void upd(int x,int v){for(int i=x;i<=n;i+=lowbit(i)) tr[i]=max(tr[i],v);}
int qry(int x){
int res=1;
for(int i=x;i>=1;i-=lowbit(i)) res=max(res,tr[i]);
return res;
}
}
using namespace BIT;
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i],mx=max(mx,a[i]);
for(int i=2;i<=mx;i++) for(int j=i;j<=mx;j+=i) p[j].pb(i);
for(int i=1;i<=n;i++) for(auto j:p[a[i]]) G[j].pb(i);
for(int i=2,sz;i<=mx;i++){
sz=(int)G[i].size();
for(int j=1;j<sz;j++){
int tmp=lower_bound(G[i].begin(),G[i].end(),2*G[i][j]-G[i][j-1])-G[i].begin();
if(tmp<sz) op[G[i][tmp]].pb({G[i][j-1],i});
}
}
for(int i=1;i<=m;i++) cin>>ql[i]>>qr[i],ans[i]=1,Q[qr[i]].pb(i);
for(int i=1;i<=n;i++){
for(auto j:op[i]) upd(n-j.x+1,j.v);
for(auto j:Q[i]) ans[j]=qry(n-ql[j]+1);
}
for(int i=1;i<=m;i++) cout<<ans[i]<<'\n';
return 0;
}
/*
8 1
8 24 4 6 6 7 3 3
2 6
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 5ms
memory: 11800kb
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: 2848ms
memory: 721260kb
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'